UNPKG

487 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6function _objectWithoutPropertiesLoose(source, excluded) {
7 if (source == null) return {};
8 var target = {};
9 var sourceKeys = Object.keys(source);
10 var key, i;
11 for (i = 0; i < sourceKeys.length; i++) {
12 key = sourceKeys[i];
13 if (excluded.indexOf(key) >= 0) continue;
14 target[key] = source[key];
15 }
16 return target;
17}
18class Position {
19 constructor(line, col, index) {
20 this.line = void 0;
21 this.column = void 0;
22 this.index = void 0;
23 this.line = line;
24 this.column = col;
25 this.index = index;
26 }
27}
28class SourceLocation {
29 constructor(start, end) {
30 this.start = void 0;
31 this.end = void 0;
32 this.filename = void 0;
33 this.identifierName = void 0;
34 this.start = start;
35 this.end = end;
36 }
37}
38function createPositionWithColumnOffset(position, columnOffset) {
39 const {
40 line,
41 column,
42 index
43 } = position;
44 return new Position(line, column + columnOffset, index + columnOffset);
45}
46const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
47var ModuleErrors = {
48 ImportMetaOutsideModule: {
49 message: `import.meta may appear only with 'sourceType: "module"'`,
50 code
51 },
52 ImportOutsideModule: {
53 message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
54 code
55 }
56};
57const NodeDescriptions = {
58 ArrayPattern: "array destructuring pattern",
59 AssignmentExpression: "assignment expression",
60 AssignmentPattern: "assignment expression",
61 ArrowFunctionExpression: "arrow function expression",
62 ConditionalExpression: "conditional expression",
63 CatchClause: "catch clause",
64 ForOfStatement: "for-of statement",
65 ForInStatement: "for-in statement",
66 ForStatement: "for-loop",
67 FormalParameters: "function parameter list",
68 Identifier: "identifier",
69 ImportSpecifier: "import specifier",
70 ImportDefaultSpecifier: "import default specifier",
71 ImportNamespaceSpecifier: "import namespace specifier",
72 ObjectPattern: "object destructuring pattern",
73 ParenthesizedExpression: "parenthesized expression",
74 RestElement: "rest element",
75 UpdateExpression: {
76 true: "prefix operation",
77 false: "postfix operation"
78 },
79 VariableDeclarator: "variable declaration",
80 YieldExpression: "yield expression"
81};
82const toNodeDescription = ({
83 type,
84 prefix
85}) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
86var StandardErrors = {
87 AccessorIsGenerator: ({
88 kind
89 }) => `A ${kind}ter cannot be a generator.`,
90 ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
91 AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
92 AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
93 AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
94 AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
95 AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
96 AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
97 AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
98 BadGetterArity: "A 'get' accessor must not have any formal parameters.",
99 BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
100 BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
101 ConstructorClassField: "Classes may not have a field named 'constructor'.",
102 ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
103 ConstructorIsAccessor: "Class constructor may not be an accessor.",
104 ConstructorIsAsync: "Constructor can't be an async function.",
105 ConstructorIsGenerator: "Constructor can't be a generator.",
106 DeclarationMissingInitializer: ({
107 kind
108 }) => `Missing initializer in ${kind} declaration.`,
109 DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
110 DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
111 DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
112 DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
113 DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
114 DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
115 DecoratorStaticBlock: "Decorators can't be used with a static block.",
116 DeletePrivateField: "Deleting a private field is not allowed.",
117 DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
118 DuplicateConstructor: "Duplicate constructor in the same class.",
119 DuplicateDefaultExport: "Only one default export allowed per module.",
120 DuplicateExport: ({
121 exportName
122 }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
123 DuplicateProto: "Redefinition of __proto__ property.",
124 DuplicateRegExpFlags: "Duplicate regular expression flag.",
125 ElementAfterRest: "Rest element must be last element.",
126 EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
127 ExportBindingIsString: ({
128 localName,
129 exportName
130 }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
131 ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
132 ForInOfLoopInitializer: ({
133 type
134 }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
135 ForInUsing: "For-in loop may not start with 'using' declaration.",
136 ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
137 ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
138 GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
139 IllegalBreakContinue: ({
140 type
141 }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
142 IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
143 IllegalReturn: "'return' outside of function.",
144 ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedAssertSyntax: true` option in the import attributes plugin to suppress this error.",
145 ImportBindingIsString: ({
146 importName
147 }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
148 ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
149 ImportCallArity: ({
150 maxArgumentCount
151 }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
152 ImportCallNotNewExpression: "Cannot use new with import(...).",
153 ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
154 ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
155 ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
156 ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
157 IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
158 InvalidBigIntLiteral: "Invalid BigIntLiteral.",
159 InvalidCodePoint: "Code point out of bounds.",
160 InvalidCoverInitializedName: "Invalid shorthand property initializer.",
161 InvalidDecimal: "Invalid decimal.",
162 InvalidDigit: ({
163 radix
164 }) => `Expected number in radix ${radix}.`,
165 InvalidEscapeSequence: "Bad character escape sequence.",
166 InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
167 InvalidEscapedReservedWord: ({
168 reservedWord
169 }) => `Escape sequence in keyword ${reservedWord}.`,
170 InvalidIdentifier: ({
171 identifierName
172 }) => `Invalid identifier ${identifierName}.`,
173 InvalidLhs: ({
174 ancestor
175 }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
176 InvalidLhsBinding: ({
177 ancestor
178 }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
179 InvalidNumber: "Invalid number.",
180 InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
181 InvalidOrUnexpectedToken: ({
182 unexpected
183 }) => `Unexpected character '${unexpected}'.`,
184 InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
185 InvalidPrivateFieldResolution: ({
186 identifierName
187 }) => `Private name #${identifierName} is not defined.`,
188 InvalidPropertyBindingPattern: "Binding member expression.",
189 InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
190 InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
191 LabelRedeclaration: ({
192 labelName
193 }) => `Label '${labelName}' is already declared.`,
194 LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
195 LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
196 MalformedRegExpFlags: "Invalid regular expression flag.",
197 MissingClassName: "A class name is required.",
198 MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
199 MissingSemicolon: "Missing semicolon.",
200 MissingPlugin: ({
201 missingPlugin
202 }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
203 MissingOneOfPlugins: ({
204 missingPlugin
205 }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
206 MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
207 MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
208 ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
209 ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
210 ModuleAttributesWithDuplicateKeys: ({
211 key
212 }) => `Duplicate key "${key}" is not allowed in module attributes.`,
213 ModuleExportNameHasLoneSurrogate: ({
214 surrogateCharCode
215 }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
216 ModuleExportUndefined: ({
217 localName
218 }) => `Export '${localName}' is not defined.`,
219 MultipleDefaultsInSwitch: "Multiple default clauses.",
220 NewlineAfterThrow: "Illegal newline after throw.",
221 NoCatchOrFinally: "Missing catch or finally clause.",
222 NumberIdentifier: "Identifier directly after number.",
223 NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
224 ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
225 OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
226 OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
227 OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
228 ParamDupe: "Argument name clash.",
229 PatternHasAccessor: "Object pattern can't contain getter or setter.",
230 PatternHasMethod: "Object pattern can't contain methods.",
231 PrivateInExpectedIn: ({
232 identifierName
233 }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
234 PrivateNameRedeclaration: ({
235 identifierName
236 }) => `Duplicate private name #${identifierName}.`,
237 RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
238 RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
239 RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
240 RecordNoProto: "'__proto__' is not allowed in Record expressions.",
241 RestTrailingComma: "Unexpected trailing comma after rest element.",
242 SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
243 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.",
244 StaticPrototype: "Classes may not have static property named prototype.",
245 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?",
246 SuperPrivateField: "Private fields can't be accessed on super.",
247 TrailingDecorator: "Decorators must be attached to a class element.",
248 TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
249 TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
250 TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
251 UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
252 UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
253 UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
254 UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
255 UnexpectedKeyword: ({
256 keyword
257 }) => `Unexpected keyword '${keyword}'.`,
258 UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
259 UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
260 UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
261 UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
262 UnexpectedPrivateField: "Unexpected private name.",
263 UnexpectedReservedWord: ({
264 reservedWord
265 }) => `Unexpected reserved word '${reservedWord}'.`,
266 UnexpectedSuper: "'super' is only allowed in object methods and classes.",
267 UnexpectedToken: ({
268 expected,
269 unexpected
270 }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
271 UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
272 UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
273 UnsupportedBind: "Binding should be performed on object property.",
274 UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
275 UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
276 UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
277 UnsupportedMetaProperty: ({
278 target,
279 onlyValidPropertyName
280 }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
281 UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
282 UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
283 UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
284 UnterminatedComment: "Unterminated comment.",
285 UnterminatedRegExp: "Unterminated regular expression.",
286 UnterminatedString: "Unterminated string constant.",
287 UnterminatedTemplate: "Unterminated template.",
288 UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
289 VarRedeclaration: ({
290 identifierName
291 }) => `Identifier '${identifierName}' has already been declared.`,
292 YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
293 YieldInParameter: "Yield expression is not allowed in formal parameters.",
294 ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
295};
296var StrictModeErrors = {
297 StrictDelete: "Deleting local variable in strict mode.",
298 StrictEvalArguments: ({
299 referenceName
300 }) => `Assigning to '${referenceName}' in strict mode.`,
301 StrictEvalArgumentsBinding: ({
302 bindingName
303 }) => `Binding '${bindingName}' in strict mode.`,
304 StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
305 StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
306 StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
307 StrictWith: "'with' in strict mode."
308};
309const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
310var PipelineOperatorErrors = {
311 PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
312 PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
313 PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
314 PipeTopicUnconfiguredToken: ({
315 token
316 }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
317 PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
318 PipeUnparenthesizedBody: ({
319 type
320 }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
321 type
322 })}; please wrap it in parentheses.`,
323 PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
324 PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
325 PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
326 PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
327 PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
328 PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
329};
330const _excluded$1 = ["toMessage"],
331 _excluded2$1 = ["message"];
332function defineHidden(obj, key, value) {
333 Object.defineProperty(obj, key, {
334 enumerable: false,
335 configurable: true,
336 value
337 });
338}
339function toParseErrorConstructor(_ref) {
340 let {
341 toMessage
342 } = _ref,
343 properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
344 return function constructor({
345 loc,
346 details
347 }) {
348 const error = new SyntaxError();
349 Object.assign(error, properties, {
350 loc,
351 pos: loc.index
352 });
353 if ("missingPlugin" in details) {
354 Object.assign(error, {
355 missingPlugin: details.missingPlugin
356 });
357 }
358 defineHidden(error, "clone", function clone(overrides = {}) {
359 var _overrides$loc;
360 const {
361 line,
362 column,
363 index
364 } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
365 return constructor({
366 loc: new Position(line, column, index),
367 details: Object.assign({}, details, overrides.details)
368 });
369 });
370 defineHidden(error, "details", details);
371 Object.defineProperty(error, "message", {
372 configurable: true,
373 get() {
374 const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
375 this.message = message;
376 return message;
377 },
378 set(value) {
379 Object.defineProperty(this, "message", {
380 value,
381 writable: true
382 });
383 }
384 });
385 return error;
386 };
387}
388function ParseErrorEnum(argument, syntaxPlugin) {
389 if (Array.isArray(argument)) {
390 return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
391 }
392 const ParseErrorConstructors = {};
393 for (const reasonCode of Object.keys(argument)) {
394 const template = argument[reasonCode];
395 const _ref2 = typeof template === "string" ? {
396 message: () => template
397 } : typeof template === "function" ? {
398 message: template
399 } : template,
400 {
401 message
402 } = _ref2,
403 rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
404 const toMessage = typeof message === "string" ? () => message : message;
405 ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
406 code: "BABEL_PARSER_SYNTAX_ERROR",
407 reasonCode,
408 toMessage
409 }, syntaxPlugin ? {
410 syntaxPlugin
411 } : {}, rest));
412 }
413 return ParseErrorConstructors;
414}
415const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
416const {
417 defineProperty
418} = Object;
419const toUnenumerable = (object, key) => defineProperty(object, key, {
420 enumerable: false,
421 value: object[key]
422});
423function toESTreeLocation(node) {
424 node.loc.start && toUnenumerable(node.loc.start, "index");
425 node.loc.end && toUnenumerable(node.loc.end, "index");
426 return node;
427}
428var estree = superClass => class ESTreeParserMixin extends superClass {
429 parse() {
430 const file = toESTreeLocation(super.parse());
431 if (this.options.tokens) {
432 file.tokens = file.tokens.map(toESTreeLocation);
433 }
434 return file;
435 }
436 parseRegExpLiteral({
437 pattern,
438 flags
439 }) {
440 let regex = null;
441 try {
442 regex = new RegExp(pattern, flags);
443 } catch (e) {}
444 const node = this.estreeParseLiteral(regex);
445 node.regex = {
446 pattern,
447 flags
448 };
449 return node;
450 }
451 parseBigIntLiteral(value) {
452 let bigInt;
453 try {
454 bigInt = BigInt(value);
455 } catch (_unused) {
456 bigInt = null;
457 }
458 const node = this.estreeParseLiteral(bigInt);
459 node.bigint = String(node.value || value);
460 return node;
461 }
462 parseDecimalLiteral(value) {
463 const decimal = null;
464 const node = this.estreeParseLiteral(decimal);
465 node.decimal = String(node.value || value);
466 return node;
467 }
468 estreeParseLiteral(value) {
469 return this.parseLiteral(value, "Literal");
470 }
471 parseStringLiteral(value) {
472 return this.estreeParseLiteral(value);
473 }
474 parseNumericLiteral(value) {
475 return this.estreeParseLiteral(value);
476 }
477 parseNullLiteral() {
478 return this.estreeParseLiteral(null);
479 }
480 parseBooleanLiteral(value) {
481 return this.estreeParseLiteral(value);
482 }
483 directiveToStmt(directive) {
484 const expression = directive.value;
485 delete directive.value;
486 expression.type = "Literal";
487 expression.raw = expression.extra.raw;
488 expression.value = expression.extra.expressionValue;
489 const stmt = directive;
490 stmt.type = "ExpressionStatement";
491 stmt.expression = expression;
492 stmt.directive = expression.extra.rawValue;
493 delete expression.extra;
494 return stmt;
495 }
496 initFunction(node, isAsync) {
497 super.initFunction(node, isAsync);
498 node.expression = false;
499 }
500 checkDeclaration(node) {
501 if (node != null && this.isObjectProperty(node)) {
502 this.checkDeclaration(node.value);
503 } else {
504 super.checkDeclaration(node);
505 }
506 }
507 getObjectOrClassMethodParams(method) {
508 return method.value.params;
509 }
510 isValidDirective(stmt) {
511 var _stmt$expression$extr;
512 return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
513 }
514 parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
515 super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
516 const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
517 node.body = directiveStatements.concat(node.body);
518 delete node.directives;
519 }
520 pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
521 this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
522 if (method.typeParameters) {
523 method.value.typeParameters = method.typeParameters;
524 delete method.typeParameters;
525 }
526 classBody.body.push(method);
527 }
528 parsePrivateName() {
529 const node = super.parsePrivateName();
530 {
531 if (!this.getPluginOption("estree", "classFeatures")) {
532 return node;
533 }
534 }
535 return this.convertPrivateNameToPrivateIdentifier(node);
536 }
537 convertPrivateNameToPrivateIdentifier(node) {
538 const name = super.getPrivateNameSV(node);
539 node = node;
540 delete node.id;
541 node.name = name;
542 node.type = "PrivateIdentifier";
543 return node;
544 }
545 isPrivateName(node) {
546 {
547 if (!this.getPluginOption("estree", "classFeatures")) {
548 return super.isPrivateName(node);
549 }
550 }
551 return node.type === "PrivateIdentifier";
552 }
553 getPrivateNameSV(node) {
554 {
555 if (!this.getPluginOption("estree", "classFeatures")) {
556 return super.getPrivateNameSV(node);
557 }
558 }
559 return node.name;
560 }
561 parseLiteral(value, type) {
562 const node = super.parseLiteral(value, type);
563 node.raw = node.extra.raw;
564 delete node.extra;
565 return node;
566 }
567 parseFunctionBody(node, allowExpression, isMethod = false) {
568 super.parseFunctionBody(node, allowExpression, isMethod);
569 node.expression = node.body.type !== "BlockStatement";
570 }
571 parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
572 let funcNode = this.startNode();
573 funcNode.kind = node.kind;
574 funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
575 funcNode.type = "FunctionExpression";
576 delete funcNode.kind;
577 node.value = funcNode;
578 if (type === "ClassPrivateMethod") {
579 node.computed = false;
580 }
581 return this.finishNode(node, "MethodDefinition");
582 }
583 parseClassProperty(...args) {
584 const propertyNode = super.parseClassProperty(...args);
585 {
586 if (!this.getPluginOption("estree", "classFeatures")) {
587 return propertyNode;
588 }
589 }
590 propertyNode.type = "PropertyDefinition";
591 return propertyNode;
592 }
593 parseClassPrivateProperty(...args) {
594 const propertyNode = super.parseClassPrivateProperty(...args);
595 {
596 if (!this.getPluginOption("estree", "classFeatures")) {
597 return propertyNode;
598 }
599 }
600 propertyNode.type = "PropertyDefinition";
601 propertyNode.computed = false;
602 return propertyNode;
603 }
604 parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
605 const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
606 if (node) {
607 node.type = "Property";
608 if (node.kind === "method") {
609 node.kind = "init";
610 }
611 node.shorthand = false;
612 }
613 return node;
614 }
615 parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
616 const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
617 if (node) {
618 node.kind = "init";
619 node.type = "Property";
620 }
621 return node;
622 }
623 isValidLVal(type, isUnparenthesizedInAssign, binding) {
624 return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
625 }
626 isAssignable(node, isBinding) {
627 if (node != null && this.isObjectProperty(node)) {
628 return this.isAssignable(node.value, isBinding);
629 }
630 return super.isAssignable(node, isBinding);
631 }
632 toAssignable(node, isLHS = false) {
633 if (node != null && this.isObjectProperty(node)) {
634 const {
635 key,
636 value
637 } = node;
638 if (this.isPrivateName(key)) {
639 this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
640 }
641 this.toAssignable(value, isLHS);
642 } else {
643 super.toAssignable(node, isLHS);
644 }
645 }
646 toAssignableObjectExpressionProp(prop, isLast, isLHS) {
647 if (prop.kind === "get" || prop.kind === "set") {
648 this.raise(Errors.PatternHasAccessor, {
649 at: prop.key
650 });
651 } else if (prop.method) {
652 this.raise(Errors.PatternHasMethod, {
653 at: prop.key
654 });
655 } else {
656 super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
657 }
658 }
659 finishCallExpression(unfinished, optional) {
660 const node = super.finishCallExpression(unfinished, optional);
661 if (node.callee.type === "Import") {
662 node.type = "ImportExpression";
663 node.source = node.arguments[0];
664 if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
665 var _node$arguments$;
666 node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
667 }
668 delete node.arguments;
669 delete node.callee;
670 }
671 return node;
672 }
673 toReferencedArguments(node) {
674 if (node.type === "ImportExpression") {
675 return;
676 }
677 super.toReferencedArguments(node);
678 }
679 parseExport(unfinished, decorators) {
680 const exportStartLoc = this.state.lastTokStartLoc;
681 const node = super.parseExport(unfinished, decorators);
682 switch (node.type) {
683 case "ExportAllDeclaration":
684 node.exported = null;
685 break;
686 case "ExportNamedDeclaration":
687 if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
688 node.type = "ExportAllDeclaration";
689 node.exported = node.specifiers[0].exported;
690 delete node.specifiers;
691 }
692 case "ExportDefaultDeclaration":
693 {
694 var _declaration$decorato;
695 const {
696 declaration
697 } = node;
698 if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
699 this.resetStartLocation(node, exportStartLoc);
700 }
701 }
702 break;
703 }
704 return node;
705 }
706 parseSubscript(base, startLoc, noCalls, state) {
707 const node = super.parseSubscript(base, startLoc, noCalls, state);
708 if (state.optionalChainMember) {
709 if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
710 node.type = node.type.substring(8);
711 }
712 if (state.stop) {
713 const chain = this.startNodeAtNode(node);
714 chain.expression = node;
715 return this.finishNode(chain, "ChainExpression");
716 }
717 } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
718 node.optional = false;
719 }
720 return node;
721 }
722 hasPropertyAsPrivateName(node) {
723 if (node.type === "ChainExpression") {
724 node = node.expression;
725 }
726 return super.hasPropertyAsPrivateName(node);
727 }
728 isObjectProperty(node) {
729 return node.type === "Property" && node.kind === "init" && !node.method;
730 }
731 isObjectMethod(node) {
732 return node.method || node.kind === "get" || node.kind === "set";
733 }
734 finishNodeAt(node, type, endLoc) {
735 return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
736 }
737 resetStartLocation(node, startLoc) {
738 super.resetStartLocation(node, startLoc);
739 toESTreeLocation(node);
740 }
741 resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
742 super.resetEndLocation(node, endLoc);
743 toESTreeLocation(node);
744 }
745};
746class TokContext {
747 constructor(token, preserveSpace) {
748 this.token = void 0;
749 this.preserveSpace = void 0;
750 this.token = token;
751 this.preserveSpace = !!preserveSpace;
752 }
753}
754const types = {
755 brace: new TokContext("{"),
756 j_oTag: new TokContext("<tag"),
757 j_cTag: new TokContext("</tag"),
758 j_expr: new TokContext("<tag>...</tag>", true)
759};
760{
761 types.template = new TokContext("`", true);
762}
763const beforeExpr = true;
764const startsExpr = true;
765const isLoop = true;
766const isAssign = true;
767const prefix = true;
768const postfix = true;
769class ExportedTokenType {
770 constructor(label, conf = {}) {
771 this.label = void 0;
772 this.keyword = void 0;
773 this.beforeExpr = void 0;
774 this.startsExpr = void 0;
775 this.rightAssociative = void 0;
776 this.isLoop = void 0;
777 this.isAssign = void 0;
778 this.prefix = void 0;
779 this.postfix = void 0;
780 this.binop = void 0;
781 this.label = label;
782 this.keyword = conf.keyword;
783 this.beforeExpr = !!conf.beforeExpr;
784 this.startsExpr = !!conf.startsExpr;
785 this.rightAssociative = !!conf.rightAssociative;
786 this.isLoop = !!conf.isLoop;
787 this.isAssign = !!conf.isAssign;
788 this.prefix = !!conf.prefix;
789 this.postfix = !!conf.postfix;
790 this.binop = conf.binop != null ? conf.binop : null;
791 {
792 this.updateContext = null;
793 }
794 }
795}
796const keywords$1 = new Map();
797function createKeyword(name, options = {}) {
798 options.keyword = name;
799 const token = createToken(name, options);
800 keywords$1.set(name, token);
801 return token;
802}
803function createBinop(name, binop) {
804 return createToken(name, {
805 beforeExpr,
806 binop
807 });
808}
809let tokenTypeCounter = -1;
810const tokenTypes = [];
811const tokenLabels = [];
812const tokenBinops = [];
813const tokenBeforeExprs = [];
814const tokenStartsExprs = [];
815const tokenPrefixes = [];
816function createToken(name, options = {}) {
817 var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
818 ++tokenTypeCounter;
819 tokenLabels.push(name);
820 tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
821 tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
822 tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
823 tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
824 tokenTypes.push(new ExportedTokenType(name, options));
825 return tokenTypeCounter;
826}
827function createKeywordLike(name, options = {}) {
828 var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
829 ++tokenTypeCounter;
830 keywords$1.set(name, tokenTypeCounter);
831 tokenLabels.push(name);
832 tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
833 tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
834 tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
835 tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
836 tokenTypes.push(new ExportedTokenType("name", options));
837 return tokenTypeCounter;
838}
839const tt = {
840 bracketL: createToken("[", {
841 beforeExpr,
842 startsExpr
843 }),
844 bracketHashL: createToken("#[", {
845 beforeExpr,
846 startsExpr
847 }),
848 bracketBarL: createToken("[|", {
849 beforeExpr,
850 startsExpr
851 }),
852 bracketR: createToken("]"),
853 bracketBarR: createToken("|]"),
854 braceL: createToken("{", {
855 beforeExpr,
856 startsExpr
857 }),
858 braceBarL: createToken("{|", {
859 beforeExpr,
860 startsExpr
861 }),
862 braceHashL: createToken("#{", {
863 beforeExpr,
864 startsExpr
865 }),
866 braceR: createToken("}"),
867 braceBarR: createToken("|}"),
868 parenL: createToken("(", {
869 beforeExpr,
870 startsExpr
871 }),
872 parenR: createToken(")"),
873 comma: createToken(",", {
874 beforeExpr
875 }),
876 semi: createToken(";", {
877 beforeExpr
878 }),
879 colon: createToken(":", {
880 beforeExpr
881 }),
882 doubleColon: createToken("::", {
883 beforeExpr
884 }),
885 dot: createToken("."),
886 question: createToken("?", {
887 beforeExpr
888 }),
889 questionDot: createToken("?."),
890 arrow: createToken("=>", {
891 beforeExpr
892 }),
893 template: createToken("template"),
894 ellipsis: createToken("...", {
895 beforeExpr
896 }),
897 backQuote: createToken("`", {
898 startsExpr
899 }),
900 dollarBraceL: createToken("${", {
901 beforeExpr,
902 startsExpr
903 }),
904 templateTail: createToken("...`", {
905 startsExpr
906 }),
907 templateNonTail: createToken("...${", {
908 beforeExpr,
909 startsExpr
910 }),
911 at: createToken("@"),
912 hash: createToken("#", {
913 startsExpr
914 }),
915 interpreterDirective: createToken("#!..."),
916 eq: createToken("=", {
917 beforeExpr,
918 isAssign
919 }),
920 assign: createToken("_=", {
921 beforeExpr,
922 isAssign
923 }),
924 slashAssign: createToken("_=", {
925 beforeExpr,
926 isAssign
927 }),
928 xorAssign: createToken("_=", {
929 beforeExpr,
930 isAssign
931 }),
932 moduloAssign: createToken("_=", {
933 beforeExpr,
934 isAssign
935 }),
936 incDec: createToken("++/--", {
937 prefix,
938 postfix,
939 startsExpr
940 }),
941 bang: createToken("!", {
942 beforeExpr,
943 prefix,
944 startsExpr
945 }),
946 tilde: createToken("~", {
947 beforeExpr,
948 prefix,
949 startsExpr
950 }),
951 doubleCaret: createToken("^^", {
952 startsExpr
953 }),
954 doubleAt: createToken("@@", {
955 startsExpr
956 }),
957 pipeline: createBinop("|>", 0),
958 nullishCoalescing: createBinop("??", 1),
959 logicalOR: createBinop("||", 1),
960 logicalAND: createBinop("&&", 2),
961 bitwiseOR: createBinop("|", 3),
962 bitwiseXOR: createBinop("^", 4),
963 bitwiseAND: createBinop("&", 5),
964 equality: createBinop("==/!=/===/!==", 6),
965 lt: createBinop("</>/<=/>=", 7),
966 gt: createBinop("</>/<=/>=", 7),
967 relational: createBinop("</>/<=/>=", 7),
968 bitShift: createBinop("<</>>/>>>", 8),
969 bitShiftL: createBinop("<</>>/>>>", 8),
970 bitShiftR: createBinop("<</>>/>>>", 8),
971 plusMin: createToken("+/-", {
972 beforeExpr,
973 binop: 9,
974 prefix,
975 startsExpr
976 }),
977 modulo: createToken("%", {
978 binop: 10,
979 startsExpr
980 }),
981 star: createToken("*", {
982 binop: 10
983 }),
984 slash: createBinop("/", 10),
985 exponent: createToken("**", {
986 beforeExpr,
987 binop: 11,
988 rightAssociative: true
989 }),
990 _in: createKeyword("in", {
991 beforeExpr,
992 binop: 7
993 }),
994 _instanceof: createKeyword("instanceof", {
995 beforeExpr,
996 binop: 7
997 }),
998 _break: createKeyword("break"),
999 _case: createKeyword("case", {
1000 beforeExpr
1001 }),
1002 _catch: createKeyword("catch"),
1003 _continue: createKeyword("continue"),
1004 _debugger: createKeyword("debugger"),
1005 _default: createKeyword("default", {
1006 beforeExpr
1007 }),
1008 _else: createKeyword("else", {
1009 beforeExpr
1010 }),
1011 _finally: createKeyword("finally"),
1012 _function: createKeyword("function", {
1013 startsExpr
1014 }),
1015 _if: createKeyword("if"),
1016 _return: createKeyword("return", {
1017 beforeExpr
1018 }),
1019 _switch: createKeyword("switch"),
1020 _throw: createKeyword("throw", {
1021 beforeExpr,
1022 prefix,
1023 startsExpr
1024 }),
1025 _try: createKeyword("try"),
1026 _var: createKeyword("var"),
1027 _const: createKeyword("const"),
1028 _with: createKeyword("with"),
1029 _new: createKeyword("new", {
1030 beforeExpr,
1031 startsExpr
1032 }),
1033 _this: createKeyword("this", {
1034 startsExpr
1035 }),
1036 _super: createKeyword("super", {
1037 startsExpr
1038 }),
1039 _class: createKeyword("class", {
1040 startsExpr
1041 }),
1042 _extends: createKeyword("extends", {
1043 beforeExpr
1044 }),
1045 _export: createKeyword("export"),
1046 _import: createKeyword("import", {
1047 startsExpr
1048 }),
1049 _null: createKeyword("null", {
1050 startsExpr
1051 }),
1052 _true: createKeyword("true", {
1053 startsExpr
1054 }),
1055 _false: createKeyword("false", {
1056 startsExpr
1057 }),
1058 _typeof: createKeyword("typeof", {
1059 beforeExpr,
1060 prefix,
1061 startsExpr
1062 }),
1063 _void: createKeyword("void", {
1064 beforeExpr,
1065 prefix,
1066 startsExpr
1067 }),
1068 _delete: createKeyword("delete", {
1069 beforeExpr,
1070 prefix,
1071 startsExpr
1072 }),
1073 _do: createKeyword("do", {
1074 isLoop,
1075 beforeExpr
1076 }),
1077 _for: createKeyword("for", {
1078 isLoop
1079 }),
1080 _while: createKeyword("while", {
1081 isLoop
1082 }),
1083 _as: createKeywordLike("as", {
1084 startsExpr
1085 }),
1086 _assert: createKeywordLike("assert", {
1087 startsExpr
1088 }),
1089 _async: createKeywordLike("async", {
1090 startsExpr
1091 }),
1092 _await: createKeywordLike("await", {
1093 startsExpr
1094 }),
1095 _from: createKeywordLike("from", {
1096 startsExpr
1097 }),
1098 _get: createKeywordLike("get", {
1099 startsExpr
1100 }),
1101 _let: createKeywordLike("let", {
1102 startsExpr
1103 }),
1104 _meta: createKeywordLike("meta", {
1105 startsExpr
1106 }),
1107 _of: createKeywordLike("of", {
1108 startsExpr
1109 }),
1110 _sent: createKeywordLike("sent", {
1111 startsExpr
1112 }),
1113 _set: createKeywordLike("set", {
1114 startsExpr
1115 }),
1116 _static: createKeywordLike("static", {
1117 startsExpr
1118 }),
1119 _using: createKeywordLike("using", {
1120 startsExpr
1121 }),
1122 _yield: createKeywordLike("yield", {
1123 startsExpr
1124 }),
1125 _asserts: createKeywordLike("asserts", {
1126 startsExpr
1127 }),
1128 _checks: createKeywordLike("checks", {
1129 startsExpr
1130 }),
1131 _exports: createKeywordLike("exports", {
1132 startsExpr
1133 }),
1134 _global: createKeywordLike("global", {
1135 startsExpr
1136 }),
1137 _implements: createKeywordLike("implements", {
1138 startsExpr
1139 }),
1140 _intrinsic: createKeywordLike("intrinsic", {
1141 startsExpr
1142 }),
1143 _infer: createKeywordLike("infer", {
1144 startsExpr
1145 }),
1146 _is: createKeywordLike("is", {
1147 startsExpr
1148 }),
1149 _mixins: createKeywordLike("mixins", {
1150 startsExpr
1151 }),
1152 _proto: createKeywordLike("proto", {
1153 startsExpr
1154 }),
1155 _require: createKeywordLike("require", {
1156 startsExpr
1157 }),
1158 _satisfies: createKeywordLike("satisfies", {
1159 startsExpr
1160 }),
1161 _keyof: createKeywordLike("keyof", {
1162 startsExpr
1163 }),
1164 _readonly: createKeywordLike("readonly", {
1165 startsExpr
1166 }),
1167 _unique: createKeywordLike("unique", {
1168 startsExpr
1169 }),
1170 _abstract: createKeywordLike("abstract", {
1171 startsExpr
1172 }),
1173 _declare: createKeywordLike("declare", {
1174 startsExpr
1175 }),
1176 _enum: createKeywordLike("enum", {
1177 startsExpr
1178 }),
1179 _module: createKeywordLike("module", {
1180 startsExpr
1181 }),
1182 _namespace: createKeywordLike("namespace", {
1183 startsExpr
1184 }),
1185 _interface: createKeywordLike("interface", {
1186 startsExpr
1187 }),
1188 _type: createKeywordLike("type", {
1189 startsExpr
1190 }),
1191 _opaque: createKeywordLike("opaque", {
1192 startsExpr
1193 }),
1194 name: createToken("name", {
1195 startsExpr
1196 }),
1197 string: createToken("string", {
1198 startsExpr
1199 }),
1200 num: createToken("num", {
1201 startsExpr
1202 }),
1203 bigint: createToken("bigint", {
1204 startsExpr
1205 }),
1206 decimal: createToken("decimal", {
1207 startsExpr
1208 }),
1209 regexp: createToken("regexp", {
1210 startsExpr
1211 }),
1212 privateName: createToken("#name", {
1213 startsExpr
1214 }),
1215 eof: createToken("eof"),
1216 jsxName: createToken("jsxName"),
1217 jsxText: createToken("jsxText", {
1218 beforeExpr: true
1219 }),
1220 jsxTagStart: createToken("jsxTagStart", {
1221 startsExpr: true
1222 }),
1223 jsxTagEnd: createToken("jsxTagEnd"),
1224 placeholder: createToken("%%", {
1225 startsExpr: true
1226 })
1227};
1228function tokenIsIdentifier(token) {
1229 return token >= 93 && token <= 130;
1230}
1231function tokenKeywordOrIdentifierIsKeyword(token) {
1232 return token <= 92;
1233}
1234function tokenIsKeywordOrIdentifier(token) {
1235 return token >= 58 && token <= 130;
1236}
1237function tokenIsLiteralPropertyName(token) {
1238 return token >= 58 && token <= 134;
1239}
1240function tokenComesBeforeExpression(token) {
1241 return tokenBeforeExprs[token];
1242}
1243function tokenCanStartExpression(token) {
1244 return tokenStartsExprs[token];
1245}
1246function tokenIsAssignment(token) {
1247 return token >= 29 && token <= 33;
1248}
1249function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
1250 return token >= 127 && token <= 129;
1251}
1252function tokenIsLoop(token) {
1253 return token >= 90 && token <= 92;
1254}
1255function tokenIsKeyword(token) {
1256 return token >= 58 && token <= 92;
1257}
1258function tokenIsOperator(token) {
1259 return token >= 39 && token <= 59;
1260}
1261function tokenIsPostfix(token) {
1262 return token === 34;
1263}
1264function tokenIsPrefix(token) {
1265 return tokenPrefixes[token];
1266}
1267function tokenIsTSTypeOperator(token) {
1268 return token >= 119 && token <= 121;
1269}
1270function tokenIsTSDeclarationStart(token) {
1271 return token >= 122 && token <= 128;
1272}
1273function tokenLabelName(token) {
1274 return tokenLabels[token];
1275}
1276function tokenOperatorPrecedence(token) {
1277 return tokenBinops[token];
1278}
1279function tokenIsRightAssociative(token) {
1280 return token === 57;
1281}
1282function tokenIsTemplate(token) {
1283 return token >= 24 && token <= 25;
1284}
1285function getExportedToken(token) {
1286 return tokenTypes[token];
1287}
1288{
1289 tokenTypes[8].updateContext = context => {
1290 context.pop();
1291 };
1292 tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
1293 context.push(types.brace);
1294 };
1295 tokenTypes[22].updateContext = context => {
1296 if (context[context.length - 1] === types.template) {
1297 context.pop();
1298 } else {
1299 context.push(types.template);
1300 }
1301 };
1302 tokenTypes[140].updateContext = context => {
1303 context.push(types.j_expr, types.j_oTag);
1304 };
1305}
1306let 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-\u088e\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\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\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-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\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-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\ua7f2-\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";
1307let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0898-\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-\u1ace\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\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\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";
1308const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
1309const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
1310nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
1311const 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, 68, 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, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 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, 159, 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, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 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, 757, 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, 4153, 7, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938, 6, 4191];
1312const 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, 370, 1, 81, 2, 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, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 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, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 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, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
1313function isInAstralSet(code, set) {
1314 let pos = 0x10000;
1315 for (let i = 0, length = set.length; i < length; i += 2) {
1316 pos += set[i];
1317 if (pos > code) return false;
1318 pos += set[i + 1];
1319 if (pos >= code) return true;
1320 }
1321 return false;
1322}
1323function isIdentifierStart(code) {
1324 if (code < 65) return code === 36;
1325 if (code <= 90) return true;
1326 if (code < 97) return code === 95;
1327 if (code <= 122) return true;
1328 if (code <= 0xffff) {
1329 return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
1330 }
1331 return isInAstralSet(code, astralIdentifierStartCodes);
1332}
1333function isIdentifierChar(code) {
1334 if (code < 48) return code === 36;
1335 if (code < 58) return true;
1336 if (code < 65) return false;
1337 if (code <= 90) return true;
1338 if (code < 97) return code === 95;
1339 if (code <= 122) return true;
1340 if (code <= 0xffff) {
1341 return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
1342 }
1343 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
1344}
1345const reservedWords = {
1346 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"],
1347 strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
1348 strictBind: ["eval", "arguments"]
1349};
1350const keywords = new Set(reservedWords.keyword);
1351const reservedWordsStrictSet = new Set(reservedWords.strict);
1352const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
1353function isReservedWord(word, inModule) {
1354 return inModule && word === "await" || word === "enum";
1355}
1356function isStrictReservedWord(word, inModule) {
1357 return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
1358}
1359function isStrictBindOnlyReservedWord(word) {
1360 return reservedWordsStrictBindSet.has(word);
1361}
1362function isStrictBindReservedWord(word, inModule) {
1363 return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
1364}
1365function isKeyword(word) {
1366 return keywords.has(word);
1367}
1368function isIteratorStart(current, next, next2) {
1369 return current === 64 && next === 64 && isIdentifierStart(next2);
1370}
1371const 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"]);
1372function canBeReservedWord(word) {
1373 return reservedWordLikeSet.has(word);
1374}
1375class Scope {
1376 constructor(flags) {
1377 this.var = new Set();
1378 this.lexical = new Set();
1379 this.functions = new Set();
1380 this.flags = flags;
1381 }
1382}
1383class ScopeHandler {
1384 constructor(parser, inModule) {
1385 this.parser = void 0;
1386 this.scopeStack = [];
1387 this.inModule = void 0;
1388 this.undefinedExports = new Map();
1389 this.parser = parser;
1390 this.inModule = inModule;
1391 }
1392 get inTopLevel() {
1393 return (this.currentScope().flags & 1) > 0;
1394 }
1395 get inFunction() {
1396 return (this.currentVarScopeFlags() & 2) > 0;
1397 }
1398 get allowSuper() {
1399 return (this.currentThisScopeFlags() & 16) > 0;
1400 }
1401 get allowDirectSuper() {
1402 return (this.currentThisScopeFlags() & 32) > 0;
1403 }
1404 get inClass() {
1405 return (this.currentThisScopeFlags() & 64) > 0;
1406 }
1407 get inClassAndNotInNonArrowFunction() {
1408 const flags = this.currentThisScopeFlags();
1409 return (flags & 64) > 0 && (flags & 2) === 0;
1410 }
1411 get inStaticBlock() {
1412 for (let i = this.scopeStack.length - 1;; i--) {
1413 const {
1414 flags
1415 } = this.scopeStack[i];
1416 if (flags & 128) {
1417 return true;
1418 }
1419 if (flags & (387 | 64)) {
1420 return false;
1421 }
1422 }
1423 }
1424 get inNonArrowFunction() {
1425 return (this.currentThisScopeFlags() & 2) > 0;
1426 }
1427 get treatFunctionsAsVar() {
1428 return this.treatFunctionsAsVarInScope(this.currentScope());
1429 }
1430 createScope(flags) {
1431 return new Scope(flags);
1432 }
1433 enter(flags) {
1434 this.scopeStack.push(this.createScope(flags));
1435 }
1436 exit() {
1437 const scope = this.scopeStack.pop();
1438 return scope.flags;
1439 }
1440 treatFunctionsAsVarInScope(scope) {
1441 return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
1442 }
1443 declareName(name, bindingType, loc) {
1444 let scope = this.currentScope();
1445 if (bindingType & 8 || bindingType & 16) {
1446 this.checkRedeclarationInScope(scope, name, bindingType, loc);
1447 if (bindingType & 16) {
1448 scope.functions.add(name);
1449 } else {
1450 scope.lexical.add(name);
1451 }
1452 if (bindingType & 8) {
1453 this.maybeExportDefined(scope, name);
1454 }
1455 } else if (bindingType & 4) {
1456 for (let i = this.scopeStack.length - 1; i >= 0; --i) {
1457 scope = this.scopeStack[i];
1458 this.checkRedeclarationInScope(scope, name, bindingType, loc);
1459 scope.var.add(name);
1460 this.maybeExportDefined(scope, name);
1461 if (scope.flags & 387) break;
1462 }
1463 }
1464 if (this.parser.inModule && scope.flags & 1) {
1465 this.undefinedExports.delete(name);
1466 }
1467 }
1468 maybeExportDefined(scope, name) {
1469 if (this.parser.inModule && scope.flags & 1) {
1470 this.undefinedExports.delete(name);
1471 }
1472 }
1473 checkRedeclarationInScope(scope, name, bindingType, loc) {
1474 if (this.isRedeclaredInScope(scope, name, bindingType)) {
1475 this.parser.raise(Errors.VarRedeclaration, {
1476 at: loc,
1477 identifierName: name
1478 });
1479 }
1480 }
1481 isRedeclaredInScope(scope, name, bindingType) {
1482 if (!(bindingType & 1)) return false;
1483 if (bindingType & 8) {
1484 return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
1485 }
1486 if (bindingType & 16) {
1487 return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
1488 }
1489 return scope.lexical.has(name) && !(scope.flags & 8 && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
1490 }
1491 checkLocalExport(id) {
1492 const {
1493 name
1494 } = id;
1495 const topLevelScope = this.scopeStack[0];
1496 if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
1497 this.undefinedExports.set(name, id.loc.start);
1498 }
1499 }
1500 currentScope() {
1501 return this.scopeStack[this.scopeStack.length - 1];
1502 }
1503 currentVarScopeFlags() {
1504 for (let i = this.scopeStack.length - 1;; i--) {
1505 const {
1506 flags
1507 } = this.scopeStack[i];
1508 if (flags & 387) {
1509 return flags;
1510 }
1511 }
1512 }
1513 currentThisScopeFlags() {
1514 for (let i = this.scopeStack.length - 1;; i--) {
1515 const {
1516 flags
1517 } = this.scopeStack[i];
1518 if (flags & (387 | 64) && !(flags & 4)) {
1519 return flags;
1520 }
1521 }
1522 }
1523}
1524class FlowScope extends Scope {
1525 constructor(...args) {
1526 super(...args);
1527 this.declareFunctions = new Set();
1528 }
1529}
1530class FlowScopeHandler extends ScopeHandler {
1531 createScope(flags) {
1532 return new FlowScope(flags);
1533 }
1534 declareName(name, bindingType, loc) {
1535 const scope = this.currentScope();
1536 if (bindingType & 2048) {
1537 this.checkRedeclarationInScope(scope, name, bindingType, loc);
1538 this.maybeExportDefined(scope, name);
1539 scope.declareFunctions.add(name);
1540 return;
1541 }
1542 super.declareName(name, bindingType, loc);
1543 }
1544 isRedeclaredInScope(scope, name, bindingType) {
1545 if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
1546 if (bindingType & 2048) {
1547 return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
1548 }
1549 return false;
1550 }
1551 checkLocalExport(id) {
1552 if (!this.scopeStack[0].declareFunctions.has(id.name)) {
1553 super.checkLocalExport(id);
1554 }
1555 }
1556}
1557class BaseParser {
1558 constructor() {
1559 this.sawUnambiguousESM = false;
1560 this.ambiguousScriptDifferentAst = false;
1561 }
1562 hasPlugin(pluginConfig) {
1563 if (typeof pluginConfig === "string") {
1564 return this.plugins.has(pluginConfig);
1565 } else {
1566 const [pluginName, pluginOptions] = pluginConfig;
1567 if (!this.hasPlugin(pluginName)) {
1568 return false;
1569 }
1570 const actualOptions = this.plugins.get(pluginName);
1571 for (const key of Object.keys(pluginOptions)) {
1572 if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
1573 return false;
1574 }
1575 }
1576 return true;
1577 }
1578 }
1579 getPluginOption(plugin, name) {
1580 var _this$plugins$get;
1581 return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
1582 }
1583}
1584function setTrailingComments(node, comments) {
1585 if (node.trailingComments === undefined) {
1586 node.trailingComments = comments;
1587 } else {
1588 node.trailingComments.unshift(...comments);
1589 }
1590}
1591function setLeadingComments(node, comments) {
1592 if (node.leadingComments === undefined) {
1593 node.leadingComments = comments;
1594 } else {
1595 node.leadingComments.unshift(...comments);
1596 }
1597}
1598function setInnerComments(node, comments) {
1599 if (node.innerComments === undefined) {
1600 node.innerComments = comments;
1601 } else {
1602 node.innerComments.unshift(...comments);
1603 }
1604}
1605function adjustInnerComments(node, elements, commentWS) {
1606 let lastElement = null;
1607 let i = elements.length;
1608 while (lastElement === null && i > 0) {
1609 lastElement = elements[--i];
1610 }
1611 if (lastElement === null || lastElement.start > commentWS.start) {
1612 setInnerComments(node, commentWS.comments);
1613 } else {
1614 setTrailingComments(lastElement, commentWS.comments);
1615 }
1616}
1617class CommentsParser extends BaseParser {
1618 addComment(comment) {
1619 if (this.filename) comment.loc.filename = this.filename;
1620 this.state.comments.push(comment);
1621 }
1622 processComment(node) {
1623 const {
1624 commentStack
1625 } = this.state;
1626 const commentStackLength = commentStack.length;
1627 if (commentStackLength === 0) return;
1628 let i = commentStackLength - 1;
1629 const lastCommentWS = commentStack[i];
1630 if (lastCommentWS.start === node.end) {
1631 lastCommentWS.leadingNode = node;
1632 i--;
1633 }
1634 const {
1635 start: nodeStart
1636 } = node;
1637 for (; i >= 0; i--) {
1638 const commentWS = commentStack[i];
1639 const commentEnd = commentWS.end;
1640 if (commentEnd > nodeStart) {
1641 commentWS.containingNode = node;
1642 this.finalizeComment(commentWS);
1643 commentStack.splice(i, 1);
1644 } else {
1645 if (commentEnd === nodeStart) {
1646 commentWS.trailingNode = node;
1647 }
1648 break;
1649 }
1650 }
1651 }
1652 finalizeComment(commentWS) {
1653 const {
1654 comments
1655 } = commentWS;
1656 if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
1657 if (commentWS.leadingNode !== null) {
1658 setTrailingComments(commentWS.leadingNode, comments);
1659 }
1660 if (commentWS.trailingNode !== null) {
1661 setLeadingComments(commentWS.trailingNode, comments);
1662 }
1663 } else {
1664 const {
1665 containingNode: node,
1666 start: commentStart
1667 } = commentWS;
1668 if (this.input.charCodeAt(commentStart - 1) === 44) {
1669 switch (node.type) {
1670 case "ObjectExpression":
1671 case "ObjectPattern":
1672 case "RecordExpression":
1673 adjustInnerComments(node, node.properties, commentWS);
1674 break;
1675 case "CallExpression":
1676 case "OptionalCallExpression":
1677 adjustInnerComments(node, node.arguments, commentWS);
1678 break;
1679 case "FunctionDeclaration":
1680 case "FunctionExpression":
1681 case "ArrowFunctionExpression":
1682 case "ObjectMethod":
1683 case "ClassMethod":
1684 case "ClassPrivateMethod":
1685 adjustInnerComments(node, node.params, commentWS);
1686 break;
1687 case "ArrayExpression":
1688 case "ArrayPattern":
1689 case "TupleExpression":
1690 adjustInnerComments(node, node.elements, commentWS);
1691 break;
1692 case "ExportNamedDeclaration":
1693 case "ImportDeclaration":
1694 adjustInnerComments(node, node.specifiers, commentWS);
1695 break;
1696 default:
1697 {
1698 setInnerComments(node, comments);
1699 }
1700 }
1701 } else {
1702 setInnerComments(node, comments);
1703 }
1704 }
1705 }
1706 finalizeRemainingComments() {
1707 const {
1708 commentStack
1709 } = this.state;
1710 for (let i = commentStack.length - 1; i >= 0; i--) {
1711 this.finalizeComment(commentStack[i]);
1712 }
1713 this.state.commentStack = [];
1714 }
1715 resetPreviousNodeTrailingComments(node) {
1716 const {
1717 commentStack
1718 } = this.state;
1719 const {
1720 length
1721 } = commentStack;
1722 if (length === 0) return;
1723 const commentWS = commentStack[length - 1];
1724 if (commentWS.leadingNode === node) {
1725 commentWS.leadingNode = null;
1726 }
1727 }
1728 resetPreviousIdentifierLeadingComments(node) {
1729 const {
1730 commentStack
1731 } = this.state;
1732 const {
1733 length
1734 } = commentStack;
1735 if (length === 0) return;
1736 if (commentStack[length - 1].trailingNode === node) {
1737 commentStack[length - 1].trailingNode = null;
1738 } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
1739 commentStack[length - 2].trailingNode = null;
1740 }
1741 }
1742 takeSurroundingComments(node, start, end) {
1743 const {
1744 commentStack
1745 } = this.state;
1746 const commentStackLength = commentStack.length;
1747 if (commentStackLength === 0) return;
1748 let i = commentStackLength - 1;
1749 for (; i >= 0; i--) {
1750 const commentWS = commentStack[i];
1751 const commentEnd = commentWS.end;
1752 const commentStart = commentWS.start;
1753 if (commentStart === end) {
1754 commentWS.leadingNode = node;
1755 } else if (commentEnd === start) {
1756 commentWS.trailingNode = node;
1757 } else if (commentEnd < start) {
1758 break;
1759 }
1760 }
1761 }
1762}
1763const lineBreak = /\r\n?|[\n\u2028\u2029]/;
1764const lineBreakG = new RegExp(lineBreak.source, "g");
1765function isNewLine(code) {
1766 switch (code) {
1767 case 10:
1768 case 13:
1769 case 8232:
1770 case 8233:
1771 return true;
1772 default:
1773 return false;
1774 }
1775}
1776const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
1777const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
1778const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
1779function isWhitespace(code) {
1780 switch (code) {
1781 case 0x0009:
1782 case 0x000b:
1783 case 0x000c:
1784 case 32:
1785 case 160:
1786 case 5760:
1787 case 0x2000:
1788 case 0x2001:
1789 case 0x2002:
1790 case 0x2003:
1791 case 0x2004:
1792 case 0x2005:
1793 case 0x2006:
1794 case 0x2007:
1795 case 0x2008:
1796 case 0x2009:
1797 case 0x200a:
1798 case 0x202f:
1799 case 0x205f:
1800 case 0x3000:
1801 case 0xfeff:
1802 return true;
1803 default:
1804 return false;
1805 }
1806}
1807class State {
1808 constructor() {
1809 this.strict = void 0;
1810 this.curLine = void 0;
1811 this.lineStart = void 0;
1812 this.startLoc = void 0;
1813 this.endLoc = void 0;
1814 this.errors = [];
1815 this.potentialArrowAt = -1;
1816 this.noArrowAt = [];
1817 this.noArrowParamsConversionAt = [];
1818 this.maybeInArrowParameters = false;
1819 this.inType = false;
1820 this.noAnonFunctionType = false;
1821 this.hasFlowComment = false;
1822 this.isAmbientContext = false;
1823 this.inAbstractClass = false;
1824 this.inDisallowConditionalTypesContext = false;
1825 this.topicContext = {
1826 maxNumOfResolvableTopics: 0,
1827 maxTopicIndex: null
1828 };
1829 this.soloAwait = false;
1830 this.inFSharpPipelineDirectBody = false;
1831 this.labels = [];
1832 this.comments = [];
1833 this.commentStack = [];
1834 this.pos = 0;
1835 this.type = 137;
1836 this.value = null;
1837 this.start = 0;
1838 this.end = 0;
1839 this.lastTokEndLoc = null;
1840 this.lastTokStartLoc = null;
1841 this.lastTokStart = 0;
1842 this.context = [types.brace];
1843 this.canStartJSXElement = true;
1844 this.containsEsc = false;
1845 this.firstInvalidTemplateEscapePos = null;
1846 this.strictErrors = new Map();
1847 this.tokensLength = 0;
1848 }
1849 init({
1850 strictMode,
1851 sourceType,
1852 startLine,
1853 startColumn
1854 }) {
1855 this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
1856 this.curLine = startLine;
1857 this.lineStart = -startColumn;
1858 this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
1859 }
1860 curPosition() {
1861 return new Position(this.curLine, this.pos - this.lineStart, this.pos);
1862 }
1863 clone(skipArrays) {
1864 const state = new State();
1865 const keys = Object.keys(this);
1866 for (let i = 0, length = keys.length; i < length; i++) {
1867 const key = keys[i];
1868 let val = this[key];
1869 if (!skipArrays && Array.isArray(val)) {
1870 val = val.slice();
1871 }
1872 state[key] = val;
1873 }
1874 return state;
1875 }
1876}
1877var _isDigit = function isDigit(code) {
1878 return code >= 48 && code <= 57;
1879};
1880const forbiddenNumericSeparatorSiblings = {
1881 decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
1882 hex: new Set([46, 88, 95, 120])
1883};
1884const isAllowedNumericSeparatorSibling = {
1885 bin: ch => ch === 48 || ch === 49,
1886 oct: ch => ch >= 48 && ch <= 55,
1887 dec: ch => ch >= 48 && ch <= 57,
1888 hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
1889};
1890function readStringContents(type, input, pos, lineStart, curLine, errors) {
1891 const initialPos = pos;
1892 const initialLineStart = lineStart;
1893 const initialCurLine = curLine;
1894 let out = "";
1895 let firstInvalidLoc = null;
1896 let chunkStart = pos;
1897 const {
1898 length
1899 } = input;
1900 for (;;) {
1901 if (pos >= length) {
1902 errors.unterminated(initialPos, initialLineStart, initialCurLine);
1903 out += input.slice(chunkStart, pos);
1904 break;
1905 }
1906 const ch = input.charCodeAt(pos);
1907 if (isStringEnd(type, ch, input, pos)) {
1908 out += input.slice(chunkStart, pos);
1909 break;
1910 }
1911 if (ch === 92) {
1912 out += input.slice(chunkStart, pos);
1913 const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
1914 if (res.ch === null && !firstInvalidLoc) {
1915 firstInvalidLoc = {
1916 pos,
1917 lineStart,
1918 curLine
1919 };
1920 } else {
1921 out += res.ch;
1922 }
1923 ({
1924 pos,
1925 lineStart,
1926 curLine
1927 } = res);
1928 chunkStart = pos;
1929 } else if (ch === 8232 || ch === 8233) {
1930 ++pos;
1931 ++curLine;
1932 lineStart = pos;
1933 } else if (ch === 10 || ch === 13) {
1934 if (type === "template") {
1935 out += input.slice(chunkStart, pos) + "\n";
1936 ++pos;
1937 if (ch === 13 && input.charCodeAt(pos) === 10) {
1938 ++pos;
1939 }
1940 ++curLine;
1941 chunkStart = lineStart = pos;
1942 } else {
1943 errors.unterminated(initialPos, initialLineStart, initialCurLine);
1944 }
1945 } else {
1946 ++pos;
1947 }
1948 }
1949 return {
1950 pos,
1951 str: out,
1952 firstInvalidLoc,
1953 lineStart,
1954 curLine,
1955 containsInvalid: !!firstInvalidLoc
1956 };
1957}
1958function isStringEnd(type, ch, input, pos) {
1959 if (type === "template") {
1960 return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
1961 }
1962 return ch === (type === "double" ? 34 : 39);
1963}
1964function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
1965 const throwOnInvalid = !inTemplate;
1966 pos++;
1967 const res = ch => ({
1968 pos,
1969 ch,
1970 lineStart,
1971 curLine
1972 });
1973 const ch = input.charCodeAt(pos++);
1974 switch (ch) {
1975 case 110:
1976 return res("\n");
1977 case 114:
1978 return res("\r");
1979 case 120:
1980 {
1981 let code;
1982 ({
1983 code,
1984 pos
1985 } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
1986 return res(code === null ? null : String.fromCharCode(code));
1987 }
1988 case 117:
1989 {
1990 let code;
1991 ({
1992 code,
1993 pos
1994 } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
1995 return res(code === null ? null : String.fromCodePoint(code));
1996 }
1997 case 116:
1998 return res("\t");
1999 case 98:
2000 return res("\b");
2001 case 118:
2002 return res("\u000b");
2003 case 102:
2004 return res("\f");
2005 case 13:
2006 if (input.charCodeAt(pos) === 10) {
2007 ++pos;
2008 }
2009 case 10:
2010 lineStart = pos;
2011 ++curLine;
2012 case 8232:
2013 case 8233:
2014 return res("");
2015 case 56:
2016 case 57:
2017 if (inTemplate) {
2018 return res(null);
2019 } else {
2020 errors.strictNumericEscape(pos - 1, lineStart, curLine);
2021 }
2022 default:
2023 if (ch >= 48 && ch <= 55) {
2024 const startPos = pos - 1;
2025 const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
2026 let octalStr = match[0];
2027 let octal = parseInt(octalStr, 8);
2028 if (octal > 255) {
2029 octalStr = octalStr.slice(0, -1);
2030 octal = parseInt(octalStr, 8);
2031 }
2032 pos += octalStr.length - 1;
2033 const next = input.charCodeAt(pos);
2034 if (octalStr !== "0" || next === 56 || next === 57) {
2035 if (inTemplate) {
2036 return res(null);
2037 } else {
2038 errors.strictNumericEscape(startPos, lineStart, curLine);
2039 }
2040 }
2041 return res(String.fromCharCode(octal));
2042 }
2043 return res(String.fromCharCode(ch));
2044 }
2045}
2046function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
2047 const initialPos = pos;
2048 let n;
2049 ({
2050 n,
2051 pos
2052 } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
2053 if (n === null) {
2054 if (throwOnInvalid) {
2055 errors.invalidEscapeSequence(initialPos, lineStart, curLine);
2056 } else {
2057 pos = initialPos - 1;
2058 }
2059 }
2060 return {
2061 code: n,
2062 pos
2063 };
2064}
2065function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
2066 const start = pos;
2067 const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
2068 const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
2069 let invalid = false;
2070 let total = 0;
2071 for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
2072 const code = input.charCodeAt(pos);
2073 let val;
2074 if (code === 95 && allowNumSeparator !== "bail") {
2075 const prev = input.charCodeAt(pos - 1);
2076 const next = input.charCodeAt(pos + 1);
2077 if (!allowNumSeparator) {
2078 if (bailOnError) return {
2079 n: null,
2080 pos
2081 };
2082 errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
2083 } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
2084 if (bailOnError) return {
2085 n: null,
2086 pos
2087 };
2088 errors.unexpectedNumericSeparator(pos, lineStart, curLine);
2089 }
2090 ++pos;
2091 continue;
2092 }
2093 if (code >= 97) {
2094 val = code - 97 + 10;
2095 } else if (code >= 65) {
2096 val = code - 65 + 10;
2097 } else if (_isDigit(code)) {
2098 val = code - 48;
2099 } else {
2100 val = Infinity;
2101 }
2102 if (val >= radix) {
2103 if (val <= 9 && bailOnError) {
2104 return {
2105 n: null,
2106 pos
2107 };
2108 } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
2109 val = 0;
2110 } else if (forceLen) {
2111 val = 0;
2112 invalid = true;
2113 } else {
2114 break;
2115 }
2116 }
2117 ++pos;
2118 total = total * radix + val;
2119 }
2120 if (pos === start || len != null && pos - start !== len || invalid) {
2121 return {
2122 n: null,
2123 pos
2124 };
2125 }
2126 return {
2127 n: total,
2128 pos
2129 };
2130}
2131function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
2132 const ch = input.charCodeAt(pos);
2133 let code;
2134 if (ch === 123) {
2135 ++pos;
2136 ({
2137 code,
2138 pos
2139 } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
2140 ++pos;
2141 if (code !== null && code > 0x10ffff) {
2142 if (throwOnInvalid) {
2143 errors.invalidCodePoint(pos, lineStart, curLine);
2144 } else {
2145 return {
2146 code: null,
2147 pos
2148 };
2149 }
2150 }
2151 } else {
2152 ({
2153 code,
2154 pos
2155 } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
2156 }
2157 return {
2158 code,
2159 pos
2160 };
2161}
2162const _excluded = ["at"],
2163 _excluded2 = ["at"];
2164function buildPosition(pos, lineStart, curLine) {
2165 return new Position(curLine, pos - lineStart, pos);
2166}
2167const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
2168class Token {
2169 constructor(state) {
2170 this.type = state.type;
2171 this.value = state.value;
2172 this.start = state.start;
2173 this.end = state.end;
2174 this.loc = new SourceLocation(state.startLoc, state.endLoc);
2175 }
2176}
2177class Tokenizer extends CommentsParser {
2178 constructor(options, input) {
2179 super();
2180 this.isLookahead = void 0;
2181 this.tokens = [];
2182 this.errorHandlers_readInt = {
2183 invalidDigit: (pos, lineStart, curLine, radix) => {
2184 if (!this.options.errorRecovery) return false;
2185 this.raise(Errors.InvalidDigit, {
2186 at: buildPosition(pos, lineStart, curLine),
2187 radix
2188 });
2189 return true;
2190 },
2191 numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
2192 unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
2193 };
2194 this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
2195 invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
2196 invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
2197 });
2198 this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
2199 strictNumericEscape: (pos, lineStart, curLine) => {
2200 this.recordStrictModeErrors(Errors.StrictNumericEscape, {
2201 at: buildPosition(pos, lineStart, curLine)
2202 });
2203 },
2204 unterminated: (pos, lineStart, curLine) => {
2205 throw this.raise(Errors.UnterminatedString, {
2206 at: buildPosition(pos - 1, lineStart, curLine)
2207 });
2208 }
2209 });
2210 this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
2211 strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
2212 unterminated: (pos, lineStart, curLine) => {
2213 throw this.raise(Errors.UnterminatedTemplate, {
2214 at: buildPosition(pos, lineStart, curLine)
2215 });
2216 }
2217 });
2218 this.state = new State();
2219 this.state.init(options);
2220 this.input = input;
2221 this.length = input.length;
2222 this.isLookahead = false;
2223 }
2224 pushToken(token) {
2225 this.tokens.length = this.state.tokensLength;
2226 this.tokens.push(token);
2227 ++this.state.tokensLength;
2228 }
2229 next() {
2230 this.checkKeywordEscapes();
2231 if (this.options.tokens) {
2232 this.pushToken(new Token(this.state));
2233 }
2234 this.state.lastTokStart = this.state.start;
2235 this.state.lastTokEndLoc = this.state.endLoc;
2236 this.state.lastTokStartLoc = this.state.startLoc;
2237 this.nextToken();
2238 }
2239 eat(type) {
2240 if (this.match(type)) {
2241 this.next();
2242 return true;
2243 } else {
2244 return false;
2245 }
2246 }
2247 match(type) {
2248 return this.state.type === type;
2249 }
2250 createLookaheadState(state) {
2251 return {
2252 pos: state.pos,
2253 value: null,
2254 type: state.type,
2255 start: state.start,
2256 end: state.end,
2257 context: [this.curContext()],
2258 inType: state.inType,
2259 startLoc: state.startLoc,
2260 lastTokEndLoc: state.lastTokEndLoc,
2261 curLine: state.curLine,
2262 lineStart: state.lineStart,
2263 curPosition: state.curPosition
2264 };
2265 }
2266 lookahead() {
2267 const old = this.state;
2268 this.state = this.createLookaheadState(old);
2269 this.isLookahead = true;
2270 this.nextToken();
2271 this.isLookahead = false;
2272 const curr = this.state;
2273 this.state = old;
2274 return curr;
2275 }
2276 nextTokenStart() {
2277 return this.nextTokenStartSince(this.state.pos);
2278 }
2279 nextTokenStartSince(pos) {
2280 skipWhiteSpace.lastIndex = pos;
2281 return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
2282 }
2283 lookaheadCharCode() {
2284 return this.input.charCodeAt(this.nextTokenStart());
2285 }
2286 nextTokenInLineStart() {
2287 return this.nextTokenInLineStartSince(this.state.pos);
2288 }
2289 nextTokenInLineStartSince(pos) {
2290 skipWhiteSpaceInLine.lastIndex = pos;
2291 return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
2292 }
2293 lookaheadInLineCharCode() {
2294 return this.input.charCodeAt(this.nextTokenInLineStart());
2295 }
2296 codePointAtPos(pos) {
2297 let cp = this.input.charCodeAt(pos);
2298 if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
2299 const trail = this.input.charCodeAt(pos);
2300 if ((trail & 0xfc00) === 0xdc00) {
2301 cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
2302 }
2303 }
2304 return cp;
2305 }
2306 setStrict(strict) {
2307 this.state.strict = strict;
2308 if (strict) {
2309 this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
2310 at
2311 }));
2312 this.state.strictErrors.clear();
2313 }
2314 }
2315 curContext() {
2316 return this.state.context[this.state.context.length - 1];
2317 }
2318 nextToken() {
2319 this.skipSpace();
2320 this.state.start = this.state.pos;
2321 if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
2322 if (this.state.pos >= this.length) {
2323 this.finishToken(137);
2324 return;
2325 }
2326 this.getTokenFromCode(this.codePointAtPos(this.state.pos));
2327 }
2328 skipBlockComment(commentEnd) {
2329 let startLoc;
2330 if (!this.isLookahead) startLoc = this.state.curPosition();
2331 const start = this.state.pos;
2332 const end = this.input.indexOf(commentEnd, start + 2);
2333 if (end === -1) {
2334 throw this.raise(Errors.UnterminatedComment, {
2335 at: this.state.curPosition()
2336 });
2337 }
2338 this.state.pos = end + commentEnd.length;
2339 lineBreakG.lastIndex = start + 2;
2340 while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
2341 ++this.state.curLine;
2342 this.state.lineStart = lineBreakG.lastIndex;
2343 }
2344 if (this.isLookahead) return;
2345 const comment = {
2346 type: "CommentBlock",
2347 value: this.input.slice(start + 2, end),
2348 start,
2349 end: end + commentEnd.length,
2350 loc: new SourceLocation(startLoc, this.state.curPosition())
2351 };
2352 if (this.options.tokens) this.pushToken(comment);
2353 return comment;
2354 }
2355 skipLineComment(startSkip) {
2356 const start = this.state.pos;
2357 let startLoc;
2358 if (!this.isLookahead) startLoc = this.state.curPosition();
2359 let ch = this.input.charCodeAt(this.state.pos += startSkip);
2360 if (this.state.pos < this.length) {
2361 while (!isNewLine(ch) && ++this.state.pos < this.length) {
2362 ch = this.input.charCodeAt(this.state.pos);
2363 }
2364 }
2365 if (this.isLookahead) return;
2366 const end = this.state.pos;
2367 const value = this.input.slice(start + startSkip, end);
2368 const comment = {
2369 type: "CommentLine",
2370 value,
2371 start,
2372 end,
2373 loc: new SourceLocation(startLoc, this.state.curPosition())
2374 };
2375 if (this.options.tokens) this.pushToken(comment);
2376 return comment;
2377 }
2378 skipSpace() {
2379 const spaceStart = this.state.pos;
2380 const comments = [];
2381 loop: while (this.state.pos < this.length) {
2382 const ch = this.input.charCodeAt(this.state.pos);
2383 switch (ch) {
2384 case 32:
2385 case 160:
2386 case 9:
2387 ++this.state.pos;
2388 break;
2389 case 13:
2390 if (this.input.charCodeAt(this.state.pos + 1) === 10) {
2391 ++this.state.pos;
2392 }
2393 case 10:
2394 case 8232:
2395 case 8233:
2396 ++this.state.pos;
2397 ++this.state.curLine;
2398 this.state.lineStart = this.state.pos;
2399 break;
2400 case 47:
2401 switch (this.input.charCodeAt(this.state.pos + 1)) {
2402 case 42:
2403 {
2404 const comment = this.skipBlockComment("*/");
2405 if (comment !== undefined) {
2406 this.addComment(comment);
2407 if (this.options.attachComment) comments.push(comment);
2408 }
2409 break;
2410 }
2411 case 47:
2412 {
2413 const comment = this.skipLineComment(2);
2414 if (comment !== undefined) {
2415 this.addComment(comment);
2416 if (this.options.attachComment) comments.push(comment);
2417 }
2418 break;
2419 }
2420 default:
2421 break loop;
2422 }
2423 break;
2424 default:
2425 if (isWhitespace(ch)) {
2426 ++this.state.pos;
2427 } else if (ch === 45 && !this.inModule && this.options.annexB) {
2428 const pos = this.state.pos;
2429 if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
2430 const comment = this.skipLineComment(3);
2431 if (comment !== undefined) {
2432 this.addComment(comment);
2433 if (this.options.attachComment) comments.push(comment);
2434 }
2435 } else {
2436 break loop;
2437 }
2438 } else if (ch === 60 && !this.inModule && this.options.annexB) {
2439 const pos = this.state.pos;
2440 if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
2441 const comment = this.skipLineComment(4);
2442 if (comment !== undefined) {
2443 this.addComment(comment);
2444 if (this.options.attachComment) comments.push(comment);
2445 }
2446 } else {
2447 break loop;
2448 }
2449 } else {
2450 break loop;
2451 }
2452 }
2453 }
2454 if (comments.length > 0) {
2455 const end = this.state.pos;
2456 const commentWhitespace = {
2457 start: spaceStart,
2458 end,
2459 comments,
2460 leadingNode: null,
2461 trailingNode: null,
2462 containingNode: null
2463 };
2464 this.state.commentStack.push(commentWhitespace);
2465 }
2466 }
2467 finishToken(type, val) {
2468 this.state.end = this.state.pos;
2469 this.state.endLoc = this.state.curPosition();
2470 const prevType = this.state.type;
2471 this.state.type = type;
2472 this.state.value = val;
2473 if (!this.isLookahead) {
2474 this.updateContext(prevType);
2475 }
2476 }
2477 replaceToken(type) {
2478 this.state.type = type;
2479 this.updateContext();
2480 }
2481 readToken_numberSign() {
2482 if (this.state.pos === 0 && this.readToken_interpreter()) {
2483 return;
2484 }
2485 const nextPos = this.state.pos + 1;
2486 const next = this.codePointAtPos(nextPos);
2487 if (next >= 48 && next <= 57) {
2488 throw this.raise(Errors.UnexpectedDigitAfterHash, {
2489 at: this.state.curPosition()
2490 });
2491 }
2492 if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
2493 this.expectPlugin("recordAndTuple");
2494 if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
2495 throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
2496 at: this.state.curPosition()
2497 });
2498 }
2499 this.state.pos += 2;
2500 if (next === 123) {
2501 this.finishToken(7);
2502 } else {
2503 this.finishToken(1);
2504 }
2505 } else if (isIdentifierStart(next)) {
2506 ++this.state.pos;
2507 this.finishToken(136, this.readWord1(next));
2508 } else if (next === 92) {
2509 ++this.state.pos;
2510 this.finishToken(136, this.readWord1());
2511 } else {
2512 this.finishOp(27, 1);
2513 }
2514 }
2515 readToken_dot() {
2516 const next = this.input.charCodeAt(this.state.pos + 1);
2517 if (next >= 48 && next <= 57) {
2518 this.readNumber(true);
2519 return;
2520 }
2521 if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
2522 this.state.pos += 3;
2523 this.finishToken(21);
2524 } else {
2525 ++this.state.pos;
2526 this.finishToken(16);
2527 }
2528 }
2529 readToken_slash() {
2530 const next = this.input.charCodeAt(this.state.pos + 1);
2531 if (next === 61) {
2532 this.finishOp(31, 2);
2533 } else {
2534 this.finishOp(56, 1);
2535 }
2536 }
2537 readToken_interpreter() {
2538 if (this.state.pos !== 0 || this.length < 2) return false;
2539 let ch = this.input.charCodeAt(this.state.pos + 1);
2540 if (ch !== 33) return false;
2541 const start = this.state.pos;
2542 this.state.pos += 1;
2543 while (!isNewLine(ch) && ++this.state.pos < this.length) {
2544 ch = this.input.charCodeAt(this.state.pos);
2545 }
2546 const value = this.input.slice(start + 2, this.state.pos);
2547 this.finishToken(28, value);
2548 return true;
2549 }
2550 readToken_mult_modulo(code) {
2551 let type = code === 42 ? 55 : 54;
2552 let width = 1;
2553 let next = this.input.charCodeAt(this.state.pos + 1);
2554 if (code === 42 && next === 42) {
2555 width++;
2556 next = this.input.charCodeAt(this.state.pos + 2);
2557 type = 57;
2558 }
2559 if (next === 61 && !this.state.inType) {
2560 width++;
2561 type = code === 37 ? 33 : 30;
2562 }
2563 this.finishOp(type, width);
2564 }
2565 readToken_pipe_amp(code) {
2566 const next = this.input.charCodeAt(this.state.pos + 1);
2567 if (next === code) {
2568 if (this.input.charCodeAt(this.state.pos + 2) === 61) {
2569 this.finishOp(30, 3);
2570 } else {
2571 this.finishOp(code === 124 ? 41 : 42, 2);
2572 }
2573 return;
2574 }
2575 if (code === 124) {
2576 if (next === 62) {
2577 this.finishOp(39, 2);
2578 return;
2579 }
2580 if (this.hasPlugin("recordAndTuple") && next === 125) {
2581 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
2582 throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
2583 at: this.state.curPosition()
2584 });
2585 }
2586 this.state.pos += 2;
2587 this.finishToken(9);
2588 return;
2589 }
2590 if (this.hasPlugin("recordAndTuple") && next === 93) {
2591 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
2592 throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
2593 at: this.state.curPosition()
2594 });
2595 }
2596 this.state.pos += 2;
2597 this.finishToken(4);
2598 return;
2599 }
2600 }
2601 if (next === 61) {
2602 this.finishOp(30, 2);
2603 return;
2604 }
2605 this.finishOp(code === 124 ? 43 : 45, 1);
2606 }
2607 readToken_caret() {
2608 const next = this.input.charCodeAt(this.state.pos + 1);
2609 if (next === 61 && !this.state.inType) {
2610 this.finishOp(32, 2);
2611 } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
2612 proposal: "hack",
2613 topicToken: "^^"
2614 }])) {
2615 this.finishOp(37, 2);
2616 const lookaheadCh = this.input.codePointAt(this.state.pos);
2617 if (lookaheadCh === 94) {
2618 this.unexpected();
2619 }
2620 } else {
2621 this.finishOp(44, 1);
2622 }
2623 }
2624 readToken_atSign() {
2625 const next = this.input.charCodeAt(this.state.pos + 1);
2626 if (next === 64 && this.hasPlugin(["pipelineOperator", {
2627 proposal: "hack",
2628 topicToken: "@@"
2629 }])) {
2630 this.finishOp(38, 2);
2631 } else {
2632 this.finishOp(26, 1);
2633 }
2634 }
2635 readToken_plus_min(code) {
2636 const next = this.input.charCodeAt(this.state.pos + 1);
2637 if (next === code) {
2638 this.finishOp(34, 2);
2639 return;
2640 }
2641 if (next === 61) {
2642 this.finishOp(30, 2);
2643 } else {
2644 this.finishOp(53, 1);
2645 }
2646 }
2647 readToken_lt() {
2648 const {
2649 pos
2650 } = this.state;
2651 const next = this.input.charCodeAt(pos + 1);
2652 if (next === 60) {
2653 if (this.input.charCodeAt(pos + 2) === 61) {
2654 this.finishOp(30, 3);
2655 return;
2656 }
2657 this.finishOp(51, 2);
2658 return;
2659 }
2660 if (next === 61) {
2661 this.finishOp(49, 2);
2662 return;
2663 }
2664 this.finishOp(47, 1);
2665 }
2666 readToken_gt() {
2667 const {
2668 pos
2669 } = this.state;
2670 const next = this.input.charCodeAt(pos + 1);
2671 if (next === 62) {
2672 const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
2673 if (this.input.charCodeAt(pos + size) === 61) {
2674 this.finishOp(30, size + 1);
2675 return;
2676 }
2677 this.finishOp(52, size);
2678 return;
2679 }
2680 if (next === 61) {
2681 this.finishOp(49, 2);
2682 return;
2683 }
2684 this.finishOp(48, 1);
2685 }
2686 readToken_eq_excl(code) {
2687 const next = this.input.charCodeAt(this.state.pos + 1);
2688 if (next === 61) {
2689 this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
2690 return;
2691 }
2692 if (code === 61 && next === 62) {
2693 this.state.pos += 2;
2694 this.finishToken(19);
2695 return;
2696 }
2697 this.finishOp(code === 61 ? 29 : 35, 1);
2698 }
2699 readToken_question() {
2700 const next = this.input.charCodeAt(this.state.pos + 1);
2701 const next2 = this.input.charCodeAt(this.state.pos + 2);
2702 if (next === 63) {
2703 if (next2 === 61) {
2704 this.finishOp(30, 3);
2705 } else {
2706 this.finishOp(40, 2);
2707 }
2708 } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
2709 this.state.pos += 2;
2710 this.finishToken(18);
2711 } else {
2712 ++this.state.pos;
2713 this.finishToken(17);
2714 }
2715 }
2716 getTokenFromCode(code) {
2717 switch (code) {
2718 case 46:
2719 this.readToken_dot();
2720 return;
2721 case 40:
2722 ++this.state.pos;
2723 this.finishToken(10);
2724 return;
2725 case 41:
2726 ++this.state.pos;
2727 this.finishToken(11);
2728 return;
2729 case 59:
2730 ++this.state.pos;
2731 this.finishToken(13);
2732 return;
2733 case 44:
2734 ++this.state.pos;
2735 this.finishToken(12);
2736 return;
2737 case 91:
2738 if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
2739 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
2740 throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
2741 at: this.state.curPosition()
2742 });
2743 }
2744 this.state.pos += 2;
2745 this.finishToken(2);
2746 } else {
2747 ++this.state.pos;
2748 this.finishToken(0);
2749 }
2750 return;
2751 case 93:
2752 ++this.state.pos;
2753 this.finishToken(3);
2754 return;
2755 case 123:
2756 if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
2757 if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
2758 throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
2759 at: this.state.curPosition()
2760 });
2761 }
2762 this.state.pos += 2;
2763 this.finishToken(6);
2764 } else {
2765 ++this.state.pos;
2766 this.finishToken(5);
2767 }
2768 return;
2769 case 125:
2770 ++this.state.pos;
2771 this.finishToken(8);
2772 return;
2773 case 58:
2774 if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
2775 this.finishOp(15, 2);
2776 } else {
2777 ++this.state.pos;
2778 this.finishToken(14);
2779 }
2780 return;
2781 case 63:
2782 this.readToken_question();
2783 return;
2784 case 96:
2785 this.readTemplateToken();
2786 return;
2787 case 48:
2788 {
2789 const next = this.input.charCodeAt(this.state.pos + 1);
2790 if (next === 120 || next === 88) {
2791 this.readRadixNumber(16);
2792 return;
2793 }
2794 if (next === 111 || next === 79) {
2795 this.readRadixNumber(8);
2796 return;
2797 }
2798 if (next === 98 || next === 66) {
2799 this.readRadixNumber(2);
2800 return;
2801 }
2802 }
2803 case 49:
2804 case 50:
2805 case 51:
2806 case 52:
2807 case 53:
2808 case 54:
2809 case 55:
2810 case 56:
2811 case 57:
2812 this.readNumber(false);
2813 return;
2814 case 34:
2815 case 39:
2816 this.readString(code);
2817 return;
2818 case 47:
2819 this.readToken_slash();
2820 return;
2821 case 37:
2822 case 42:
2823 this.readToken_mult_modulo(code);
2824 return;
2825 case 124:
2826 case 38:
2827 this.readToken_pipe_amp(code);
2828 return;
2829 case 94:
2830 this.readToken_caret();
2831 return;
2832 case 43:
2833 case 45:
2834 this.readToken_plus_min(code);
2835 return;
2836 case 60:
2837 this.readToken_lt();
2838 return;
2839 case 62:
2840 this.readToken_gt();
2841 return;
2842 case 61:
2843 case 33:
2844 this.readToken_eq_excl(code);
2845 return;
2846 case 126:
2847 this.finishOp(36, 1);
2848 return;
2849 case 64:
2850 this.readToken_atSign();
2851 return;
2852 case 35:
2853 this.readToken_numberSign();
2854 return;
2855 case 92:
2856 this.readWord();
2857 return;
2858 default:
2859 if (isIdentifierStart(code)) {
2860 this.readWord(code);
2861 return;
2862 }
2863 }
2864 throw this.raise(Errors.InvalidOrUnexpectedToken, {
2865 at: this.state.curPosition(),
2866 unexpected: String.fromCodePoint(code)
2867 });
2868 }
2869 finishOp(type, size) {
2870 const str = this.input.slice(this.state.pos, this.state.pos + size);
2871 this.state.pos += size;
2872 this.finishToken(type, str);
2873 }
2874 readRegexp() {
2875 const startLoc = this.state.startLoc;
2876 const start = this.state.start + 1;
2877 let escaped, inClass;
2878 let {
2879 pos
2880 } = this.state;
2881 for (;; ++pos) {
2882 if (pos >= this.length) {
2883 throw this.raise(Errors.UnterminatedRegExp, {
2884 at: createPositionWithColumnOffset(startLoc, 1)
2885 });
2886 }
2887 const ch = this.input.charCodeAt(pos);
2888 if (isNewLine(ch)) {
2889 throw this.raise(Errors.UnterminatedRegExp, {
2890 at: createPositionWithColumnOffset(startLoc, 1)
2891 });
2892 }
2893 if (escaped) {
2894 escaped = false;
2895 } else {
2896 if (ch === 91) {
2897 inClass = true;
2898 } else if (ch === 93 && inClass) {
2899 inClass = false;
2900 } else if (ch === 47 && !inClass) {
2901 break;
2902 }
2903 escaped = ch === 92;
2904 }
2905 }
2906 const content = this.input.slice(start, pos);
2907 ++pos;
2908 let mods = "";
2909 const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
2910 while (pos < this.length) {
2911 const cp = this.codePointAtPos(pos);
2912 const char = String.fromCharCode(cp);
2913 if (VALID_REGEX_FLAGS.has(cp)) {
2914 if (cp === 118) {
2915 if (mods.includes("u")) {
2916 this.raise(Errors.IncompatibleRegExpUVFlags, {
2917 at: nextPos()
2918 });
2919 }
2920 } else if (cp === 117) {
2921 if (mods.includes("v")) {
2922 this.raise(Errors.IncompatibleRegExpUVFlags, {
2923 at: nextPos()
2924 });
2925 }
2926 }
2927 if (mods.includes(char)) {
2928 this.raise(Errors.DuplicateRegExpFlags, {
2929 at: nextPos()
2930 });
2931 }
2932 } else if (isIdentifierChar(cp) || cp === 92) {
2933 this.raise(Errors.MalformedRegExpFlags, {
2934 at: nextPos()
2935 });
2936 } else {
2937 break;
2938 }
2939 ++pos;
2940 mods += char;
2941 }
2942 this.state.pos = pos;
2943 this.finishToken(135, {
2944 pattern: content,
2945 flags: mods
2946 });
2947 }
2948 readInt(radix, len, forceLen = false, allowNumSeparator = true) {
2949 const {
2950 n,
2951 pos
2952 } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
2953 this.state.pos = pos;
2954 return n;
2955 }
2956 readRadixNumber(radix) {
2957 const startLoc = this.state.curPosition();
2958 let isBigInt = false;
2959 this.state.pos += 2;
2960 const val = this.readInt(radix);
2961 if (val == null) {
2962 this.raise(Errors.InvalidDigit, {
2963 at: createPositionWithColumnOffset(startLoc, 2),
2964 radix
2965 });
2966 }
2967 const next = this.input.charCodeAt(this.state.pos);
2968 if (next === 110) {
2969 ++this.state.pos;
2970 isBigInt = true;
2971 } else if (next === 109) {
2972 throw this.raise(Errors.InvalidDecimal, {
2973 at: startLoc
2974 });
2975 }
2976 if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
2977 throw this.raise(Errors.NumberIdentifier, {
2978 at: this.state.curPosition()
2979 });
2980 }
2981 if (isBigInt) {
2982 const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
2983 this.finishToken(133, str);
2984 return;
2985 }
2986 this.finishToken(132, val);
2987 }
2988 readNumber(startsWithDot) {
2989 const start = this.state.pos;
2990 const startLoc = this.state.curPosition();
2991 let isFloat = false;
2992 let isBigInt = false;
2993 let isDecimal = false;
2994 let hasExponent = false;
2995 let isOctal = false;
2996 if (!startsWithDot && this.readInt(10) === null) {
2997 this.raise(Errors.InvalidNumber, {
2998 at: this.state.curPosition()
2999 });
3000 }
3001 const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
3002 if (hasLeadingZero) {
3003 const integer = this.input.slice(start, this.state.pos);
3004 this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
3005 at: startLoc
3006 });
3007 if (!this.state.strict) {
3008 const underscorePos = integer.indexOf("_");
3009 if (underscorePos > 0) {
3010 this.raise(Errors.ZeroDigitNumericSeparator, {
3011 at: createPositionWithColumnOffset(startLoc, underscorePos)
3012 });
3013 }
3014 }
3015 isOctal = hasLeadingZero && !/[89]/.test(integer);
3016 }
3017 let next = this.input.charCodeAt(this.state.pos);
3018 if (next === 46 && !isOctal) {
3019 ++this.state.pos;
3020 this.readInt(10);
3021 isFloat = true;
3022 next = this.input.charCodeAt(this.state.pos);
3023 }
3024 if ((next === 69 || next === 101) && !isOctal) {
3025 next = this.input.charCodeAt(++this.state.pos);
3026 if (next === 43 || next === 45) {
3027 ++this.state.pos;
3028 }
3029 if (this.readInt(10) === null) {
3030 this.raise(Errors.InvalidOrMissingExponent, {
3031 at: startLoc
3032 });
3033 }
3034 isFloat = true;
3035 hasExponent = true;
3036 next = this.input.charCodeAt(this.state.pos);
3037 }
3038 if (next === 110) {
3039 if (isFloat || hasLeadingZero) {
3040 this.raise(Errors.InvalidBigIntLiteral, {
3041 at: startLoc
3042 });
3043 }
3044 ++this.state.pos;
3045 isBigInt = true;
3046 }
3047 if (next === 109) {
3048 this.expectPlugin("decimal", this.state.curPosition());
3049 if (hasExponent || hasLeadingZero) {
3050 this.raise(Errors.InvalidDecimal, {
3051 at: startLoc
3052 });
3053 }
3054 ++this.state.pos;
3055 isDecimal = true;
3056 }
3057 if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
3058 throw this.raise(Errors.NumberIdentifier, {
3059 at: this.state.curPosition()
3060 });
3061 }
3062 const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
3063 if (isBigInt) {
3064 this.finishToken(133, str);
3065 return;
3066 }
3067 if (isDecimal) {
3068 this.finishToken(134, str);
3069 return;
3070 }
3071 const val = isOctal ? parseInt(str, 8) : parseFloat(str);
3072 this.finishToken(132, val);
3073 }
3074 readCodePoint(throwOnInvalid) {
3075 const {
3076 code,
3077 pos
3078 } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
3079 this.state.pos = pos;
3080 return code;
3081 }
3082 readString(quote) {
3083 const {
3084 str,
3085 pos,
3086 curLine,
3087 lineStart
3088 } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
3089 this.state.pos = pos + 1;
3090 this.state.lineStart = lineStart;
3091 this.state.curLine = curLine;
3092 this.finishToken(131, str);
3093 }
3094 readTemplateContinuation() {
3095 if (!this.match(8)) {
3096 this.unexpected(null, 8);
3097 }
3098 this.state.pos--;
3099 this.readTemplateToken();
3100 }
3101 readTemplateToken() {
3102 const opening = this.input[this.state.pos];
3103 const {
3104 str,
3105 firstInvalidLoc,
3106 pos,
3107 curLine,
3108 lineStart
3109 } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
3110 this.state.pos = pos + 1;
3111 this.state.lineStart = lineStart;
3112 this.state.curLine = curLine;
3113 if (firstInvalidLoc) {
3114 this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
3115 }
3116 if (this.input.codePointAt(pos) === 96) {
3117 this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
3118 } else {
3119 this.state.pos++;
3120 this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
3121 }
3122 }
3123 recordStrictModeErrors(toParseError, {
3124 at
3125 }) {
3126 const index = at.index;
3127 if (this.state.strict && !this.state.strictErrors.has(index)) {
3128 this.raise(toParseError, {
3129 at
3130 });
3131 } else {
3132 this.state.strictErrors.set(index, [toParseError, at]);
3133 }
3134 }
3135 readWord1(firstCode) {
3136 this.state.containsEsc = false;
3137 let word = "";
3138 const start = this.state.pos;
3139 let chunkStart = this.state.pos;
3140 if (firstCode !== undefined) {
3141 this.state.pos += firstCode <= 0xffff ? 1 : 2;
3142 }
3143 while (this.state.pos < this.length) {
3144 const ch = this.codePointAtPos(this.state.pos);
3145 if (isIdentifierChar(ch)) {
3146 this.state.pos += ch <= 0xffff ? 1 : 2;
3147 } else if (ch === 92) {
3148 this.state.containsEsc = true;
3149 word += this.input.slice(chunkStart, this.state.pos);
3150 const escStart = this.state.curPosition();
3151 const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
3152 if (this.input.charCodeAt(++this.state.pos) !== 117) {
3153 this.raise(Errors.MissingUnicodeEscape, {
3154 at: this.state.curPosition()
3155 });
3156 chunkStart = this.state.pos - 1;
3157 continue;
3158 }
3159 ++this.state.pos;
3160 const esc = this.readCodePoint(true);
3161 if (esc !== null) {
3162 if (!identifierCheck(esc)) {
3163 this.raise(Errors.EscapedCharNotAnIdentifier, {
3164 at: escStart
3165 });
3166 }
3167 word += String.fromCodePoint(esc);
3168 }
3169 chunkStart = this.state.pos;
3170 } else {
3171 break;
3172 }
3173 }
3174 return word + this.input.slice(chunkStart, this.state.pos);
3175 }
3176 readWord(firstCode) {
3177 const word = this.readWord1(firstCode);
3178 const type = keywords$1.get(word);
3179 if (type !== undefined) {
3180 this.finishToken(type, tokenLabelName(type));
3181 } else {
3182 this.finishToken(130, word);
3183 }
3184 }
3185 checkKeywordEscapes() {
3186 const {
3187 type
3188 } = this.state;
3189 if (tokenIsKeyword(type) && this.state.containsEsc) {
3190 this.raise(Errors.InvalidEscapedReservedWord, {
3191 at: this.state.startLoc,
3192 reservedWord: tokenLabelName(type)
3193 });
3194 }
3195 }
3196 raise(toParseError, raiseProperties) {
3197 const {
3198 at
3199 } = raiseProperties,
3200 details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
3201 const loc = at instanceof Position ? at : at.loc.start;
3202 const error = toParseError({
3203 loc,
3204 details
3205 });
3206 if (!this.options.errorRecovery) throw error;
3207 if (!this.isLookahead) this.state.errors.push(error);
3208 return error;
3209 }
3210 raiseOverwrite(toParseError, raiseProperties) {
3211 const {
3212 at
3213 } = raiseProperties,
3214 details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
3215 const loc = at instanceof Position ? at : at.loc.start;
3216 const pos = loc.index;
3217 const errors = this.state.errors;
3218 for (let i = errors.length - 1; i >= 0; i--) {
3219 const error = errors[i];
3220 if (error.loc.index === pos) {
3221 return errors[i] = toParseError({
3222 loc,
3223 details
3224 });
3225 }
3226 if (error.loc.index < pos) break;
3227 }
3228 return this.raise(toParseError, raiseProperties);
3229 }
3230 updateContext(prevType) {}
3231 unexpected(loc, type) {
3232 throw this.raise(Errors.UnexpectedToken, {
3233 expected: type ? tokenLabelName(type) : null,
3234 at: loc != null ? loc : this.state.startLoc
3235 });
3236 }
3237 expectPlugin(pluginName, loc) {
3238 if (this.hasPlugin(pluginName)) {
3239 return true;
3240 }
3241 throw this.raise(Errors.MissingPlugin, {
3242 at: loc != null ? loc : this.state.startLoc,
3243 missingPlugin: [pluginName]
3244 });
3245 }
3246 expectOnePlugin(pluginNames) {
3247 if (!pluginNames.some(name => this.hasPlugin(name))) {
3248 throw this.raise(Errors.MissingOneOfPlugins, {
3249 at: this.state.startLoc,
3250 missingPlugin: pluginNames
3251 });
3252 }
3253 }
3254 errorBuilder(error) {
3255 return (pos, lineStart, curLine) => {
3256 this.raise(error, {
3257 at: buildPosition(pos, lineStart, curLine)
3258 });
3259 };
3260 }
3261}
3262class ClassScope {
3263 constructor() {
3264 this.privateNames = new Set();
3265 this.loneAccessors = new Map();
3266 this.undefinedPrivateNames = new Map();
3267 }
3268}
3269class ClassScopeHandler {
3270 constructor(parser) {
3271 this.parser = void 0;
3272 this.stack = [];
3273 this.undefinedPrivateNames = new Map();
3274 this.parser = parser;
3275 }
3276 current() {
3277 return this.stack[this.stack.length - 1];
3278 }
3279 enter() {
3280 this.stack.push(new ClassScope());
3281 }
3282 exit() {
3283 const oldClassScope = this.stack.pop();
3284 const current = this.current();
3285 for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
3286 if (current) {
3287 if (!current.undefinedPrivateNames.has(name)) {
3288 current.undefinedPrivateNames.set(name, loc);
3289 }
3290 } else {
3291 this.parser.raise(Errors.InvalidPrivateFieldResolution, {
3292 at: loc,
3293 identifierName: name
3294 });
3295 }
3296 }
3297 }
3298 declarePrivateName(name, elementType, loc) {
3299 const {
3300 privateNames,
3301 loneAccessors,
3302 undefinedPrivateNames
3303 } = this.current();
3304 let redefined = privateNames.has(name);
3305 if (elementType & 3) {
3306 const accessor = redefined && loneAccessors.get(name);
3307 if (accessor) {
3308 const oldStatic = accessor & 4;
3309 const newStatic = elementType & 4;
3310 const oldKind = accessor & 3;
3311 const newKind = elementType & 3;
3312 redefined = oldKind === newKind || oldStatic !== newStatic;
3313 if (!redefined) loneAccessors.delete(name);
3314 } else if (!redefined) {
3315 loneAccessors.set(name, elementType);
3316 }
3317 }
3318 if (redefined) {
3319 this.parser.raise(Errors.PrivateNameRedeclaration, {
3320 at: loc,
3321 identifierName: name
3322 });
3323 }
3324 privateNames.add(name);
3325 undefinedPrivateNames.delete(name);
3326 }
3327 usePrivateName(name, loc) {
3328 let classScope;
3329 for (classScope of this.stack) {
3330 if (classScope.privateNames.has(name)) return;
3331 }
3332 if (classScope) {
3333 classScope.undefinedPrivateNames.set(name, loc);
3334 } else {
3335 this.parser.raise(Errors.InvalidPrivateFieldResolution, {
3336 at: loc,
3337 identifierName: name
3338 });
3339 }
3340 }
3341}
3342class ExpressionScope {
3343 constructor(type = 0) {
3344 this.type = type;
3345 }
3346 canBeArrowParameterDeclaration() {
3347 return this.type === 2 || this.type === 1;
3348 }
3349 isCertainlyParameterDeclaration() {
3350 return this.type === 3;
3351 }
3352}
3353class ArrowHeadParsingScope extends ExpressionScope {
3354 constructor(type) {
3355 super(type);
3356 this.declarationErrors = new Map();
3357 }
3358 recordDeclarationError(ParsingErrorClass, {
3359 at
3360 }) {
3361 const index = at.index;
3362 this.declarationErrors.set(index, [ParsingErrorClass, at]);
3363 }
3364 clearDeclarationError(index) {
3365 this.declarationErrors.delete(index);
3366 }
3367 iterateErrors(iterator) {
3368 this.declarationErrors.forEach(iterator);
3369 }
3370}
3371class ExpressionScopeHandler {
3372 constructor(parser) {
3373 this.parser = void 0;
3374 this.stack = [new ExpressionScope()];
3375 this.parser = parser;
3376 }
3377 enter(scope) {
3378 this.stack.push(scope);
3379 }
3380 exit() {
3381 this.stack.pop();
3382 }
3383 recordParameterInitializerError(toParseError, {
3384 at: node
3385 }) {
3386 const origin = {
3387 at: node.loc.start
3388 };
3389 const {
3390 stack
3391 } = this;
3392 let i = stack.length - 1;
3393 let scope = stack[i];
3394 while (!scope.isCertainlyParameterDeclaration()) {
3395 if (scope.canBeArrowParameterDeclaration()) {
3396 scope.recordDeclarationError(toParseError, origin);
3397 } else {
3398 return;
3399 }
3400 scope = stack[--i];
3401 }
3402 this.parser.raise(toParseError, origin);
3403 }
3404 recordArrowParameterBindingError(error, {
3405 at: node
3406 }) {
3407 const {
3408 stack
3409 } = this;
3410 const scope = stack[stack.length - 1];
3411 const origin = {
3412 at: node.loc.start
3413 };
3414 if (scope.isCertainlyParameterDeclaration()) {
3415 this.parser.raise(error, origin);
3416 } else if (scope.canBeArrowParameterDeclaration()) {
3417 scope.recordDeclarationError(error, origin);
3418 } else {
3419 return;
3420 }
3421 }
3422 recordAsyncArrowParametersError({
3423 at
3424 }) {
3425 const {
3426 stack
3427 } = this;
3428 let i = stack.length - 1;
3429 let scope = stack[i];
3430 while (scope.canBeArrowParameterDeclaration()) {
3431 if (scope.type === 2) {
3432 scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
3433 at
3434 });
3435 }
3436 scope = stack[--i];
3437 }
3438 }
3439 validateAsPattern() {
3440 const {
3441 stack
3442 } = this;
3443 const currentScope = stack[stack.length - 1];
3444 if (!currentScope.canBeArrowParameterDeclaration()) return;
3445 currentScope.iterateErrors(([toParseError, loc]) => {
3446 this.parser.raise(toParseError, {
3447 at: loc
3448 });
3449 let i = stack.length - 2;
3450 let scope = stack[i];
3451 while (scope.canBeArrowParameterDeclaration()) {
3452 scope.clearDeclarationError(loc.index);
3453 scope = stack[--i];
3454 }
3455 });
3456 }
3457}
3458function newParameterDeclarationScope() {
3459 return new ExpressionScope(3);
3460}
3461function newArrowHeadScope() {
3462 return new ArrowHeadParsingScope(1);
3463}
3464function newAsyncArrowScope() {
3465 return new ArrowHeadParsingScope(2);
3466}
3467function newExpressionScope() {
3468 return new ExpressionScope();
3469}
3470const PARAM = 0b0000,
3471 PARAM_YIELD = 0b0001,
3472 PARAM_AWAIT = 0b0010,
3473 PARAM_RETURN = 0b0100,
3474 PARAM_IN = 0b1000;
3475class ProductionParameterHandler {
3476 constructor() {
3477 this.stacks = [];
3478 }
3479 enter(flags) {
3480 this.stacks.push(flags);
3481 }
3482 exit() {
3483 this.stacks.pop();
3484 }
3485 currentFlags() {
3486 return this.stacks[this.stacks.length - 1];
3487 }
3488 get hasAwait() {
3489 return (this.currentFlags() & PARAM_AWAIT) > 0;
3490 }
3491 get hasYield() {
3492 return (this.currentFlags() & PARAM_YIELD) > 0;
3493 }
3494 get hasReturn() {
3495 return (this.currentFlags() & PARAM_RETURN) > 0;
3496 }
3497 get hasIn() {
3498 return (this.currentFlags() & PARAM_IN) > 0;
3499 }
3500}
3501function functionFlags(isAsync, isGenerator) {
3502 return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
3503}
3504class UtilParser extends Tokenizer {
3505 addExtra(node, key, value, enumerable = true) {
3506 if (!node) return;
3507 const extra = node.extra = node.extra || {};
3508 if (enumerable) {
3509 extra[key] = value;
3510 } else {
3511 Object.defineProperty(extra, key, {
3512 enumerable,
3513 value
3514 });
3515 }
3516 }
3517 isContextual(token) {
3518 return this.state.type === token && !this.state.containsEsc;
3519 }
3520 isUnparsedContextual(nameStart, name) {
3521 const nameEnd = nameStart + name.length;
3522 if (this.input.slice(nameStart, nameEnd) === name) {
3523 const nextCh = this.input.charCodeAt(nameEnd);
3524 return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
3525 }
3526 return false;
3527 }
3528 isLookaheadContextual(name) {
3529 const next = this.nextTokenStart();
3530 return this.isUnparsedContextual(next, name);
3531 }
3532 eatContextual(token) {
3533 if (this.isContextual(token)) {
3534 this.next();
3535 return true;
3536 }
3537 return false;
3538 }
3539 expectContextual(token, toParseError) {
3540 if (!this.eatContextual(token)) {
3541 if (toParseError != null) {
3542 throw this.raise(toParseError, {
3543 at: this.state.startLoc
3544 });
3545 }
3546 this.unexpected(null, token);
3547 }
3548 }
3549 canInsertSemicolon() {
3550 return this.match(137) || this.match(8) || this.hasPrecedingLineBreak();
3551 }
3552 hasPrecedingLineBreak() {
3553 return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
3554 }
3555 hasFollowingLineBreak() {
3556 skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
3557 return skipWhiteSpaceToLineBreak.test(this.input);
3558 }
3559 isLineTerminator() {
3560 return this.eat(13) || this.canInsertSemicolon();
3561 }
3562 semicolon(allowAsi = true) {
3563 if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
3564 this.raise(Errors.MissingSemicolon, {
3565 at: this.state.lastTokEndLoc
3566 });
3567 }
3568 expect(type, loc) {
3569 this.eat(type) || this.unexpected(loc, type);
3570 }
3571 tryParse(fn, oldState = this.state.clone()) {
3572 const abortSignal = {
3573 node: null
3574 };
3575 try {
3576 const node = fn((node = null) => {
3577 abortSignal.node = node;
3578 throw abortSignal;
3579 });
3580 if (this.state.errors.length > oldState.errors.length) {
3581 const failState = this.state;
3582 this.state = oldState;
3583 this.state.tokensLength = failState.tokensLength;
3584 return {
3585 node,
3586 error: failState.errors[oldState.errors.length],
3587 thrown: false,
3588 aborted: false,
3589 failState
3590 };
3591 }
3592 return {
3593 node,
3594 error: null,
3595 thrown: false,
3596 aborted: false,
3597 failState: null
3598 };
3599 } catch (error) {
3600 const failState = this.state;
3601 this.state = oldState;
3602 if (error instanceof SyntaxError) {
3603 return {
3604 node: null,
3605 error,
3606 thrown: true,
3607 aborted: false,
3608 failState
3609 };
3610 }
3611 if (error === abortSignal) {
3612 return {
3613 node: abortSignal.node,
3614 error: null,
3615 thrown: false,
3616 aborted: true,
3617 failState
3618 };
3619 }
3620 throw error;
3621 }
3622 }
3623 checkExpressionErrors(refExpressionErrors, andThrow) {
3624 if (!refExpressionErrors) return false;
3625 const {
3626 shorthandAssignLoc,
3627 doubleProtoLoc,
3628 privateKeyLoc,
3629 optionalParametersLoc
3630 } = refExpressionErrors;
3631 const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
3632 if (!andThrow) {
3633 return hasErrors;
3634 }
3635 if (shorthandAssignLoc != null) {
3636 this.raise(Errors.InvalidCoverInitializedName, {
3637 at: shorthandAssignLoc
3638 });
3639 }
3640 if (doubleProtoLoc != null) {
3641 this.raise(Errors.DuplicateProto, {
3642 at: doubleProtoLoc
3643 });
3644 }
3645 if (privateKeyLoc != null) {
3646 this.raise(Errors.UnexpectedPrivateField, {
3647 at: privateKeyLoc
3648 });
3649 }
3650 if (optionalParametersLoc != null) {
3651 this.unexpected(optionalParametersLoc);
3652 }
3653 }
3654 isLiteralPropertyName() {
3655 return tokenIsLiteralPropertyName(this.state.type);
3656 }
3657 isPrivateName(node) {
3658 return node.type === "PrivateName";
3659 }
3660 getPrivateNameSV(node) {
3661 return node.id.name;
3662 }
3663 hasPropertyAsPrivateName(node) {
3664 return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
3665 }
3666 isObjectProperty(node) {
3667 return node.type === "ObjectProperty";
3668 }
3669 isObjectMethod(node) {
3670 return node.type === "ObjectMethod";
3671 }
3672 initializeScopes(inModule = this.options.sourceType === "module") {
3673 const oldLabels = this.state.labels;
3674 this.state.labels = [];
3675 const oldExportedIdentifiers = this.exportedIdentifiers;
3676 this.exportedIdentifiers = new Set();
3677 const oldInModule = this.inModule;
3678 this.inModule = inModule;
3679 const oldScope = this.scope;
3680 const ScopeHandler = this.getScopeHandler();
3681 this.scope = new ScopeHandler(this, inModule);
3682 const oldProdParam = this.prodParam;
3683 this.prodParam = new ProductionParameterHandler();
3684 const oldClassScope = this.classScope;
3685 this.classScope = new ClassScopeHandler(this);
3686 const oldExpressionScope = this.expressionScope;
3687 this.expressionScope = new ExpressionScopeHandler(this);
3688 return () => {
3689 this.state.labels = oldLabels;
3690 this.exportedIdentifiers = oldExportedIdentifiers;
3691 this.inModule = oldInModule;
3692 this.scope = oldScope;
3693 this.prodParam = oldProdParam;
3694 this.classScope = oldClassScope;
3695 this.expressionScope = oldExpressionScope;
3696 };
3697 }
3698 enterInitialScopes() {
3699 let paramFlags = PARAM;
3700 if (this.inModule) {
3701 paramFlags |= PARAM_AWAIT;
3702 }
3703 this.scope.enter(1);
3704 this.prodParam.enter(paramFlags);
3705 }
3706 checkDestructuringPrivate(refExpressionErrors) {
3707 const {
3708 privateKeyLoc
3709 } = refExpressionErrors;
3710 if (privateKeyLoc !== null) {
3711 this.expectPlugin("destructuringPrivate", privateKeyLoc);
3712 }
3713 }
3714}
3715class ExpressionErrors {
3716 constructor() {
3717 this.shorthandAssignLoc = null;
3718 this.doubleProtoLoc = null;
3719 this.privateKeyLoc = null;
3720 this.optionalParametersLoc = null;
3721 }
3722}
3723class Node {
3724 constructor(parser, pos, loc) {
3725 this.type = "";
3726 this.start = pos;
3727 this.end = 0;
3728 this.loc = new SourceLocation(loc);
3729 if (parser != null && parser.options.ranges) this.range = [pos, 0];
3730 if (parser != null && parser.filename) this.loc.filename = parser.filename;
3731 }
3732}
3733const NodePrototype = Node.prototype;
3734{
3735 NodePrototype.__clone = function () {
3736 const newNode = new Node(undefined, this.start, this.loc.start);
3737 const keys = Object.keys(this);
3738 for (let i = 0, length = keys.length; i < length; i++) {
3739 const key = keys[i];
3740 if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
3741 newNode[key] = this[key];
3742 }
3743 }
3744 return newNode;
3745 };
3746}
3747function clonePlaceholder(node) {
3748 return cloneIdentifier(node);
3749}
3750function cloneIdentifier(node) {
3751 const {
3752 type,
3753 start,
3754 end,
3755 loc,
3756 range,
3757 extra,
3758 name
3759 } = node;
3760 const cloned = Object.create(NodePrototype);
3761 cloned.type = type;
3762 cloned.start = start;
3763 cloned.end = end;
3764 cloned.loc = loc;
3765 cloned.range = range;
3766 cloned.extra = extra;
3767 cloned.name = name;
3768 if (type === "Placeholder") {
3769 cloned.expectedNode = node.expectedNode;
3770 }
3771 return cloned;
3772}
3773function cloneStringLiteral(node) {
3774 const {
3775 type,
3776 start,
3777 end,
3778 loc,
3779 range,
3780 extra
3781 } = node;
3782 if (type === "Placeholder") {
3783 return clonePlaceholder(node);
3784 }
3785 const cloned = Object.create(NodePrototype);
3786 cloned.type = type;
3787 cloned.start = start;
3788 cloned.end = end;
3789 cloned.loc = loc;
3790 cloned.range = range;
3791 if (node.raw !== undefined) {
3792 cloned.raw = node.raw;
3793 } else {
3794 cloned.extra = extra;
3795 }
3796 cloned.value = node.value;
3797 return cloned;
3798}
3799class NodeUtils extends UtilParser {
3800 startNode() {
3801 return new Node(this, this.state.start, this.state.startLoc);
3802 }
3803 startNodeAt(loc) {
3804 return new Node(this, loc.index, loc);
3805 }
3806 startNodeAtNode(type) {
3807 return this.startNodeAt(type.loc.start);
3808 }
3809 finishNode(node, type) {
3810 return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
3811 }
3812 finishNodeAt(node, type, endLoc) {
3813 node.type = type;
3814 node.end = endLoc.index;
3815 node.loc.end = endLoc;
3816 if (this.options.ranges) node.range[1] = endLoc.index;
3817 if (this.options.attachComment) this.processComment(node);
3818 return node;
3819 }
3820 resetStartLocation(node, startLoc) {
3821 node.start = startLoc.index;
3822 node.loc.start = startLoc;
3823 if (this.options.ranges) node.range[0] = startLoc.index;
3824 }
3825 resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
3826 node.end = endLoc.index;
3827 node.loc.end = endLoc;
3828 if (this.options.ranges) node.range[1] = endLoc.index;
3829 }
3830 resetStartLocationFromNode(node, locationNode) {
3831 this.resetStartLocation(node, locationNode.loc.start);
3832 }
3833}
3834const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
3835const FlowErrors = ParseErrorEnum`flow`({
3836 AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
3837 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.",
3838 AssignReservedType: ({
3839 reservedType
3840 }) => `Cannot overwrite reserved type ${reservedType}.`,
3841 DeclareClassElement: "The `declare` modifier can only appear on class fields.",
3842 DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
3843 DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
3844 EnumBooleanMemberNotInitialized: ({
3845 memberName,
3846 enumName
3847 }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
3848 EnumDuplicateMemberName: ({
3849 memberName,
3850 enumName
3851 }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
3852 EnumInconsistentMemberValues: ({
3853 enumName
3854 }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
3855 EnumInvalidExplicitType: ({
3856 invalidEnumType,
3857 enumName
3858 }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
3859 EnumInvalidExplicitTypeUnknownSupplied: ({
3860 enumName
3861 }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
3862 EnumInvalidMemberInitializerPrimaryType: ({
3863 enumName,
3864 memberName,
3865 explicitType
3866 }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
3867 EnumInvalidMemberInitializerSymbolType: ({
3868 enumName,
3869 memberName
3870 }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
3871 EnumInvalidMemberInitializerUnknownType: ({
3872 enumName,
3873 memberName
3874 }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
3875 EnumInvalidMemberName: ({
3876 enumName,
3877 memberName,
3878 suggestion
3879 }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
3880 EnumNumberMemberNotInitialized: ({
3881 enumName,
3882 memberName
3883 }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
3884 EnumStringMemberInconsistentlyInitialized: ({
3885 enumName
3886 }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
3887 GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
3888 ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
3889 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.",
3890 InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
3891 InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
3892 InexactVariance: "Explicit inexact syntax cannot have variance.",
3893 InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
3894 MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
3895 NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
3896 NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
3897 PatternIsOptional: Object.assign({
3898 message: "A binding pattern parameter cannot be optional in an implementation signature."
3899 }, {
3900 reasonCode: "OptionalBindingPattern"
3901 }),
3902 SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
3903 SpreadVariance: "Spread properties cannot have variance.",
3904 ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
3905 ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
3906 ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
3907 ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
3908 ThisParamNoDefault: "The `this` parameter may not have a default value.",
3909 TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
3910 TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
3911 UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
3912 UnexpectedReservedType: ({
3913 reservedType
3914 }) => `Unexpected reserved type ${reservedType}.`,
3915 UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
3916 UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
3917 UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
3918 UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
3919 UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
3920 UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
3921 UnsupportedDeclareExportKind: ({
3922 unsupportedExportKind,
3923 suggestion
3924 }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
3925 UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
3926 UnterminatedFlowComment: "Unterminated flow-comment."
3927});
3928function isEsModuleType(bodyElement) {
3929 return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
3930}
3931function hasTypeImportKind(node) {
3932 return node.importKind === "type" || node.importKind === "typeof";
3933}
3934const exportSuggestions = {
3935 const: "declare export var",
3936 let: "declare export var",
3937 type: "export type",
3938 interface: "export interface"
3939};
3940function partition(list, test) {
3941 const list1 = [];
3942 const list2 = [];
3943 for (let i = 0; i < list.length; i++) {
3944 (test(list[i], i, list) ? list1 : list2).push(list[i]);
3945 }
3946 return [list1, list2];
3947}
3948const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
3949var flow = superClass => class FlowParserMixin extends superClass {
3950 constructor(...args) {
3951 super(...args);
3952 this.flowPragma = undefined;
3953 }
3954 getScopeHandler() {
3955 return FlowScopeHandler;
3956 }
3957 shouldParseTypes() {
3958 return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
3959 }
3960 shouldParseEnums() {
3961 return !!this.getPluginOption("flow", "enums");
3962 }
3963 finishToken(type, val) {
3964 if (type !== 131 && type !== 13 && type !== 28) {
3965 if (this.flowPragma === undefined) {
3966 this.flowPragma = null;
3967 }
3968 }
3969 super.finishToken(type, val);
3970 }
3971 addComment(comment) {
3972 if (this.flowPragma === undefined) {
3973 const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
3974 if (!matches) ;else if (matches[1] === "flow") {
3975 this.flowPragma = "flow";
3976 } else if (matches[1] === "noflow") {
3977 this.flowPragma = "noflow";
3978 } else {
3979 throw new Error("Unexpected flow pragma");
3980 }
3981 }
3982 super.addComment(comment);
3983 }
3984 flowParseTypeInitialiser(tok) {
3985 const oldInType = this.state.inType;
3986 this.state.inType = true;
3987 this.expect(tok || 14);
3988 const type = this.flowParseType();
3989 this.state.inType = oldInType;
3990 return type;
3991 }
3992 flowParsePredicate() {
3993 const node = this.startNode();
3994 const moduloLoc = this.state.startLoc;
3995 this.next();
3996 this.expectContextual(108);
3997 if (this.state.lastTokStart > moduloLoc.index + 1) {
3998 this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
3999 at: moduloLoc
4000 });
4001 }
4002 if (this.eat(10)) {
4003 node.value = super.parseExpression();
4004 this.expect(11);
4005 return this.finishNode(node, "DeclaredPredicate");
4006 } else {
4007 return this.finishNode(node, "InferredPredicate");
4008 }
4009 }
4010 flowParseTypeAndPredicateInitialiser() {
4011 const oldInType = this.state.inType;
4012 this.state.inType = true;
4013 this.expect(14);
4014 let type = null;
4015 let predicate = null;
4016 if (this.match(54)) {
4017 this.state.inType = oldInType;
4018 predicate = this.flowParsePredicate();
4019 } else {
4020 type = this.flowParseType();
4021 this.state.inType = oldInType;
4022 if (this.match(54)) {
4023 predicate = this.flowParsePredicate();
4024 }
4025 }
4026 return [type, predicate];
4027 }
4028 flowParseDeclareClass(node) {
4029 this.next();
4030 this.flowParseInterfaceish(node, true);
4031 return this.finishNode(node, "DeclareClass");
4032 }
4033 flowParseDeclareFunction(node) {
4034 this.next();
4035 const id = node.id = this.parseIdentifier();
4036 const typeNode = this.startNode();
4037 const typeContainer = this.startNode();
4038 if (this.match(47)) {
4039 typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
4040 } else {
4041 typeNode.typeParameters = null;
4042 }
4043 this.expect(10);
4044 const tmp = this.flowParseFunctionTypeParams();
4045 typeNode.params = tmp.params;
4046 typeNode.rest = tmp.rest;
4047 typeNode.this = tmp._this;
4048 this.expect(11);
4049 [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
4050 typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
4051 id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
4052 this.resetEndLocation(id);
4053 this.semicolon();
4054 this.scope.declareName(node.id.name, 2048, node.id.loc.start);
4055 return this.finishNode(node, "DeclareFunction");
4056 }
4057 flowParseDeclare(node, insideModule) {
4058 if (this.match(80)) {
4059 return this.flowParseDeclareClass(node);
4060 } else if (this.match(68)) {
4061 return this.flowParseDeclareFunction(node);
4062 } else if (this.match(74)) {
4063 return this.flowParseDeclareVariable(node);
4064 } else if (this.eatContextual(125)) {
4065 if (this.match(16)) {
4066 return this.flowParseDeclareModuleExports(node);
4067 } else {
4068 if (insideModule) {
4069 this.raise(FlowErrors.NestedDeclareModule, {
4070 at: this.state.lastTokStartLoc
4071 });
4072 }
4073 return this.flowParseDeclareModule(node);
4074 }
4075 } else if (this.isContextual(128)) {
4076 return this.flowParseDeclareTypeAlias(node);
4077 } else if (this.isContextual(129)) {
4078 return this.flowParseDeclareOpaqueType(node);
4079 } else if (this.isContextual(127)) {
4080 return this.flowParseDeclareInterface(node);
4081 } else if (this.match(82)) {
4082 return this.flowParseDeclareExportDeclaration(node, insideModule);
4083 } else {
4084 this.unexpected();
4085 }
4086 }
4087 flowParseDeclareVariable(node) {
4088 this.next();
4089 node.id = this.flowParseTypeAnnotatableIdentifier(true);
4090 this.scope.declareName(node.id.name, 5, node.id.loc.start);
4091 this.semicolon();
4092 return this.finishNode(node, "DeclareVariable");
4093 }
4094 flowParseDeclareModule(node) {
4095 this.scope.enter(0);
4096 if (this.match(131)) {
4097 node.id = super.parseExprAtom();
4098 } else {
4099 node.id = this.parseIdentifier();
4100 }
4101 const bodyNode = node.body = this.startNode();
4102 const body = bodyNode.body = [];
4103 this.expect(5);
4104 while (!this.match(8)) {
4105 let bodyNode = this.startNode();
4106 if (this.match(83)) {
4107 this.next();
4108 if (!this.isContextual(128) && !this.match(87)) {
4109 this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
4110 at: this.state.lastTokStartLoc
4111 });
4112 }
4113 super.parseImport(bodyNode);
4114 } else {
4115 this.expectContextual(123, FlowErrors.UnsupportedStatementInDeclareModule);
4116 bodyNode = this.flowParseDeclare(bodyNode, true);
4117 }
4118 body.push(bodyNode);
4119 }
4120 this.scope.exit();
4121 this.expect(8);
4122 this.finishNode(bodyNode, "BlockStatement");
4123 let kind = null;
4124 let hasModuleExport = false;
4125 body.forEach(bodyElement => {
4126 if (isEsModuleType(bodyElement)) {
4127 if (kind === "CommonJS") {
4128 this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
4129 at: bodyElement
4130 });
4131 }
4132 kind = "ES";
4133 } else if (bodyElement.type === "DeclareModuleExports") {
4134 if (hasModuleExport) {
4135 this.raise(FlowErrors.DuplicateDeclareModuleExports, {
4136 at: bodyElement
4137 });
4138 }
4139 if (kind === "ES") {
4140 this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
4141 at: bodyElement
4142 });
4143 }
4144 kind = "CommonJS";
4145 hasModuleExport = true;
4146 }
4147 });
4148 node.kind = kind || "CommonJS";
4149 return this.finishNode(node, "DeclareModule");
4150 }
4151 flowParseDeclareExportDeclaration(node, insideModule) {
4152 this.expect(82);
4153 if (this.eat(65)) {
4154 if (this.match(68) || this.match(80)) {
4155 node.declaration = this.flowParseDeclare(this.startNode());
4156 } else {
4157 node.declaration = this.flowParseType();
4158 this.semicolon();
4159 }
4160 node.default = true;
4161 return this.finishNode(node, "DeclareExportDeclaration");
4162 } else {
4163 if (this.match(75) || this.isLet() || (this.isContextual(128) || this.isContextual(127)) && !insideModule) {
4164 const label = this.state.value;
4165 throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
4166 at: this.state.startLoc,
4167 unsupportedExportKind: label,
4168 suggestion: exportSuggestions[label]
4169 });
4170 }
4171 if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(129)) {
4172 node.declaration = this.flowParseDeclare(this.startNode());
4173 node.default = false;
4174 return this.finishNode(node, "DeclareExportDeclaration");
4175 } else if (this.match(55) || this.match(5) || this.isContextual(127) || this.isContextual(128) || this.isContextual(129)) {
4176 node = this.parseExport(node, null);
4177 if (node.type === "ExportNamedDeclaration") {
4178 node.type = "ExportDeclaration";
4179 node.default = false;
4180 delete node.exportKind;
4181 }
4182 node.type = "Declare" + node.type;
4183 return node;
4184 }
4185 }
4186 this.unexpected();
4187 }
4188 flowParseDeclareModuleExports(node) {
4189 this.next();
4190 this.expectContextual(109);
4191 node.typeAnnotation = this.flowParseTypeAnnotation();
4192 this.semicolon();
4193 return this.finishNode(node, "DeclareModuleExports");
4194 }
4195 flowParseDeclareTypeAlias(node) {
4196 this.next();
4197 const finished = this.flowParseTypeAlias(node);
4198 finished.type = "DeclareTypeAlias";
4199 return finished;
4200 }
4201 flowParseDeclareOpaqueType(node) {
4202 this.next();
4203 const finished = this.flowParseOpaqueType(node, true);
4204 finished.type = "DeclareOpaqueType";
4205 return finished;
4206 }
4207 flowParseDeclareInterface(node) {
4208 this.next();
4209 this.flowParseInterfaceish(node, false);
4210 return this.finishNode(node, "DeclareInterface");
4211 }
4212 flowParseInterfaceish(node, isClass) {
4213 node.id = this.flowParseRestrictedIdentifier(!isClass, true);
4214 this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
4215 if (this.match(47)) {
4216 node.typeParameters = this.flowParseTypeParameterDeclaration();
4217 } else {
4218 node.typeParameters = null;
4219 }
4220 node.extends = [];
4221 if (this.eat(81)) {
4222 do {
4223 node.extends.push(this.flowParseInterfaceExtends());
4224 } while (!isClass && this.eat(12));
4225 }
4226 if (isClass) {
4227 node.implements = [];
4228 node.mixins = [];
4229 if (this.eatContextual(115)) {
4230 do {
4231 node.mixins.push(this.flowParseInterfaceExtends());
4232 } while (this.eat(12));
4233 }
4234 if (this.eatContextual(111)) {
4235 do {
4236 node.implements.push(this.flowParseInterfaceExtends());
4237 } while (this.eat(12));
4238 }
4239 }
4240 node.body = this.flowParseObjectType({
4241 allowStatic: isClass,
4242 allowExact: false,
4243 allowSpread: false,
4244 allowProto: isClass,
4245 allowInexact: false
4246 });
4247 }
4248 flowParseInterfaceExtends() {
4249 const node = this.startNode();
4250 node.id = this.flowParseQualifiedTypeIdentifier();
4251 if (this.match(47)) {
4252 node.typeParameters = this.flowParseTypeParameterInstantiation();
4253 } else {
4254 node.typeParameters = null;
4255 }
4256 return this.finishNode(node, "InterfaceExtends");
4257 }
4258 flowParseInterface(node) {
4259 this.flowParseInterfaceish(node, false);
4260 return this.finishNode(node, "InterfaceDeclaration");
4261 }
4262 checkNotUnderscore(word) {
4263 if (word === "_") {
4264 this.raise(FlowErrors.UnexpectedReservedUnderscore, {
4265 at: this.state.startLoc
4266 });
4267 }
4268 }
4269 checkReservedType(word, startLoc, declaration) {
4270 if (!reservedTypes.has(word)) return;
4271 this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
4272 at: startLoc,
4273 reservedType: word
4274 });
4275 }
4276 flowParseRestrictedIdentifier(liberal, declaration) {
4277 this.checkReservedType(this.state.value, this.state.startLoc, declaration);
4278 return this.parseIdentifier(liberal);
4279 }
4280 flowParseTypeAlias(node) {
4281 node.id = this.flowParseRestrictedIdentifier(false, true);
4282 this.scope.declareName(node.id.name, 8201, node.id.loc.start);
4283 if (this.match(47)) {
4284 node.typeParameters = this.flowParseTypeParameterDeclaration();
4285 } else {
4286 node.typeParameters = null;
4287 }
4288 node.right = this.flowParseTypeInitialiser(29);
4289 this.semicolon();
4290 return this.finishNode(node, "TypeAlias");
4291 }
4292 flowParseOpaqueType(node, declare) {
4293 this.expectContextual(128);
4294 node.id = this.flowParseRestrictedIdentifier(true, true);
4295 this.scope.declareName(node.id.name, 8201, node.id.loc.start);
4296 if (this.match(47)) {
4297 node.typeParameters = this.flowParseTypeParameterDeclaration();
4298 } else {
4299 node.typeParameters = null;
4300 }
4301 node.supertype = null;
4302 if (this.match(14)) {
4303 node.supertype = this.flowParseTypeInitialiser(14);
4304 }
4305 node.impltype = null;
4306 if (!declare) {
4307 node.impltype = this.flowParseTypeInitialiser(29);
4308 }
4309 this.semicolon();
4310 return this.finishNode(node, "OpaqueType");
4311 }
4312 flowParseTypeParameter(requireDefault = false) {
4313 const nodeStartLoc = this.state.startLoc;
4314 const node = this.startNode();
4315 const variance = this.flowParseVariance();
4316 const ident = this.flowParseTypeAnnotatableIdentifier();
4317 node.name = ident.name;
4318 node.variance = variance;
4319 node.bound = ident.typeAnnotation;
4320 if (this.match(29)) {
4321 this.eat(29);
4322 node.default = this.flowParseType();
4323 } else {
4324 if (requireDefault) {
4325 this.raise(FlowErrors.MissingTypeParamDefault, {
4326 at: nodeStartLoc
4327 });
4328 }
4329 }
4330 return this.finishNode(node, "TypeParameter");
4331 }
4332 flowParseTypeParameterDeclaration() {
4333 const oldInType = this.state.inType;
4334 const node = this.startNode();
4335 node.params = [];
4336 this.state.inType = true;
4337 if (this.match(47) || this.match(140)) {
4338 this.next();
4339 } else {
4340 this.unexpected();
4341 }
4342 let defaultRequired = false;
4343 do {
4344 const typeParameter = this.flowParseTypeParameter(defaultRequired);
4345 node.params.push(typeParameter);
4346 if (typeParameter.default) {
4347 defaultRequired = true;
4348 }
4349 if (!this.match(48)) {
4350 this.expect(12);
4351 }
4352 } while (!this.match(48));
4353 this.expect(48);
4354 this.state.inType = oldInType;
4355 return this.finishNode(node, "TypeParameterDeclaration");
4356 }
4357 flowParseTypeParameterInstantiation() {
4358 const node = this.startNode();
4359 const oldInType = this.state.inType;
4360 node.params = [];
4361 this.state.inType = true;
4362 this.expect(47);
4363 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
4364 this.state.noAnonFunctionType = false;
4365 while (!this.match(48)) {
4366 node.params.push(this.flowParseType());
4367 if (!this.match(48)) {
4368 this.expect(12);
4369 }
4370 }
4371 this.state.noAnonFunctionType = oldNoAnonFunctionType;
4372 this.expect(48);
4373 this.state.inType = oldInType;
4374 return this.finishNode(node, "TypeParameterInstantiation");
4375 }
4376 flowParseTypeParameterInstantiationCallOrNew() {
4377 const node = this.startNode();
4378 const oldInType = this.state.inType;
4379 node.params = [];
4380 this.state.inType = true;
4381 this.expect(47);
4382 while (!this.match(48)) {
4383 node.params.push(this.flowParseTypeOrImplicitInstantiation());
4384 if (!this.match(48)) {
4385 this.expect(12);
4386 }
4387 }
4388 this.expect(48);
4389 this.state.inType = oldInType;
4390 return this.finishNode(node, "TypeParameterInstantiation");
4391 }
4392 flowParseInterfaceType() {
4393 const node = this.startNode();
4394 this.expectContextual(127);
4395 node.extends = [];
4396 if (this.eat(81)) {
4397 do {
4398 node.extends.push(this.flowParseInterfaceExtends());
4399 } while (this.eat(12));
4400 }
4401 node.body = this.flowParseObjectType({
4402 allowStatic: false,
4403 allowExact: false,
4404 allowSpread: false,
4405 allowProto: false,
4406 allowInexact: false
4407 });
4408 return this.finishNode(node, "InterfaceTypeAnnotation");
4409 }
4410 flowParseObjectPropertyKey() {
4411 return this.match(132) || this.match(131) ? super.parseExprAtom() : this.parseIdentifier(true);
4412 }
4413 flowParseObjectTypeIndexer(node, isStatic, variance) {
4414 node.static = isStatic;
4415 if (this.lookahead().type === 14) {
4416 node.id = this.flowParseObjectPropertyKey();
4417 node.key = this.flowParseTypeInitialiser();
4418 } else {
4419 node.id = null;
4420 node.key = this.flowParseType();
4421 }
4422 this.expect(3);
4423 node.value = this.flowParseTypeInitialiser();
4424 node.variance = variance;
4425 return this.finishNode(node, "ObjectTypeIndexer");
4426 }
4427 flowParseObjectTypeInternalSlot(node, isStatic) {
4428 node.static = isStatic;
4429 node.id = this.flowParseObjectPropertyKey();
4430 this.expect(3);
4431 this.expect(3);
4432 if (this.match(47) || this.match(10)) {
4433 node.method = true;
4434 node.optional = false;
4435 node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
4436 } else {
4437 node.method = false;
4438 if (this.eat(17)) {
4439 node.optional = true;
4440 }
4441 node.value = this.flowParseTypeInitialiser();
4442 }
4443 return this.finishNode(node, "ObjectTypeInternalSlot");
4444 }
4445 flowParseObjectTypeMethodish(node) {
4446 node.params = [];
4447 node.rest = null;
4448 node.typeParameters = null;
4449 node.this = null;
4450 if (this.match(47)) {
4451 node.typeParameters = this.flowParseTypeParameterDeclaration();
4452 }
4453 this.expect(10);
4454 if (this.match(78)) {
4455 node.this = this.flowParseFunctionTypeParam(true);
4456 node.this.name = null;
4457 if (!this.match(11)) {
4458 this.expect(12);
4459 }
4460 }
4461 while (!this.match(11) && !this.match(21)) {
4462 node.params.push(this.flowParseFunctionTypeParam(false));
4463 if (!this.match(11)) {
4464 this.expect(12);
4465 }
4466 }
4467 if (this.eat(21)) {
4468 node.rest = this.flowParseFunctionTypeParam(false);
4469 }
4470 this.expect(11);
4471 node.returnType = this.flowParseTypeInitialiser();
4472 return this.finishNode(node, "FunctionTypeAnnotation");
4473 }
4474 flowParseObjectTypeCallProperty(node, isStatic) {
4475 const valueNode = this.startNode();
4476 node.static = isStatic;
4477 node.value = this.flowParseObjectTypeMethodish(valueNode);
4478 return this.finishNode(node, "ObjectTypeCallProperty");
4479 }
4480 flowParseObjectType({
4481 allowStatic,
4482 allowExact,
4483 allowSpread,
4484 allowProto,
4485 allowInexact
4486 }) {
4487 const oldInType = this.state.inType;
4488 this.state.inType = true;
4489 const nodeStart = this.startNode();
4490 nodeStart.callProperties = [];
4491 nodeStart.properties = [];
4492 nodeStart.indexers = [];
4493 nodeStart.internalSlots = [];
4494 let endDelim;
4495 let exact;
4496 let inexact = false;
4497 if (allowExact && this.match(6)) {
4498 this.expect(6);
4499 endDelim = 9;
4500 exact = true;
4501 } else {
4502 this.expect(5);
4503 endDelim = 8;
4504 exact = false;
4505 }
4506 nodeStart.exact = exact;
4507 while (!this.match(endDelim)) {
4508 let isStatic = false;
4509 let protoStartLoc = null;
4510 let inexactStartLoc = null;
4511 const node = this.startNode();
4512 if (allowProto && this.isContextual(116)) {
4513 const lookahead = this.lookahead();
4514 if (lookahead.type !== 14 && lookahead.type !== 17) {
4515 this.next();
4516 protoStartLoc = this.state.startLoc;
4517 allowStatic = false;
4518 }
4519 }
4520 if (allowStatic && this.isContextual(104)) {
4521 const lookahead = this.lookahead();
4522 if (lookahead.type !== 14 && lookahead.type !== 17) {
4523 this.next();
4524 isStatic = true;
4525 }
4526 }
4527 const variance = this.flowParseVariance();
4528 if (this.eat(0)) {
4529 if (protoStartLoc != null) {
4530 this.unexpected(protoStartLoc);
4531 }
4532 if (this.eat(0)) {
4533 if (variance) {
4534 this.unexpected(variance.loc.start);
4535 }
4536 nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
4537 } else {
4538 nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
4539 }
4540 } else if (this.match(10) || this.match(47)) {
4541 if (protoStartLoc != null) {
4542 this.unexpected(protoStartLoc);
4543 }
4544 if (variance) {
4545 this.unexpected(variance.loc.start);
4546 }
4547 nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
4548 } else {
4549 let kind = "init";
4550 if (this.isContextual(98) || this.isContextual(103)) {
4551 const lookahead = this.lookahead();
4552 if (tokenIsLiteralPropertyName(lookahead.type)) {
4553 kind = this.state.value;
4554 this.next();
4555 }
4556 }
4557 const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
4558 if (propOrInexact === null) {
4559 inexact = true;
4560 inexactStartLoc = this.state.lastTokStartLoc;
4561 } else {
4562 nodeStart.properties.push(propOrInexact);
4563 }
4564 }
4565 this.flowObjectTypeSemicolon();
4566 if (inexactStartLoc && !this.match(8) && !this.match(9)) {
4567 this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
4568 at: inexactStartLoc
4569 });
4570 }
4571 }
4572 this.expect(endDelim);
4573 if (allowSpread) {
4574 nodeStart.inexact = inexact;
4575 }
4576 const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
4577 this.state.inType = oldInType;
4578 return out;
4579 }
4580 flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
4581 if (this.eat(21)) {
4582 const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
4583 if (isInexactToken) {
4584 if (!allowSpread) {
4585 this.raise(FlowErrors.InexactInsideNonObject, {
4586 at: this.state.lastTokStartLoc
4587 });
4588 } else if (!allowInexact) {
4589 this.raise(FlowErrors.InexactInsideExact, {
4590 at: this.state.lastTokStartLoc
4591 });
4592 }
4593 if (variance) {
4594 this.raise(FlowErrors.InexactVariance, {
4595 at: variance
4596 });
4597 }
4598 return null;
4599 }
4600 if (!allowSpread) {
4601 this.raise(FlowErrors.UnexpectedSpreadType, {
4602 at: this.state.lastTokStartLoc
4603 });
4604 }
4605 if (protoStartLoc != null) {
4606 this.unexpected(protoStartLoc);
4607 }
4608 if (variance) {
4609 this.raise(FlowErrors.SpreadVariance, {
4610 at: variance
4611 });
4612 }
4613 node.argument = this.flowParseType();
4614 return this.finishNode(node, "ObjectTypeSpreadProperty");
4615 } else {
4616 node.key = this.flowParseObjectPropertyKey();
4617 node.static = isStatic;
4618 node.proto = protoStartLoc != null;
4619 node.kind = kind;
4620 let optional = false;
4621 if (this.match(47) || this.match(10)) {
4622 node.method = true;
4623 if (protoStartLoc != null) {
4624 this.unexpected(protoStartLoc);
4625 }
4626 if (variance) {
4627 this.unexpected(variance.loc.start);
4628 }
4629 node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
4630 if (kind === "get" || kind === "set") {
4631 this.flowCheckGetterSetterParams(node);
4632 }
4633 if (!allowSpread && node.key.name === "constructor" && node.value.this) {
4634 this.raise(FlowErrors.ThisParamBannedInConstructor, {
4635 at: node.value.this
4636 });
4637 }
4638 } else {
4639 if (kind !== "init") this.unexpected();
4640 node.method = false;
4641 if (this.eat(17)) {
4642 optional = true;
4643 }
4644 node.value = this.flowParseTypeInitialiser();
4645 node.variance = variance;
4646 }
4647 node.optional = optional;
4648 return this.finishNode(node, "ObjectTypeProperty");
4649 }
4650 }
4651 flowCheckGetterSetterParams(property) {
4652 const paramCount = property.kind === "get" ? 0 : 1;
4653 const length = property.value.params.length + (property.value.rest ? 1 : 0);
4654 if (property.value.this) {
4655 this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
4656 at: property.value.this
4657 });
4658 }
4659 if (length !== paramCount) {
4660 this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
4661 at: property
4662 });
4663 }
4664 if (property.kind === "set" && property.value.rest) {
4665 this.raise(Errors.BadSetterRestParameter, {
4666 at: property
4667 });
4668 }
4669 }
4670 flowObjectTypeSemicolon() {
4671 if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
4672 this.unexpected();
4673 }
4674 }
4675 flowParseQualifiedTypeIdentifier(startLoc, id) {
4676 var _startLoc;
4677 (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
4678 let node = id || this.flowParseRestrictedIdentifier(true);
4679 while (this.eat(16)) {
4680 const node2 = this.startNodeAt(startLoc);
4681 node2.qualification = node;
4682 node2.id = this.flowParseRestrictedIdentifier(true);
4683 node = this.finishNode(node2, "QualifiedTypeIdentifier");
4684 }
4685 return node;
4686 }
4687 flowParseGenericType(startLoc, id) {
4688 const node = this.startNodeAt(startLoc);
4689 node.typeParameters = null;
4690 node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
4691 if (this.match(47)) {
4692 node.typeParameters = this.flowParseTypeParameterInstantiation();
4693 }
4694 return this.finishNode(node, "GenericTypeAnnotation");
4695 }
4696 flowParseTypeofType() {
4697 const node = this.startNode();
4698 this.expect(87);
4699 node.argument = this.flowParsePrimaryType();
4700 return this.finishNode(node, "TypeofTypeAnnotation");
4701 }
4702 flowParseTupleType() {
4703 const node = this.startNode();
4704 node.types = [];
4705 this.expect(0);
4706 while (this.state.pos < this.length && !this.match(3)) {
4707 node.types.push(this.flowParseType());
4708 if (this.match(3)) break;
4709 this.expect(12);
4710 }
4711 this.expect(3);
4712 return this.finishNode(node, "TupleTypeAnnotation");
4713 }
4714 flowParseFunctionTypeParam(first) {
4715 let name = null;
4716 let optional = false;
4717 let typeAnnotation = null;
4718 const node = this.startNode();
4719 const lh = this.lookahead();
4720 const isThis = this.state.type === 78;
4721 if (lh.type === 14 || lh.type === 17) {
4722 if (isThis && !first) {
4723 this.raise(FlowErrors.ThisParamMustBeFirst, {
4724 at: node
4725 });
4726 }
4727 name = this.parseIdentifier(isThis);
4728 if (this.eat(17)) {
4729 optional = true;
4730 if (isThis) {
4731 this.raise(FlowErrors.ThisParamMayNotBeOptional, {
4732 at: node
4733 });
4734 }
4735 }
4736 typeAnnotation = this.flowParseTypeInitialiser();
4737 } else {
4738 typeAnnotation = this.flowParseType();
4739 }
4740 node.name = name;
4741 node.optional = optional;
4742 node.typeAnnotation = typeAnnotation;
4743 return this.finishNode(node, "FunctionTypeParam");
4744 }
4745 reinterpretTypeAsFunctionTypeParam(type) {
4746 const node = this.startNodeAt(type.loc.start);
4747 node.name = null;
4748 node.optional = false;
4749 node.typeAnnotation = type;
4750 return this.finishNode(node, "FunctionTypeParam");
4751 }
4752 flowParseFunctionTypeParams(params = []) {
4753 let rest = null;
4754 let _this = null;
4755 if (this.match(78)) {
4756 _this = this.flowParseFunctionTypeParam(true);
4757 _this.name = null;
4758 if (!this.match(11)) {
4759 this.expect(12);
4760 }
4761 }
4762 while (!this.match(11) && !this.match(21)) {
4763 params.push(this.flowParseFunctionTypeParam(false));
4764 if (!this.match(11)) {
4765 this.expect(12);
4766 }
4767 }
4768 if (this.eat(21)) {
4769 rest = this.flowParseFunctionTypeParam(false);
4770 }
4771 return {
4772 params,
4773 rest,
4774 _this
4775 };
4776 }
4777 flowIdentToTypeAnnotation(startLoc, node, id) {
4778 switch (id.name) {
4779 case "any":
4780 return this.finishNode(node, "AnyTypeAnnotation");
4781 case "bool":
4782 case "boolean":
4783 return this.finishNode(node, "BooleanTypeAnnotation");
4784 case "mixed":
4785 return this.finishNode(node, "MixedTypeAnnotation");
4786 case "empty":
4787 return this.finishNode(node, "EmptyTypeAnnotation");
4788 case "number":
4789 return this.finishNode(node, "NumberTypeAnnotation");
4790 case "string":
4791 return this.finishNode(node, "StringTypeAnnotation");
4792 case "symbol":
4793 return this.finishNode(node, "SymbolTypeAnnotation");
4794 default:
4795 this.checkNotUnderscore(id.name);
4796 return this.flowParseGenericType(startLoc, id);
4797 }
4798 }
4799 flowParsePrimaryType() {
4800 const startLoc = this.state.startLoc;
4801 const node = this.startNode();
4802 let tmp;
4803 let type;
4804 let isGroupedType = false;
4805 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
4806 switch (this.state.type) {
4807 case 5:
4808 return this.flowParseObjectType({
4809 allowStatic: false,
4810 allowExact: false,
4811 allowSpread: true,
4812 allowProto: false,
4813 allowInexact: true
4814 });
4815 case 6:
4816 return this.flowParseObjectType({
4817 allowStatic: false,
4818 allowExact: true,
4819 allowSpread: true,
4820 allowProto: false,
4821 allowInexact: false
4822 });
4823 case 0:
4824 this.state.noAnonFunctionType = false;
4825 type = this.flowParseTupleType();
4826 this.state.noAnonFunctionType = oldNoAnonFunctionType;
4827 return type;
4828 case 47:
4829 node.typeParameters = this.flowParseTypeParameterDeclaration();
4830 this.expect(10);
4831 tmp = this.flowParseFunctionTypeParams();
4832 node.params = tmp.params;
4833 node.rest = tmp.rest;
4834 node.this = tmp._this;
4835 this.expect(11);
4836 this.expect(19);
4837 node.returnType = this.flowParseType();
4838 return this.finishNode(node, "FunctionTypeAnnotation");
4839 case 10:
4840 this.next();
4841 if (!this.match(11) && !this.match(21)) {
4842 if (tokenIsIdentifier(this.state.type) || this.match(78)) {
4843 const token = this.lookahead().type;
4844 isGroupedType = token !== 17 && token !== 14;
4845 } else {
4846 isGroupedType = true;
4847 }
4848 }
4849 if (isGroupedType) {
4850 this.state.noAnonFunctionType = false;
4851 type = this.flowParseType();
4852 this.state.noAnonFunctionType = oldNoAnonFunctionType;
4853 if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
4854 this.expect(11);
4855 return type;
4856 } else {
4857 this.eat(12);
4858 }
4859 }
4860 if (type) {
4861 tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
4862 } else {
4863 tmp = this.flowParseFunctionTypeParams();
4864 }
4865 node.params = tmp.params;
4866 node.rest = tmp.rest;
4867 node.this = tmp._this;
4868 this.expect(11);
4869 this.expect(19);
4870 node.returnType = this.flowParseType();
4871 node.typeParameters = null;
4872 return this.finishNode(node, "FunctionTypeAnnotation");
4873 case 131:
4874 return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
4875 case 85:
4876 case 86:
4877 node.value = this.match(85);
4878 this.next();
4879 return this.finishNode(node, "BooleanLiteralTypeAnnotation");
4880 case 53:
4881 if (this.state.value === "-") {
4882 this.next();
4883 if (this.match(132)) {
4884 return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
4885 }
4886 if (this.match(133)) {
4887 return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
4888 }
4889 throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
4890 at: this.state.startLoc
4891 });
4892 }
4893 this.unexpected();
4894 return;
4895 case 132:
4896 return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
4897 case 133:
4898 return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
4899 case 88:
4900 this.next();
4901 return this.finishNode(node, "VoidTypeAnnotation");
4902 case 84:
4903 this.next();
4904 return this.finishNode(node, "NullLiteralTypeAnnotation");
4905 case 78:
4906 this.next();
4907 return this.finishNode(node, "ThisTypeAnnotation");
4908 case 55:
4909 this.next();
4910 return this.finishNode(node, "ExistsTypeAnnotation");
4911 case 87:
4912 return this.flowParseTypeofType();
4913 default:
4914 if (tokenIsKeyword(this.state.type)) {
4915 const label = tokenLabelName(this.state.type);
4916 this.next();
4917 return super.createIdentifier(node, label);
4918 } else if (tokenIsIdentifier(this.state.type)) {
4919 if (this.isContextual(127)) {
4920 return this.flowParseInterfaceType();
4921 }
4922 return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
4923 }
4924 }
4925 this.unexpected();
4926 }
4927 flowParsePostfixType() {
4928 const startLoc = this.state.startLoc;
4929 let type = this.flowParsePrimaryType();
4930 let seenOptionalIndexedAccess = false;
4931 while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
4932 const node = this.startNodeAt(startLoc);
4933 const optional = this.eat(18);
4934 seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
4935 this.expect(0);
4936 if (!optional && this.match(3)) {
4937 node.elementType = type;
4938 this.next();
4939 type = this.finishNode(node, "ArrayTypeAnnotation");
4940 } else {
4941 node.objectType = type;
4942 node.indexType = this.flowParseType();
4943 this.expect(3);
4944 if (seenOptionalIndexedAccess) {
4945 node.optional = optional;
4946 type = this.finishNode(node, "OptionalIndexedAccessType");
4947 } else {
4948 type = this.finishNode(node, "IndexedAccessType");
4949 }
4950 }
4951 }
4952 return type;
4953 }
4954 flowParsePrefixType() {
4955 const node = this.startNode();
4956 if (this.eat(17)) {
4957 node.typeAnnotation = this.flowParsePrefixType();
4958 return this.finishNode(node, "NullableTypeAnnotation");
4959 } else {
4960 return this.flowParsePostfixType();
4961 }
4962 }
4963 flowParseAnonFunctionWithoutParens() {
4964 const param = this.flowParsePrefixType();
4965 if (!this.state.noAnonFunctionType && this.eat(19)) {
4966 const node = this.startNodeAt(param.loc.start);
4967 node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
4968 node.rest = null;
4969 node.this = null;
4970 node.returnType = this.flowParseType();
4971 node.typeParameters = null;
4972 return this.finishNode(node, "FunctionTypeAnnotation");
4973 }
4974 return param;
4975 }
4976 flowParseIntersectionType() {
4977 const node = this.startNode();
4978 this.eat(45);
4979 const type = this.flowParseAnonFunctionWithoutParens();
4980 node.types = [type];
4981 while (this.eat(45)) {
4982 node.types.push(this.flowParseAnonFunctionWithoutParens());
4983 }
4984 return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
4985 }
4986 flowParseUnionType() {
4987 const node = this.startNode();
4988 this.eat(43);
4989 const type = this.flowParseIntersectionType();
4990 node.types = [type];
4991 while (this.eat(43)) {
4992 node.types.push(this.flowParseIntersectionType());
4993 }
4994 return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
4995 }
4996 flowParseType() {
4997 const oldInType = this.state.inType;
4998 this.state.inType = true;
4999 const type = this.flowParseUnionType();
5000 this.state.inType = oldInType;
5001 return type;
5002 }
5003 flowParseTypeOrImplicitInstantiation() {
5004 if (this.state.type === 130 && this.state.value === "_") {
5005 const startLoc = this.state.startLoc;
5006 const node = this.parseIdentifier();
5007 return this.flowParseGenericType(startLoc, node);
5008 } else {
5009 return this.flowParseType();
5010 }
5011 }
5012 flowParseTypeAnnotation() {
5013 const node = this.startNode();
5014 node.typeAnnotation = this.flowParseTypeInitialiser();
5015 return this.finishNode(node, "TypeAnnotation");
5016 }
5017 flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
5018 const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
5019 if (this.match(14)) {
5020 ident.typeAnnotation = this.flowParseTypeAnnotation();
5021 this.resetEndLocation(ident);
5022 }
5023 return ident;
5024 }
5025 typeCastToParameter(node) {
5026 node.expression.typeAnnotation = node.typeAnnotation;
5027 this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
5028 return node.expression;
5029 }
5030 flowParseVariance() {
5031 let variance = null;
5032 if (this.match(53)) {
5033 variance = this.startNode();
5034 if (this.state.value === "+") {
5035 variance.kind = "plus";
5036 } else {
5037 variance.kind = "minus";
5038 }
5039 this.next();
5040 return this.finishNode(variance, "Variance");
5041 }
5042 return variance;
5043 }
5044 parseFunctionBody(node, allowExpressionBody, isMethod = false) {
5045 if (allowExpressionBody) {
5046 this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
5047 return;
5048 }
5049 super.parseFunctionBody(node, false, isMethod);
5050 }
5051 parseFunctionBodyAndFinish(node, type, isMethod = false) {
5052 if (this.match(14)) {
5053 const typeNode = this.startNode();
5054 [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
5055 node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
5056 }
5057 return super.parseFunctionBodyAndFinish(node, type, isMethod);
5058 }
5059 parseStatementLike(flags) {
5060 if (this.state.strict && this.isContextual(127)) {
5061 const lookahead = this.lookahead();
5062 if (tokenIsKeywordOrIdentifier(lookahead.type)) {
5063 const node = this.startNode();
5064 this.next();
5065 return this.flowParseInterface(node);
5066 }
5067 } else if (this.shouldParseEnums() && this.isContextual(124)) {
5068 const node = this.startNode();
5069 this.next();
5070 return this.flowParseEnumDeclaration(node);
5071 }
5072 const stmt = super.parseStatementLike(flags);
5073 if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
5074 this.flowPragma = null;
5075 }
5076 return stmt;
5077 }
5078 parseExpressionStatement(node, expr, decorators) {
5079 if (expr.type === "Identifier") {
5080 if (expr.name === "declare") {
5081 if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
5082 return this.flowParseDeclare(node);
5083 }
5084 } else if (tokenIsIdentifier(this.state.type)) {
5085 if (expr.name === "interface") {
5086 return this.flowParseInterface(node);
5087 } else if (expr.name === "type") {
5088 return this.flowParseTypeAlias(node);
5089 } else if (expr.name === "opaque") {
5090 return this.flowParseOpaqueType(node, false);
5091 }
5092 }
5093 }
5094 return super.parseExpressionStatement(node, expr, decorators);
5095 }
5096 shouldParseExportDeclaration() {
5097 const {
5098 type
5099 } = this.state;
5100 if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
5101 return !this.state.containsEsc;
5102 }
5103 return super.shouldParseExportDeclaration();
5104 }
5105 isExportDefaultSpecifier() {
5106 const {
5107 type
5108 } = this.state;
5109 if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
5110 return this.state.containsEsc;
5111 }
5112 return super.isExportDefaultSpecifier();
5113 }
5114 parseExportDefaultExpression() {
5115 if (this.shouldParseEnums() && this.isContextual(124)) {
5116 const node = this.startNode();
5117 this.next();
5118 return this.flowParseEnumDeclaration(node);
5119 }
5120 return super.parseExportDefaultExpression();
5121 }
5122 parseConditional(expr, startLoc, refExpressionErrors) {
5123 if (!this.match(17)) return expr;
5124 if (this.state.maybeInArrowParameters) {
5125 const nextCh = this.lookaheadCharCode();
5126 if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
5127 this.setOptionalParametersError(refExpressionErrors);
5128 return expr;
5129 }
5130 }
5131 this.expect(17);
5132 const state = this.state.clone();
5133 const originalNoArrowAt = this.state.noArrowAt;
5134 const node = this.startNodeAt(startLoc);
5135 let {
5136 consequent,
5137 failed
5138 } = this.tryParseConditionalConsequent();
5139 let [valid, invalid] = this.getArrowLikeExpressions(consequent);
5140 if (failed || invalid.length > 0) {
5141 const noArrowAt = [...originalNoArrowAt];
5142 if (invalid.length > 0) {
5143 this.state = state;
5144 this.state.noArrowAt = noArrowAt;
5145 for (let i = 0; i < invalid.length; i++) {
5146 noArrowAt.push(invalid[i].start);
5147 }
5148 ({
5149 consequent,
5150 failed
5151 } = this.tryParseConditionalConsequent());
5152 [valid, invalid] = this.getArrowLikeExpressions(consequent);
5153 }
5154 if (failed && valid.length > 1) {
5155 this.raise(FlowErrors.AmbiguousConditionalArrow, {
5156 at: state.startLoc
5157 });
5158 }
5159 if (failed && valid.length === 1) {
5160 this.state = state;
5161 noArrowAt.push(valid[0].start);
5162 this.state.noArrowAt = noArrowAt;
5163 ({
5164 consequent,
5165 failed
5166 } = this.tryParseConditionalConsequent());
5167 }
5168 }
5169 this.getArrowLikeExpressions(consequent, true);
5170 this.state.noArrowAt = originalNoArrowAt;
5171 this.expect(14);
5172 node.test = expr;
5173 node.consequent = consequent;
5174 node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
5175 return this.finishNode(node, "ConditionalExpression");
5176 }
5177 tryParseConditionalConsequent() {
5178 this.state.noArrowParamsConversionAt.push(this.state.start);
5179 const consequent = this.parseMaybeAssignAllowIn();
5180 const failed = !this.match(14);
5181 this.state.noArrowParamsConversionAt.pop();
5182 return {
5183 consequent,
5184 failed
5185 };
5186 }
5187 getArrowLikeExpressions(node, disallowInvalid) {
5188 const stack = [node];
5189 const arrows = [];
5190 while (stack.length !== 0) {
5191 const node = stack.pop();
5192 if (node.type === "ArrowFunctionExpression") {
5193 if (node.typeParameters || !node.returnType) {
5194 this.finishArrowValidation(node);
5195 } else {
5196 arrows.push(node);
5197 }
5198 stack.push(node.body);
5199 } else if (node.type === "ConditionalExpression") {
5200 stack.push(node.consequent);
5201 stack.push(node.alternate);
5202 }
5203 }
5204 if (disallowInvalid) {
5205 arrows.forEach(node => this.finishArrowValidation(node));
5206 return [arrows, []];
5207 }
5208 return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
5209 }
5210 finishArrowValidation(node) {
5211 var _node$extra;
5212 this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
5213 this.scope.enter(2 | 4);
5214 super.checkParams(node, false, true);
5215 this.scope.exit();
5216 }
5217 forwardNoArrowParamsConversionAt(node, parse) {
5218 let result;
5219 if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
5220 this.state.noArrowParamsConversionAt.push(this.state.start);
5221 result = parse();
5222 this.state.noArrowParamsConversionAt.pop();
5223 } else {
5224 result = parse();
5225 }
5226 return result;
5227 }
5228 parseParenItem(node, startLoc) {
5229 node = super.parseParenItem(node, startLoc);
5230 if (this.eat(17)) {
5231 node.optional = true;
5232 this.resetEndLocation(node);
5233 }
5234 if (this.match(14)) {
5235 const typeCastNode = this.startNodeAt(startLoc);
5236 typeCastNode.expression = node;
5237 typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
5238 return this.finishNode(typeCastNode, "TypeCastExpression");
5239 }
5240 return node;
5241 }
5242 assertModuleNodeAllowed(node) {
5243 if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
5244 return;
5245 }
5246 super.assertModuleNodeAllowed(node);
5247 }
5248 parseExportDeclaration(node) {
5249 if (this.isContextual(128)) {
5250 node.exportKind = "type";
5251 const declarationNode = this.startNode();
5252 this.next();
5253 if (this.match(5)) {
5254 node.specifiers = this.parseExportSpecifiers(true);
5255 super.parseExportFrom(node);
5256 return null;
5257 } else {
5258 return this.flowParseTypeAlias(declarationNode);
5259 }
5260 } else if (this.isContextual(129)) {
5261 node.exportKind = "type";
5262 const declarationNode = this.startNode();
5263 this.next();
5264 return this.flowParseOpaqueType(declarationNode, false);
5265 } else if (this.isContextual(127)) {
5266 node.exportKind = "type";
5267 const declarationNode = this.startNode();
5268 this.next();
5269 return this.flowParseInterface(declarationNode);
5270 } else if (this.shouldParseEnums() && this.isContextual(124)) {
5271 node.exportKind = "value";
5272 const declarationNode = this.startNode();
5273 this.next();
5274 return this.flowParseEnumDeclaration(declarationNode);
5275 } else {
5276 return super.parseExportDeclaration(node);
5277 }
5278 }
5279 eatExportStar(node) {
5280 if (super.eatExportStar(node)) return true;
5281 if (this.isContextual(128) && this.lookahead().type === 55) {
5282 node.exportKind = "type";
5283 this.next();
5284 this.next();
5285 return true;
5286 }
5287 return false;
5288 }
5289 maybeParseExportNamespaceSpecifier(node) {
5290 const {
5291 startLoc
5292 } = this.state;
5293 const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
5294 if (hasNamespace && node.exportKind === "type") {
5295 this.unexpected(startLoc);
5296 }
5297 return hasNamespace;
5298 }
5299 parseClassId(node, isStatement, optionalId) {
5300 super.parseClassId(node, isStatement, optionalId);
5301 if (this.match(47)) {
5302 node.typeParameters = this.flowParseTypeParameterDeclaration();
5303 }
5304 }
5305 parseClassMember(classBody, member, state) {
5306 const {
5307 startLoc
5308 } = this.state;
5309 if (this.isContextual(123)) {
5310 if (super.parseClassMemberFromModifier(classBody, member)) {
5311 return;
5312 }
5313 member.declare = true;
5314 }
5315 super.parseClassMember(classBody, member, state);
5316 if (member.declare) {
5317 if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
5318 this.raise(FlowErrors.DeclareClassElement, {
5319 at: startLoc
5320 });
5321 } else if (member.value) {
5322 this.raise(FlowErrors.DeclareClassFieldInitializer, {
5323 at: member.value
5324 });
5325 }
5326 }
5327 }
5328 isIterator(word) {
5329 return word === "iterator" || word === "asyncIterator";
5330 }
5331 readIterator() {
5332 const word = super.readWord1();
5333 const fullWord = "@@" + word;
5334 if (!this.isIterator(word) || !this.state.inType) {
5335 this.raise(Errors.InvalidIdentifier, {
5336 at: this.state.curPosition(),
5337 identifierName: fullWord
5338 });
5339 }
5340 this.finishToken(130, fullWord);
5341 }
5342 getTokenFromCode(code) {
5343 const next = this.input.charCodeAt(this.state.pos + 1);
5344 if (code === 123 && next === 124) {
5345 this.finishOp(6, 2);
5346 } else if (this.state.inType && (code === 62 || code === 60)) {
5347 this.finishOp(code === 62 ? 48 : 47, 1);
5348 } else if (this.state.inType && code === 63) {
5349 if (next === 46) {
5350 this.finishOp(18, 2);
5351 } else {
5352 this.finishOp(17, 1);
5353 }
5354 } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
5355 this.state.pos += 2;
5356 this.readIterator();
5357 } else {
5358 super.getTokenFromCode(code);
5359 }
5360 }
5361 isAssignable(node, isBinding) {
5362 if (node.type === "TypeCastExpression") {
5363 return this.isAssignable(node.expression, isBinding);
5364 } else {
5365 return super.isAssignable(node, isBinding);
5366 }
5367 }
5368 toAssignable(node, isLHS = false) {
5369 if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
5370 node.left = this.typeCastToParameter(node.left);
5371 }
5372 super.toAssignable(node, isLHS);
5373 }
5374 toAssignableList(exprList, trailingCommaLoc, isLHS) {
5375 for (let i = 0; i < exprList.length; i++) {
5376 const expr = exprList[i];
5377 if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
5378 exprList[i] = this.typeCastToParameter(expr);
5379 }
5380 }
5381 super.toAssignableList(exprList, trailingCommaLoc, isLHS);
5382 }
5383 toReferencedList(exprList, isParenthesizedExpr) {
5384 for (let i = 0; i < exprList.length; i++) {
5385 var _expr$extra;
5386 const expr = exprList[i];
5387 if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
5388 this.raise(FlowErrors.TypeCastInPattern, {
5389 at: expr.typeAnnotation
5390 });
5391 }
5392 }
5393 return exprList;
5394 }
5395 parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
5396 const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
5397 if (canBePattern && !this.state.maybeInArrowParameters) {
5398 this.toReferencedList(node.elements);
5399 }
5400 return node;
5401 }
5402 isValidLVal(type, isParenthesized, binding) {
5403 return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
5404 }
5405 parseClassProperty(node) {
5406 if (this.match(14)) {
5407 node.typeAnnotation = this.flowParseTypeAnnotation();
5408 }
5409 return super.parseClassProperty(node);
5410 }
5411 parseClassPrivateProperty(node) {
5412 if (this.match(14)) {
5413 node.typeAnnotation = this.flowParseTypeAnnotation();
5414 }
5415 return super.parseClassPrivateProperty(node);
5416 }
5417 isClassMethod() {
5418 return this.match(47) || super.isClassMethod();
5419 }
5420 isClassProperty() {
5421 return this.match(14) || super.isClassProperty();
5422 }
5423 isNonstaticConstructor(method) {
5424 return !this.match(14) && super.isNonstaticConstructor(method);
5425 }
5426 pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
5427 if (method.variance) {
5428 this.unexpected(method.variance.loc.start);
5429 }
5430 delete method.variance;
5431 if (this.match(47)) {
5432 method.typeParameters = this.flowParseTypeParameterDeclaration();
5433 }
5434 super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
5435 if (method.params && isConstructor) {
5436 const params = method.params;
5437 if (params.length > 0 && this.isThisParam(params[0])) {
5438 this.raise(FlowErrors.ThisParamBannedInConstructor, {
5439 at: method
5440 });
5441 }
5442 } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
5443 const params = method.value.params;
5444 if (params.length > 0 && this.isThisParam(params[0])) {
5445 this.raise(FlowErrors.ThisParamBannedInConstructor, {
5446 at: method
5447 });
5448 }
5449 }
5450 }
5451 pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
5452 if (method.variance) {
5453 this.unexpected(method.variance.loc.start);
5454 }
5455 delete method.variance;
5456 if (this.match(47)) {
5457 method.typeParameters = this.flowParseTypeParameterDeclaration();
5458 }
5459 super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
5460 }
5461 parseClassSuper(node) {
5462 super.parseClassSuper(node);
5463 if (node.superClass && this.match(47)) {
5464 node.superTypeParameters = this.flowParseTypeParameterInstantiation();
5465 }
5466 if (this.isContextual(111)) {
5467 this.next();
5468 const implemented = node.implements = [];
5469 do {
5470 const node = this.startNode();
5471 node.id = this.flowParseRestrictedIdentifier(true);
5472 if (this.match(47)) {
5473 node.typeParameters = this.flowParseTypeParameterInstantiation();
5474 } else {
5475 node.typeParameters = null;
5476 }
5477 implemented.push(this.finishNode(node, "ClassImplements"));
5478 } while (this.eat(12));
5479 }
5480 }
5481 checkGetterSetterParams(method) {
5482 super.checkGetterSetterParams(method);
5483 const params = this.getObjectOrClassMethodParams(method);
5484 if (params.length > 0) {
5485 const param = params[0];
5486 if (this.isThisParam(param) && method.kind === "get") {
5487 this.raise(FlowErrors.GetterMayNotHaveThisParam, {
5488 at: param
5489 });
5490 } else if (this.isThisParam(param)) {
5491 this.raise(FlowErrors.SetterMayNotHaveThisParam, {
5492 at: param
5493 });
5494 }
5495 }
5496 }
5497 parsePropertyNamePrefixOperator(node) {
5498 node.variance = this.flowParseVariance();
5499 }
5500 parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
5501 if (prop.variance) {
5502 this.unexpected(prop.variance.loc.start);
5503 }
5504 delete prop.variance;
5505 let typeParameters;
5506 if (this.match(47) && !isAccessor) {
5507 typeParameters = this.flowParseTypeParameterDeclaration();
5508 if (!this.match(10)) this.unexpected();
5509 }
5510 const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
5511 if (typeParameters) {
5512 (result.value || result).typeParameters = typeParameters;
5513 }
5514 return result;
5515 }
5516 parseAssignableListItemTypes(param) {
5517 if (this.eat(17)) {
5518 if (param.type !== "Identifier") {
5519 this.raise(FlowErrors.PatternIsOptional, {
5520 at: param
5521 });
5522 }
5523 if (this.isThisParam(param)) {
5524 this.raise(FlowErrors.ThisParamMayNotBeOptional, {
5525 at: param
5526 });
5527 }
5528 param.optional = true;
5529 }
5530 if (this.match(14)) {
5531 param.typeAnnotation = this.flowParseTypeAnnotation();
5532 } else if (this.isThisParam(param)) {
5533 this.raise(FlowErrors.ThisParamAnnotationRequired, {
5534 at: param
5535 });
5536 }
5537 if (this.match(29) && this.isThisParam(param)) {
5538 this.raise(FlowErrors.ThisParamNoDefault, {
5539 at: param
5540 });
5541 }
5542 this.resetEndLocation(param);
5543 return param;
5544 }
5545 parseMaybeDefault(startLoc, left) {
5546 const node = super.parseMaybeDefault(startLoc, left);
5547 if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
5548 this.raise(FlowErrors.TypeBeforeInitializer, {
5549 at: node.typeAnnotation
5550 });
5551 }
5552 return node;
5553 }
5554 checkImportReflection(node) {
5555 super.checkImportReflection(node);
5556 if (node.module && node.importKind !== "value") {
5557 this.raise(FlowErrors.ImportReflectionHasImportType, {
5558 at: node.specifiers[0].loc.start
5559 });
5560 }
5561 }
5562 parseImportSpecifierLocal(node, specifier, type) {
5563 specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
5564 node.specifiers.push(this.finishImportSpecifier(specifier, type));
5565 }
5566 isPotentialImportPhase(isExport) {
5567 if (super.isPotentialImportPhase(isExport)) return true;
5568 if (this.isContextual(128)) {
5569 if (!isExport) return true;
5570 const ch = this.lookaheadCharCode();
5571 return ch === 123 || ch === 42;
5572 }
5573 return !isExport && this.isContextual(87);
5574 }
5575 applyImportPhase(node, isExport, phase, loc) {
5576 super.applyImportPhase(node, isExport, phase, loc);
5577 if (isExport) {
5578 if (!phase && this.match(65)) {
5579 return;
5580 }
5581 node.exportKind = phase === "type" ? phase : "value";
5582 } else {
5583 if (phase === "type" && this.match(55)) this.unexpected();
5584 node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
5585 }
5586 }
5587 parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
5588 const firstIdent = specifier.imported;
5589 let specifierTypeKind = null;
5590 if (firstIdent.type === "Identifier") {
5591 if (firstIdent.name === "type") {
5592 specifierTypeKind = "type";
5593 } else if (firstIdent.name === "typeof") {
5594 specifierTypeKind = "typeof";
5595 }
5596 }
5597 let isBinding = false;
5598 if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
5599 const as_ident = this.parseIdentifier(true);
5600 if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
5601 specifier.imported = as_ident;
5602 specifier.importKind = specifierTypeKind;
5603 specifier.local = cloneIdentifier(as_ident);
5604 } else {
5605 specifier.imported = firstIdent;
5606 specifier.importKind = null;
5607 specifier.local = this.parseIdentifier();
5608 }
5609 } else {
5610 if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
5611 specifier.imported = this.parseIdentifier(true);
5612 specifier.importKind = specifierTypeKind;
5613 } else {
5614 if (importedIsString) {
5615 throw this.raise(Errors.ImportBindingIsString, {
5616 at: specifier,
5617 importName: firstIdent.value
5618 });
5619 }
5620 specifier.imported = firstIdent;
5621 specifier.importKind = null;
5622 }
5623 if (this.eatContextual(93)) {
5624 specifier.local = this.parseIdentifier();
5625 } else {
5626 isBinding = true;
5627 specifier.local = cloneIdentifier(specifier.imported);
5628 }
5629 }
5630 const specifierIsTypeImport = hasTypeImportKind(specifier);
5631 if (isInTypeOnlyImport && specifierIsTypeImport) {
5632 this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
5633 at: specifier
5634 });
5635 }
5636 if (isInTypeOnlyImport || specifierIsTypeImport) {
5637 this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
5638 }
5639 if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
5640 this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
5641 }
5642 return this.finishImportSpecifier(specifier, "ImportSpecifier");
5643 }
5644 parseBindingAtom() {
5645 switch (this.state.type) {
5646 case 78:
5647 return this.parseIdentifier(true);
5648 default:
5649 return super.parseBindingAtom();
5650 }
5651 }
5652 parseFunctionParams(node, isConstructor) {
5653 const kind = node.kind;
5654 if (kind !== "get" && kind !== "set" && this.match(47)) {
5655 node.typeParameters = this.flowParseTypeParameterDeclaration();
5656 }
5657 super.parseFunctionParams(node, isConstructor);
5658 }
5659 parseVarId(decl, kind) {
5660 super.parseVarId(decl, kind);
5661 if (this.match(14)) {
5662 decl.id.typeAnnotation = this.flowParseTypeAnnotation();
5663 this.resetEndLocation(decl.id);
5664 }
5665 }
5666 parseAsyncArrowFromCallExpression(node, call) {
5667 if (this.match(14)) {
5668 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
5669 this.state.noAnonFunctionType = true;
5670 node.returnType = this.flowParseTypeAnnotation();
5671 this.state.noAnonFunctionType = oldNoAnonFunctionType;
5672 }
5673 return super.parseAsyncArrowFromCallExpression(node, call);
5674 }
5675 shouldParseAsyncArrow() {
5676 return this.match(14) || super.shouldParseAsyncArrow();
5677 }
5678 parseMaybeAssign(refExpressionErrors, afterLeftParse) {
5679 var _jsx;
5680 let state = null;
5681 let jsx;
5682 if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
5683 state = this.state.clone();
5684 jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
5685 if (!jsx.error) return jsx.node;
5686 const {
5687 context
5688 } = this.state;
5689 const currentContext = context[context.length - 1];
5690 if (currentContext === types.j_oTag || currentContext === types.j_expr) {
5691 context.pop();
5692 }
5693 }
5694 if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
5695 var _jsx2, _jsx3;
5696 state = state || this.state.clone();
5697 let typeParameters;
5698 const arrow = this.tryParse(abort => {
5699 var _arrowExpression$extr;
5700 typeParameters = this.flowParseTypeParameterDeclaration();
5701 const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
5702 const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
5703 this.resetStartLocationFromNode(result, typeParameters);
5704 return result;
5705 });
5706 if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
5707 const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
5708 if (expr.type !== "ArrowFunctionExpression") abort();
5709 expr.typeParameters = typeParameters;
5710 this.resetStartLocationFromNode(expr, typeParameters);
5711 return arrowExpression;
5712 }, state);
5713 let arrowExpression = null;
5714 if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
5715 if (!arrow.error && !arrow.aborted) {
5716 if (arrow.node.async) {
5717 this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
5718 at: typeParameters
5719 });
5720 }
5721 return arrow.node;
5722 }
5723 arrowExpression = arrow.node;
5724 }
5725 if ((_jsx2 = jsx) != null && _jsx2.node) {
5726 this.state = jsx.failState;
5727 return jsx.node;
5728 }
5729 if (arrowExpression) {
5730 this.state = arrow.failState;
5731 return arrowExpression;
5732 }
5733 if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
5734 if (arrow.thrown) throw arrow.error;
5735 throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
5736 at: typeParameters
5737 });
5738 }
5739 return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
5740 }
5741 parseArrow(node) {
5742 if (this.match(14)) {
5743 const result = this.tryParse(() => {
5744 const oldNoAnonFunctionType = this.state.noAnonFunctionType;
5745 this.state.noAnonFunctionType = true;
5746 const typeNode = this.startNode();
5747 [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
5748 this.state.noAnonFunctionType = oldNoAnonFunctionType;
5749 if (this.canInsertSemicolon()) this.unexpected();
5750 if (!this.match(19)) this.unexpected();
5751 return typeNode;
5752 });
5753 if (result.thrown) return null;
5754 if (result.error) this.state = result.failState;
5755 node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
5756 }
5757 return super.parseArrow(node);
5758 }
5759 shouldParseArrow(params) {
5760 return this.match(14) || super.shouldParseArrow(params);
5761 }
5762 setArrowFunctionParameters(node, params) {
5763 if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
5764 node.params = params;
5765 } else {
5766 super.setArrowFunctionParameters(node, params);
5767 }
5768 }
5769 checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
5770 if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
5771 return;
5772 }
5773 for (let i = 0; i < node.params.length; i++) {
5774 if (this.isThisParam(node.params[i]) && i > 0) {
5775 this.raise(FlowErrors.ThisParamMustBeFirst, {
5776 at: node.params[i]
5777 });
5778 }
5779 }
5780 super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
5781 }
5782 parseParenAndDistinguishExpression(canBeArrow) {
5783 return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
5784 }
5785 parseSubscripts(base, startLoc, noCalls) {
5786 if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
5787 this.next();
5788 const node = this.startNodeAt(startLoc);
5789 node.callee = base;
5790 node.arguments = super.parseCallExpressionArguments(11, false);
5791 base = this.finishNode(node, "CallExpression");
5792 } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
5793 const state = this.state.clone();
5794 const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
5795 if (!arrow.error && !arrow.aborted) return arrow.node;
5796 const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
5797 if (result.node && !result.error) return result.node;
5798 if (arrow.node) {
5799 this.state = arrow.failState;
5800 return arrow.node;
5801 }
5802 if (result.node) {
5803 this.state = result.failState;
5804 return result.node;
5805 }
5806 throw arrow.error || result.error;
5807 }
5808 return super.parseSubscripts(base, startLoc, noCalls);
5809 }
5810 parseSubscript(base, startLoc, noCalls, subscriptState) {
5811 if (this.match(18) && this.isLookaheadToken_lt()) {
5812 subscriptState.optionalChainMember = true;
5813 if (noCalls) {
5814 subscriptState.stop = true;
5815 return base;
5816 }
5817 this.next();
5818 const node = this.startNodeAt(startLoc);
5819 node.callee = base;
5820 node.typeArguments = this.flowParseTypeParameterInstantiation();
5821 this.expect(10);
5822 node.arguments = this.parseCallExpressionArguments(11, false);
5823 node.optional = true;
5824 return this.finishCallExpression(node, true);
5825 } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
5826 const node = this.startNodeAt(startLoc);
5827 node.callee = base;
5828 const result = this.tryParse(() => {
5829 node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
5830 this.expect(10);
5831 node.arguments = super.parseCallExpressionArguments(11, false);
5832 if (subscriptState.optionalChainMember) {
5833 node.optional = false;
5834 }
5835 return this.finishCallExpression(node, subscriptState.optionalChainMember);
5836 });
5837 if (result.node) {
5838 if (result.error) this.state = result.failState;
5839 return result.node;
5840 }
5841 }
5842 return super.parseSubscript(base, startLoc, noCalls, subscriptState);
5843 }
5844 parseNewCallee(node) {
5845 super.parseNewCallee(node);
5846 let targs = null;
5847 if (this.shouldParseTypes() && this.match(47)) {
5848 targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
5849 }
5850 node.typeArguments = targs;
5851 }
5852 parseAsyncArrowWithTypeParameters(startLoc) {
5853 const node = this.startNodeAt(startLoc);
5854 this.parseFunctionParams(node, false);
5855 if (!this.parseArrow(node)) return;
5856 return super.parseArrowExpression(node, undefined, true);
5857 }
5858 readToken_mult_modulo(code) {
5859 const next = this.input.charCodeAt(this.state.pos + 1);
5860 if (code === 42 && next === 47 && this.state.hasFlowComment) {
5861 this.state.hasFlowComment = false;
5862 this.state.pos += 2;
5863 this.nextToken();
5864 return;
5865 }
5866 super.readToken_mult_modulo(code);
5867 }
5868 readToken_pipe_amp(code) {
5869 const next = this.input.charCodeAt(this.state.pos + 1);
5870 if (code === 124 && next === 125) {
5871 this.finishOp(9, 2);
5872 return;
5873 }
5874 super.readToken_pipe_amp(code);
5875 }
5876 parseTopLevel(file, program) {
5877 const fileNode = super.parseTopLevel(file, program);
5878 if (this.state.hasFlowComment) {
5879 this.raise(FlowErrors.UnterminatedFlowComment, {
5880 at: this.state.curPosition()
5881 });
5882 }
5883 return fileNode;
5884 }
5885 skipBlockComment() {
5886 if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
5887 if (this.state.hasFlowComment) {
5888 throw this.raise(FlowErrors.NestedFlowComment, {
5889 at: this.state.startLoc
5890 });
5891 }
5892 this.hasFlowCommentCompletion();
5893 const commentSkip = this.skipFlowComment();
5894 if (commentSkip) {
5895 this.state.pos += commentSkip;
5896 this.state.hasFlowComment = true;
5897 }
5898 return;
5899 }
5900 return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
5901 }
5902 skipFlowComment() {
5903 const {
5904 pos
5905 } = this.state;
5906 let shiftToFirstNonWhiteSpace = 2;
5907 while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
5908 shiftToFirstNonWhiteSpace++;
5909 }
5910 const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
5911 const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
5912 if (ch2 === 58 && ch3 === 58) {
5913 return shiftToFirstNonWhiteSpace + 2;
5914 }
5915 if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
5916 return shiftToFirstNonWhiteSpace + 12;
5917 }
5918 if (ch2 === 58 && ch3 !== 58) {
5919 return shiftToFirstNonWhiteSpace;
5920 }
5921 return false;
5922 }
5923 hasFlowCommentCompletion() {
5924 const end = this.input.indexOf("*/", this.state.pos);
5925 if (end === -1) {
5926 throw this.raise(Errors.UnterminatedComment, {
5927 at: this.state.curPosition()
5928 });
5929 }
5930 }
5931 flowEnumErrorBooleanMemberNotInitialized(loc, {
5932 enumName,
5933 memberName
5934 }) {
5935 this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
5936 at: loc,
5937 memberName,
5938 enumName
5939 });
5940 }
5941 flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
5942 return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
5943 at: loc
5944 }, enumContext));
5945 }
5946 flowEnumErrorNumberMemberNotInitialized(loc, {
5947 enumName,
5948 memberName
5949 }) {
5950 this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
5951 at: loc,
5952 enumName,
5953 memberName
5954 });
5955 }
5956 flowEnumErrorStringMemberInconsistentlyInitialized(node, {
5957 enumName
5958 }) {
5959 this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, {
5960 at: node,
5961 enumName
5962 });
5963 }
5964 flowEnumMemberInit() {
5965 const startLoc = this.state.startLoc;
5966 const endOfInit = () => this.match(12) || this.match(8);
5967 switch (this.state.type) {
5968 case 132:
5969 {
5970 const literal = this.parseNumericLiteral(this.state.value);
5971 if (endOfInit()) {
5972 return {
5973 type: "number",
5974 loc: literal.loc.start,
5975 value: literal
5976 };
5977 }
5978 return {
5979 type: "invalid",
5980 loc: startLoc
5981 };
5982 }
5983 case 131:
5984 {
5985 const literal = this.parseStringLiteral(this.state.value);
5986 if (endOfInit()) {
5987 return {
5988 type: "string",
5989 loc: literal.loc.start,
5990 value: literal
5991 };
5992 }
5993 return {
5994 type: "invalid",
5995 loc: startLoc
5996 };
5997 }
5998 case 85:
5999 case 86:
6000 {
6001 const literal = this.parseBooleanLiteral(this.match(85));
6002 if (endOfInit()) {
6003 return {
6004 type: "boolean",
6005 loc: literal.loc.start,
6006 value: literal
6007 };
6008 }
6009 return {
6010 type: "invalid",
6011 loc: startLoc
6012 };
6013 }
6014 default:
6015 return {
6016 type: "invalid",
6017 loc: startLoc
6018 };
6019 }
6020 }
6021 flowEnumMemberRaw() {
6022 const loc = this.state.startLoc;
6023 const id = this.parseIdentifier(true);
6024 const init = this.eat(29) ? this.flowEnumMemberInit() : {
6025 type: "none",
6026 loc
6027 };
6028 return {
6029 id,
6030 init
6031 };
6032 }
6033 flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
6034 const {
6035 explicitType
6036 } = context;
6037 if (explicitType === null) {
6038 return;
6039 }
6040 if (explicitType !== expectedType) {
6041 this.flowEnumErrorInvalidMemberInitializer(loc, context);
6042 }
6043 }
6044 flowEnumMembers({
6045 enumName,
6046 explicitType
6047 }) {
6048 const seenNames = new Set();
6049 const members = {
6050 booleanMembers: [],
6051 numberMembers: [],
6052 stringMembers: [],
6053 defaultedMembers: []
6054 };
6055 let hasUnknownMembers = false;
6056 while (!this.match(8)) {
6057 if (this.eat(21)) {
6058 hasUnknownMembers = true;
6059 break;
6060 }
6061 const memberNode = this.startNode();
6062 const {
6063 id,
6064 init
6065 } = this.flowEnumMemberRaw();
6066 const memberName = id.name;
6067 if (memberName === "") {
6068 continue;
6069 }
6070 if (/^[a-z]/.test(memberName)) {
6071 this.raise(FlowErrors.EnumInvalidMemberName, {
6072 at: id,
6073 memberName,
6074 suggestion: memberName[0].toUpperCase() + memberName.slice(1),
6075 enumName
6076 });
6077 }
6078 if (seenNames.has(memberName)) {
6079 this.raise(FlowErrors.EnumDuplicateMemberName, {
6080 at: id,
6081 memberName,
6082 enumName
6083 });
6084 }
6085 seenNames.add(memberName);
6086 const context = {
6087 enumName,
6088 explicitType,
6089 memberName
6090 };
6091 memberNode.id = id;
6092 switch (init.type) {
6093 case "boolean":
6094 {
6095 this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
6096 memberNode.init = init.value;
6097 members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
6098 break;
6099 }
6100 case "number":
6101 {
6102 this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
6103 memberNode.init = init.value;
6104 members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
6105 break;
6106 }
6107 case "string":
6108 {
6109 this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
6110 memberNode.init = init.value;
6111 members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
6112 break;
6113 }
6114 case "invalid":
6115 {
6116 throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
6117 }
6118 case "none":
6119 {
6120 switch (explicitType) {
6121 case "boolean":
6122 this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
6123 break;
6124 case "number":
6125 this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
6126 break;
6127 default:
6128 members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
6129 }
6130 }
6131 }
6132 if (!this.match(8)) {
6133 this.expect(12);
6134 }
6135 }
6136 return {
6137 members,
6138 hasUnknownMembers
6139 };
6140 }
6141 flowEnumStringMembers(initializedMembers, defaultedMembers, {
6142 enumName
6143 }) {
6144 if (initializedMembers.length === 0) {
6145 return defaultedMembers;
6146 } else if (defaultedMembers.length === 0) {
6147 return initializedMembers;
6148 } else if (defaultedMembers.length > initializedMembers.length) {
6149 for (const member of initializedMembers) {
6150 this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
6151 enumName
6152 });
6153 }
6154 return defaultedMembers;
6155 } else {
6156 for (const member of defaultedMembers) {
6157 this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
6158 enumName
6159 });
6160 }
6161 return initializedMembers;
6162 }
6163 }
6164 flowEnumParseExplicitType({
6165 enumName
6166 }) {
6167 if (!this.eatContextual(101)) return null;
6168 if (!tokenIsIdentifier(this.state.type)) {
6169 throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
6170 at: this.state.startLoc,
6171 enumName
6172 });
6173 }
6174 const {
6175 value
6176 } = this.state;
6177 this.next();
6178 if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
6179 this.raise(FlowErrors.EnumInvalidExplicitType, {
6180 at: this.state.startLoc,
6181 enumName,
6182 invalidEnumType: value
6183 });
6184 }
6185 return value;
6186 }
6187 flowEnumBody(node, id) {
6188 const enumName = id.name;
6189 const nameLoc = id.loc.start;
6190 const explicitType = this.flowEnumParseExplicitType({
6191 enumName
6192 });
6193 this.expect(5);
6194 const {
6195 members,
6196 hasUnknownMembers
6197 } = this.flowEnumMembers({
6198 enumName,
6199 explicitType
6200 });
6201 node.hasUnknownMembers = hasUnknownMembers;
6202 switch (explicitType) {
6203 case "boolean":
6204 node.explicitType = true;
6205 node.members = members.booleanMembers;
6206 this.expect(8);
6207 return this.finishNode(node, "EnumBooleanBody");
6208 case "number":
6209 node.explicitType = true;
6210 node.members = members.numberMembers;
6211 this.expect(8);
6212 return this.finishNode(node, "EnumNumberBody");
6213 case "string":
6214 node.explicitType = true;
6215 node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
6216 enumName
6217 });
6218 this.expect(8);
6219 return this.finishNode(node, "EnumStringBody");
6220 case "symbol":
6221 node.members = members.defaultedMembers;
6222 this.expect(8);
6223 return this.finishNode(node, "EnumSymbolBody");
6224 default:
6225 {
6226 const empty = () => {
6227 node.members = [];
6228 this.expect(8);
6229 return this.finishNode(node, "EnumStringBody");
6230 };
6231 node.explicitType = false;
6232 const boolsLen = members.booleanMembers.length;
6233 const numsLen = members.numberMembers.length;
6234 const strsLen = members.stringMembers.length;
6235 const defaultedLen = members.defaultedMembers.length;
6236 if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
6237 return empty();
6238 } else if (!boolsLen && !numsLen) {
6239 node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
6240 enumName
6241 });
6242 this.expect(8);
6243 return this.finishNode(node, "EnumStringBody");
6244 } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
6245 for (const member of members.defaultedMembers) {
6246 this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
6247 enumName,
6248 memberName: member.id.name
6249 });
6250 }
6251 node.members = members.booleanMembers;
6252 this.expect(8);
6253 return this.finishNode(node, "EnumBooleanBody");
6254 } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
6255 for (const member of members.defaultedMembers) {
6256 this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
6257 enumName,
6258 memberName: member.id.name
6259 });
6260 }
6261 node.members = members.numberMembers;
6262 this.expect(8);
6263 return this.finishNode(node, "EnumNumberBody");
6264 } else {
6265 this.raise(FlowErrors.EnumInconsistentMemberValues, {
6266 at: nameLoc,
6267 enumName
6268 });
6269 return empty();
6270 }
6271 }
6272 }
6273 }
6274 flowParseEnumDeclaration(node) {
6275 const id = this.parseIdentifier();
6276 node.id = id;
6277 node.body = this.flowEnumBody(this.startNode(), id);
6278 return this.finishNode(node, "EnumDeclaration");
6279 }
6280 isLookaheadToken_lt() {
6281 const next = this.nextTokenStart();
6282 if (this.input.charCodeAt(next) === 60) {
6283 const afterNext = this.input.charCodeAt(next + 1);
6284 return afterNext !== 60 && afterNext !== 61;
6285 }
6286 return false;
6287 }
6288 maybeUnwrapTypeCastExpression(node) {
6289 return node.type === "TypeCastExpression" ? node.expression : node;
6290 }
6291};
6292const entities = {
6293 __proto__: null,
6294 quot: "\u0022",
6295 amp: "&",
6296 apos: "\u0027",
6297 lt: "<",
6298 gt: ">",
6299 nbsp: "\u00A0",
6300 iexcl: "\u00A1",
6301 cent: "\u00A2",
6302 pound: "\u00A3",
6303 curren: "\u00A4",
6304 yen: "\u00A5",
6305 brvbar: "\u00A6",
6306 sect: "\u00A7",
6307 uml: "\u00A8",
6308 copy: "\u00A9",
6309 ordf: "\u00AA",
6310 laquo: "\u00AB",
6311 not: "\u00AC",
6312 shy: "\u00AD",
6313 reg: "\u00AE",
6314 macr: "\u00AF",
6315 deg: "\u00B0",
6316 plusmn: "\u00B1",
6317 sup2: "\u00B2",
6318 sup3: "\u00B3",
6319 acute: "\u00B4",
6320 micro: "\u00B5",
6321 para: "\u00B6",
6322 middot: "\u00B7",
6323 cedil: "\u00B8",
6324 sup1: "\u00B9",
6325 ordm: "\u00BA",
6326 raquo: "\u00BB",
6327 frac14: "\u00BC",
6328 frac12: "\u00BD",
6329 frac34: "\u00BE",
6330 iquest: "\u00BF",
6331 Agrave: "\u00C0",
6332 Aacute: "\u00C1",
6333 Acirc: "\u00C2",
6334 Atilde: "\u00C3",
6335 Auml: "\u00C4",
6336 Aring: "\u00C5",
6337 AElig: "\u00C6",
6338 Ccedil: "\u00C7",
6339 Egrave: "\u00C8",
6340 Eacute: "\u00C9",
6341 Ecirc: "\u00CA",
6342 Euml: "\u00CB",
6343 Igrave: "\u00CC",
6344 Iacute: "\u00CD",
6345 Icirc: "\u00CE",
6346 Iuml: "\u00CF",
6347 ETH: "\u00D0",
6348 Ntilde: "\u00D1",
6349 Ograve: "\u00D2",
6350 Oacute: "\u00D3",
6351 Ocirc: "\u00D4",
6352 Otilde: "\u00D5",
6353 Ouml: "\u00D6",
6354 times: "\u00D7",
6355 Oslash: "\u00D8",
6356 Ugrave: "\u00D9",
6357 Uacute: "\u00DA",
6358 Ucirc: "\u00DB",
6359 Uuml: "\u00DC",
6360 Yacute: "\u00DD",
6361 THORN: "\u00DE",
6362 szlig: "\u00DF",
6363 agrave: "\u00E0",
6364 aacute: "\u00E1",
6365 acirc: "\u00E2",
6366 atilde: "\u00E3",
6367 auml: "\u00E4",
6368 aring: "\u00E5",
6369 aelig: "\u00E6",
6370 ccedil: "\u00E7",
6371 egrave: "\u00E8",
6372 eacute: "\u00E9",
6373 ecirc: "\u00EA",
6374 euml: "\u00EB",
6375 igrave: "\u00EC",
6376 iacute: "\u00ED",
6377 icirc: "\u00EE",
6378 iuml: "\u00EF",
6379 eth: "\u00F0",
6380 ntilde: "\u00F1",
6381 ograve: "\u00F2",
6382 oacute: "\u00F3",
6383 ocirc: "\u00F4",
6384 otilde: "\u00F5",
6385 ouml: "\u00F6",
6386 divide: "\u00F7",
6387 oslash: "\u00F8",
6388 ugrave: "\u00F9",
6389 uacute: "\u00FA",
6390 ucirc: "\u00FB",
6391 uuml: "\u00FC",
6392 yacute: "\u00FD",
6393 thorn: "\u00FE",
6394 yuml: "\u00FF",
6395 OElig: "\u0152",
6396 oelig: "\u0153",
6397 Scaron: "\u0160",
6398 scaron: "\u0161",
6399 Yuml: "\u0178",
6400 fnof: "\u0192",
6401 circ: "\u02C6",
6402 tilde: "\u02DC",
6403 Alpha: "\u0391",
6404 Beta: "\u0392",
6405 Gamma: "\u0393",
6406 Delta: "\u0394",
6407 Epsilon: "\u0395",
6408 Zeta: "\u0396",
6409 Eta: "\u0397",
6410 Theta: "\u0398",
6411 Iota: "\u0399",
6412 Kappa: "\u039A",
6413 Lambda: "\u039B",
6414 Mu: "\u039C",
6415 Nu: "\u039D",
6416 Xi: "\u039E",
6417 Omicron: "\u039F",
6418 Pi: "\u03A0",
6419 Rho: "\u03A1",
6420 Sigma: "\u03A3",
6421 Tau: "\u03A4",
6422 Upsilon: "\u03A5",
6423 Phi: "\u03A6",
6424 Chi: "\u03A7",
6425 Psi: "\u03A8",
6426 Omega: "\u03A9",
6427 alpha: "\u03B1",
6428 beta: "\u03B2",
6429 gamma: "\u03B3",
6430 delta: "\u03B4",
6431 epsilon: "\u03B5",
6432 zeta: "\u03B6",
6433 eta: "\u03B7",
6434 theta: "\u03B8",
6435 iota: "\u03B9",
6436 kappa: "\u03BA",
6437 lambda: "\u03BB",
6438 mu: "\u03BC",
6439 nu: "\u03BD",
6440 xi: "\u03BE",
6441 omicron: "\u03BF",
6442 pi: "\u03C0",
6443 rho: "\u03C1",
6444 sigmaf: "\u03C2",
6445 sigma: "\u03C3",
6446 tau: "\u03C4",
6447 upsilon: "\u03C5",
6448 phi: "\u03C6",
6449 chi: "\u03C7",
6450 psi: "\u03C8",
6451 omega: "\u03C9",
6452 thetasym: "\u03D1",
6453 upsih: "\u03D2",
6454 piv: "\u03D6",
6455 ensp: "\u2002",
6456 emsp: "\u2003",
6457 thinsp: "\u2009",
6458 zwnj: "\u200C",
6459 zwj: "\u200D",
6460 lrm: "\u200E",
6461 rlm: "\u200F",
6462 ndash: "\u2013",
6463 mdash: "\u2014",
6464 lsquo: "\u2018",
6465 rsquo: "\u2019",
6466 sbquo: "\u201A",
6467 ldquo: "\u201C",
6468 rdquo: "\u201D",
6469 bdquo: "\u201E",
6470 dagger: "\u2020",
6471 Dagger: "\u2021",
6472 bull: "\u2022",
6473 hellip: "\u2026",
6474 permil: "\u2030",
6475 prime: "\u2032",
6476 Prime: "\u2033",
6477 lsaquo: "\u2039",
6478 rsaquo: "\u203A",
6479 oline: "\u203E",
6480 frasl: "\u2044",
6481 euro: "\u20AC",
6482 image: "\u2111",
6483 weierp: "\u2118",
6484 real: "\u211C",
6485 trade: "\u2122",
6486 alefsym: "\u2135",
6487 larr: "\u2190",
6488 uarr: "\u2191",
6489 rarr: "\u2192",
6490 darr: "\u2193",
6491 harr: "\u2194",
6492 crarr: "\u21B5",
6493 lArr: "\u21D0",
6494 uArr: "\u21D1",
6495 rArr: "\u21D2",
6496 dArr: "\u21D3",
6497 hArr: "\u21D4",
6498 forall: "\u2200",
6499 part: "\u2202",
6500 exist: "\u2203",
6501 empty: "\u2205",
6502 nabla: "\u2207",
6503 isin: "\u2208",
6504 notin: "\u2209",
6505 ni: "\u220B",
6506 prod: "\u220F",
6507 sum: "\u2211",
6508 minus: "\u2212",
6509 lowast: "\u2217",
6510 radic: "\u221A",
6511 prop: "\u221D",
6512 infin: "\u221E",
6513 ang: "\u2220",
6514 and: "\u2227",
6515 or: "\u2228",
6516 cap: "\u2229",
6517 cup: "\u222A",
6518 int: "\u222B",
6519 there4: "\u2234",
6520 sim: "\u223C",
6521 cong: "\u2245",
6522 asymp: "\u2248",
6523 ne: "\u2260",
6524 equiv: "\u2261",
6525 le: "\u2264",
6526 ge: "\u2265",
6527 sub: "\u2282",
6528 sup: "\u2283",
6529 nsub: "\u2284",
6530 sube: "\u2286",
6531 supe: "\u2287",
6532 oplus: "\u2295",
6533 otimes: "\u2297",
6534 perp: "\u22A5",
6535 sdot: "\u22C5",
6536 lceil: "\u2308",
6537 rceil: "\u2309",
6538 lfloor: "\u230A",
6539 rfloor: "\u230B",
6540 lang: "\u2329",
6541 rang: "\u232A",
6542 loz: "\u25CA",
6543 spades: "\u2660",
6544 clubs: "\u2663",
6545 hearts: "\u2665",
6546 diams: "\u2666"
6547};
6548const JsxErrors = ParseErrorEnum`jsx`({
6549 AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
6550 MissingClosingTagElement: ({
6551 openingTagName
6552 }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
6553 MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
6554 UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
6555 UnexpectedToken: ({
6556 unexpected,
6557 HTMLEntity
6558 }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
6559 UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
6560 UnterminatedJsxContent: "Unterminated JSX contents.",
6561 UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
6562});
6563function isFragment(object) {
6564 return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
6565}
6566function getQualifiedJSXName(object) {
6567 if (object.type === "JSXIdentifier") {
6568 return object.name;
6569 }
6570 if (object.type === "JSXNamespacedName") {
6571 return object.namespace.name + ":" + object.name.name;
6572 }
6573 if (object.type === "JSXMemberExpression") {
6574 return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
6575 }
6576 throw new Error("Node had unexpected type: " + object.type);
6577}
6578var jsx = superClass => class JSXParserMixin extends superClass {
6579 jsxReadToken() {
6580 let out = "";
6581 let chunkStart = this.state.pos;
6582 for (;;) {
6583 if (this.state.pos >= this.length) {
6584 throw this.raise(JsxErrors.UnterminatedJsxContent, {
6585 at: this.state.startLoc
6586 });
6587 }
6588 const ch = this.input.charCodeAt(this.state.pos);
6589 switch (ch) {
6590 case 60:
6591 case 123:
6592 if (this.state.pos === this.state.start) {
6593 if (ch === 60 && this.state.canStartJSXElement) {
6594 ++this.state.pos;
6595 this.finishToken(140);
6596 } else {
6597 super.getTokenFromCode(ch);
6598 }
6599 return;
6600 }
6601 out += this.input.slice(chunkStart, this.state.pos);
6602 this.finishToken(139, out);
6603 return;
6604 case 38:
6605 out += this.input.slice(chunkStart, this.state.pos);
6606 out += this.jsxReadEntity();
6607 chunkStart = this.state.pos;
6608 break;
6609 case 62:
6610 case 125:
6611 default:
6612 if (isNewLine(ch)) {
6613 out += this.input.slice(chunkStart, this.state.pos);
6614 out += this.jsxReadNewLine(true);
6615 chunkStart = this.state.pos;
6616 } else {
6617 ++this.state.pos;
6618 }
6619 }
6620 }
6621 }
6622 jsxReadNewLine(normalizeCRLF) {
6623 const ch = this.input.charCodeAt(this.state.pos);
6624 let out;
6625 ++this.state.pos;
6626 if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
6627 ++this.state.pos;
6628 out = normalizeCRLF ? "\n" : "\r\n";
6629 } else {
6630 out = String.fromCharCode(ch);
6631 }
6632 ++this.state.curLine;
6633 this.state.lineStart = this.state.pos;
6634 return out;
6635 }
6636 jsxReadString(quote) {
6637 let out = "";
6638 let chunkStart = ++this.state.pos;
6639 for (;;) {
6640 if (this.state.pos >= this.length) {
6641 throw this.raise(Errors.UnterminatedString, {
6642 at: this.state.startLoc
6643 });
6644 }
6645 const ch = this.input.charCodeAt(this.state.pos);
6646 if (ch === quote) break;
6647 if (ch === 38) {
6648 out += this.input.slice(chunkStart, this.state.pos);
6649 out += this.jsxReadEntity();
6650 chunkStart = this.state.pos;
6651 } else if (isNewLine(ch)) {
6652 out += this.input.slice(chunkStart, this.state.pos);
6653 out += this.jsxReadNewLine(false);
6654 chunkStart = this.state.pos;
6655 } else {
6656 ++this.state.pos;
6657 }
6658 }
6659 out += this.input.slice(chunkStart, this.state.pos++);
6660 this.finishToken(131, out);
6661 }
6662 jsxReadEntity() {
6663 const startPos = ++this.state.pos;
6664 if (this.codePointAtPos(this.state.pos) === 35) {
6665 ++this.state.pos;
6666 let radix = 10;
6667 if (this.codePointAtPos(this.state.pos) === 120) {
6668 radix = 16;
6669 ++this.state.pos;
6670 }
6671 const codePoint = this.readInt(radix, undefined, false, "bail");
6672 if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
6673 ++this.state.pos;
6674 return String.fromCodePoint(codePoint);
6675 }
6676 } else {
6677 let count = 0;
6678 let semi = false;
6679 while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
6680 ++this.state.pos;
6681 }
6682 if (semi) {
6683 const desc = this.input.slice(startPos, this.state.pos);
6684 const entity = entities[desc];
6685 ++this.state.pos;
6686 if (entity) {
6687 return entity;
6688 }
6689 }
6690 }
6691 this.state.pos = startPos;
6692 return "&";
6693 }
6694 jsxReadWord() {
6695 let ch;
6696 const start = this.state.pos;
6697 do {
6698 ch = this.input.charCodeAt(++this.state.pos);
6699 } while (isIdentifierChar(ch) || ch === 45);
6700 this.finishToken(138, this.input.slice(start, this.state.pos));
6701 }
6702 jsxParseIdentifier() {
6703 const node = this.startNode();
6704 if (this.match(138)) {
6705 node.name = this.state.value;
6706 } else if (tokenIsKeyword(this.state.type)) {
6707 node.name = tokenLabelName(this.state.type);
6708 } else {
6709 this.unexpected();
6710 }
6711 this.next();
6712 return this.finishNode(node, "JSXIdentifier");
6713 }
6714 jsxParseNamespacedName() {
6715 const startLoc = this.state.startLoc;
6716 const name = this.jsxParseIdentifier();
6717 if (!this.eat(14)) return name;
6718 const node = this.startNodeAt(startLoc);
6719 node.namespace = name;
6720 node.name = this.jsxParseIdentifier();
6721 return this.finishNode(node, "JSXNamespacedName");
6722 }
6723 jsxParseElementName() {
6724 const startLoc = this.state.startLoc;
6725 let node = this.jsxParseNamespacedName();
6726 if (node.type === "JSXNamespacedName") {
6727 return node;
6728 }
6729 while (this.eat(16)) {
6730 const newNode = this.startNodeAt(startLoc);
6731 newNode.object = node;
6732 newNode.property = this.jsxParseIdentifier();
6733 node = this.finishNode(newNode, "JSXMemberExpression");
6734 }
6735 return node;
6736 }
6737 jsxParseAttributeValue() {
6738 let node;
6739 switch (this.state.type) {
6740 case 5:
6741 node = this.startNode();
6742 this.setContext(types.brace);
6743 this.next();
6744 node = this.jsxParseExpressionContainer(node, types.j_oTag);
6745 if (node.expression.type === "JSXEmptyExpression") {
6746 this.raise(JsxErrors.AttributeIsEmpty, {
6747 at: node
6748 });
6749 }
6750 return node;
6751 case 140:
6752 case 131:
6753 return this.parseExprAtom();
6754 default:
6755 throw this.raise(JsxErrors.UnsupportedJsxValue, {
6756 at: this.state.startLoc
6757 });
6758 }
6759 }
6760 jsxParseEmptyExpression() {
6761 const node = this.startNodeAt(this.state.lastTokEndLoc);
6762 return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
6763 }
6764 jsxParseSpreadChild(node) {
6765 this.next();
6766 node.expression = this.parseExpression();
6767 this.setContext(types.j_expr);
6768 this.state.canStartJSXElement = true;
6769 this.expect(8);
6770 return this.finishNode(node, "JSXSpreadChild");
6771 }
6772 jsxParseExpressionContainer(node, previousContext) {
6773 if (this.match(8)) {
6774 node.expression = this.jsxParseEmptyExpression();
6775 } else {
6776 const expression = this.parseExpression();
6777 node.expression = expression;
6778 }
6779 this.setContext(previousContext);
6780 this.state.canStartJSXElement = true;
6781 this.expect(8);
6782 return this.finishNode(node, "JSXExpressionContainer");
6783 }
6784 jsxParseAttribute() {
6785 const node = this.startNode();
6786 if (this.match(5)) {
6787 this.setContext(types.brace);
6788 this.next();
6789 this.expect(21);
6790 node.argument = this.parseMaybeAssignAllowIn();
6791 this.setContext(types.j_oTag);
6792 this.state.canStartJSXElement = true;
6793 this.expect(8);
6794 return this.finishNode(node, "JSXSpreadAttribute");
6795 }
6796 node.name = this.jsxParseNamespacedName();
6797 node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
6798 return this.finishNode(node, "JSXAttribute");
6799 }
6800 jsxParseOpeningElementAt(startLoc) {
6801 const node = this.startNodeAt(startLoc);
6802 if (this.eat(141)) {
6803 return this.finishNode(node, "JSXOpeningFragment");
6804 }
6805 node.name = this.jsxParseElementName();
6806 return this.jsxParseOpeningElementAfterName(node);
6807 }
6808 jsxParseOpeningElementAfterName(node) {
6809 const attributes = [];
6810 while (!this.match(56) && !this.match(141)) {
6811 attributes.push(this.jsxParseAttribute());
6812 }
6813 node.attributes = attributes;
6814 node.selfClosing = this.eat(56);
6815 this.expect(141);
6816 return this.finishNode(node, "JSXOpeningElement");
6817 }
6818 jsxParseClosingElementAt(startLoc) {
6819 const node = this.startNodeAt(startLoc);
6820 if (this.eat(141)) {
6821 return this.finishNode(node, "JSXClosingFragment");
6822 }
6823 node.name = this.jsxParseElementName();
6824 this.expect(141);
6825 return this.finishNode(node, "JSXClosingElement");
6826 }
6827 jsxParseElementAt(startLoc) {
6828 const node = this.startNodeAt(startLoc);
6829 const children = [];
6830 const openingElement = this.jsxParseOpeningElementAt(startLoc);
6831 let closingElement = null;
6832 if (!openingElement.selfClosing) {
6833 contents: for (;;) {
6834 switch (this.state.type) {
6835 case 140:
6836 startLoc = this.state.startLoc;
6837 this.next();
6838 if (this.eat(56)) {
6839 closingElement = this.jsxParseClosingElementAt(startLoc);
6840 break contents;
6841 }
6842 children.push(this.jsxParseElementAt(startLoc));
6843 break;
6844 case 139:
6845 children.push(this.parseExprAtom());
6846 break;
6847 case 5:
6848 {
6849 const node = this.startNode();
6850 this.setContext(types.brace);
6851 this.next();
6852 if (this.match(21)) {
6853 children.push(this.jsxParseSpreadChild(node));
6854 } else {
6855 children.push(this.jsxParseExpressionContainer(node, types.j_expr));
6856 }
6857 break;
6858 }
6859 default:
6860 this.unexpected();
6861 }
6862 }
6863 if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
6864 this.raise(JsxErrors.MissingClosingTagFragment, {
6865 at: closingElement
6866 });
6867 } else if (!isFragment(openingElement) && isFragment(closingElement)) {
6868 this.raise(JsxErrors.MissingClosingTagElement, {
6869 at: closingElement,
6870 openingTagName: getQualifiedJSXName(openingElement.name)
6871 });
6872 } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
6873 if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
6874 this.raise(JsxErrors.MissingClosingTagElement, {
6875 at: closingElement,
6876 openingTagName: getQualifiedJSXName(openingElement.name)
6877 });
6878 }
6879 }
6880 }
6881 if (isFragment(openingElement)) {
6882 node.openingFragment = openingElement;
6883 node.closingFragment = closingElement;
6884 } else {
6885 node.openingElement = openingElement;
6886 node.closingElement = closingElement;
6887 }
6888 node.children = children;
6889 if (this.match(47)) {
6890 throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
6891 at: this.state.startLoc
6892 });
6893 }
6894 return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
6895 }
6896 jsxParseElement() {
6897 const startLoc = this.state.startLoc;
6898 this.next();
6899 return this.jsxParseElementAt(startLoc);
6900 }
6901 setContext(newContext) {
6902 const {
6903 context
6904 } = this.state;
6905 context[context.length - 1] = newContext;
6906 }
6907 parseExprAtom(refExpressionErrors) {
6908 if (this.match(139)) {
6909 return this.parseLiteral(this.state.value, "JSXText");
6910 } else if (this.match(140)) {
6911 return this.jsxParseElement();
6912 } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
6913 this.replaceToken(140);
6914 return this.jsxParseElement();
6915 } else {
6916 return super.parseExprAtom(refExpressionErrors);
6917 }
6918 }
6919 skipSpace() {
6920 const curContext = this.curContext();
6921 if (!curContext.preserveSpace) super.skipSpace();
6922 }
6923 getTokenFromCode(code) {
6924 const context = this.curContext();
6925 if (context === types.j_expr) {
6926 this.jsxReadToken();
6927 return;
6928 }
6929 if (context === types.j_oTag || context === types.j_cTag) {
6930 if (isIdentifierStart(code)) {
6931 this.jsxReadWord();
6932 return;
6933 }
6934 if (code === 62) {
6935 ++this.state.pos;
6936 this.finishToken(141);
6937 return;
6938 }
6939 if ((code === 34 || code === 39) && context === types.j_oTag) {
6940 this.jsxReadString(code);
6941 return;
6942 }
6943 }
6944 if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
6945 ++this.state.pos;
6946 this.finishToken(140);
6947 return;
6948 }
6949 super.getTokenFromCode(code);
6950 }
6951 updateContext(prevType) {
6952 const {
6953 context,
6954 type
6955 } = this.state;
6956 if (type === 56 && prevType === 140) {
6957 context.splice(-2, 2, types.j_cTag);
6958 this.state.canStartJSXElement = false;
6959 } else if (type === 140) {
6960 context.push(types.j_oTag);
6961 } else if (type === 141) {
6962 const out = context[context.length - 1];
6963 if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
6964 context.pop();
6965 this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
6966 } else {
6967 this.setContext(types.j_expr);
6968 this.state.canStartJSXElement = true;
6969 }
6970 } else {
6971 this.state.canStartJSXElement = tokenComesBeforeExpression(type);
6972 }
6973 }
6974};
6975class TypeScriptScope extends Scope {
6976 constructor(...args) {
6977 super(...args);
6978 this.types = new Set();
6979 this.enums = new Set();
6980 this.constEnums = new Set();
6981 this.classes = new Set();
6982 this.exportOnlyBindings = new Set();
6983 }
6984}
6985class TypeScriptScopeHandler extends ScopeHandler {
6986 constructor(...args) {
6987 super(...args);
6988 this.importsStack = [];
6989 }
6990 createScope(flags) {
6991 this.importsStack.push(new Set());
6992 return new TypeScriptScope(flags);
6993 }
6994 enter(flags) {
6995 if (flags == 256) {
6996 this.importsStack.push(new Set());
6997 }
6998 super.enter(flags);
6999 }
7000 exit() {
7001 const flags = super.exit();
7002 if (flags == 256) {
7003 this.importsStack.pop();
7004 }
7005 return flags;
7006 }
7007 hasImport(name, allowShadow) {
7008 const len = this.importsStack.length;
7009 if (this.importsStack[len - 1].has(name)) {
7010 return true;
7011 }
7012 if (!allowShadow && len > 1) {
7013 for (let i = 0; i < len - 1; i++) {
7014 if (this.importsStack[i].has(name)) return true;
7015 }
7016 }
7017 return false;
7018 }
7019 declareName(name, bindingType, loc) {
7020 if (bindingType & 4096) {
7021 if (this.hasImport(name, true)) {
7022 this.parser.raise(Errors.VarRedeclaration, {
7023 at: loc,
7024 identifierName: name
7025 });
7026 }
7027 this.importsStack[this.importsStack.length - 1].add(name);
7028 return;
7029 }
7030 const scope = this.currentScope();
7031 if (bindingType & 1024) {
7032 this.maybeExportDefined(scope, name);
7033 scope.exportOnlyBindings.add(name);
7034 return;
7035 }
7036 super.declareName(name, bindingType, loc);
7037 if (bindingType & 2) {
7038 if (!(bindingType & 1)) {
7039 this.checkRedeclarationInScope(scope, name, bindingType, loc);
7040 this.maybeExportDefined(scope, name);
7041 }
7042 scope.types.add(name);
7043 }
7044 if (bindingType & 256) scope.enums.add(name);
7045 if (bindingType & 512) {
7046 scope.constEnums.add(name);
7047 }
7048 if (bindingType & 128) scope.classes.add(name);
7049 }
7050 isRedeclaredInScope(scope, name, bindingType) {
7051 if (scope.enums.has(name)) {
7052 if (bindingType & 256) {
7053 const isConst = !!(bindingType & 512);
7054 const wasConst = scope.constEnums.has(name);
7055 return isConst !== wasConst;
7056 }
7057 return true;
7058 }
7059 if (bindingType & 128 && scope.classes.has(name)) {
7060 if (scope.lexical.has(name)) {
7061 return !!(bindingType & 1);
7062 } else {
7063 return false;
7064 }
7065 }
7066 if (bindingType & 2 && scope.types.has(name)) {
7067 return true;
7068 }
7069 return super.isRedeclaredInScope(scope, name, bindingType);
7070 }
7071 checkLocalExport(id) {
7072 const {
7073 name
7074 } = id;
7075 if (this.hasImport(name)) return;
7076 const len = this.scopeStack.length;
7077 for (let i = len - 1; i >= 0; i--) {
7078 const scope = this.scopeStack[i];
7079 if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
7080 }
7081 super.checkLocalExport(id);
7082 }
7083}
7084const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
7085const unwrapParenthesizedExpression = node => {
7086 return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
7087};
7088class LValParser extends NodeUtils {
7089 toAssignable(node, isLHS = false) {
7090 var _node$extra, _node$extra3;
7091 let parenthesized = undefined;
7092 if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
7093 parenthesized = unwrapParenthesizedExpression(node);
7094 if (isLHS) {
7095 if (parenthesized.type === "Identifier") {
7096 this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
7097 at: node
7098 });
7099 } else if (parenthesized.type !== "MemberExpression") {
7100 this.raise(Errors.InvalidParenthesizedAssignment, {
7101 at: node
7102 });
7103 }
7104 } else {
7105 this.raise(Errors.InvalidParenthesizedAssignment, {
7106 at: node
7107 });
7108 }
7109 }
7110 switch (node.type) {
7111 case "Identifier":
7112 case "ObjectPattern":
7113 case "ArrayPattern":
7114 case "AssignmentPattern":
7115 case "RestElement":
7116 break;
7117 case "ObjectExpression":
7118 node.type = "ObjectPattern";
7119 for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
7120 var _node$extra2;
7121 const prop = node.properties[i];
7122 const isLast = i === last;
7123 this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
7124 if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
7125 this.raise(Errors.RestTrailingComma, {
7126 at: node.extra.trailingCommaLoc
7127 });
7128 }
7129 }
7130 break;
7131 case "ObjectProperty":
7132 {
7133 const {
7134 key,
7135 value
7136 } = node;
7137 if (this.isPrivateName(key)) {
7138 this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
7139 }
7140 this.toAssignable(value, isLHS);
7141 break;
7142 }
7143 case "SpreadElement":
7144 {
7145 throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
7146 }
7147 case "ArrayExpression":
7148 node.type = "ArrayPattern";
7149 this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
7150 break;
7151 case "AssignmentExpression":
7152 if (node.operator !== "=") {
7153 this.raise(Errors.MissingEqInAssignment, {
7154 at: node.left.loc.end
7155 });
7156 }
7157 node.type = "AssignmentPattern";
7158 delete node.operator;
7159 this.toAssignable(node.left, isLHS);
7160 break;
7161 case "ParenthesizedExpression":
7162 this.toAssignable(parenthesized, isLHS);
7163 break;
7164 }
7165 }
7166 toAssignableObjectExpressionProp(prop, isLast, isLHS) {
7167 if (prop.type === "ObjectMethod") {
7168 this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
7169 at: prop.key
7170 });
7171 } else if (prop.type === "SpreadElement") {
7172 prop.type = "RestElement";
7173 const arg = prop.argument;
7174 this.checkToRestConversion(arg, false);
7175 this.toAssignable(arg, isLHS);
7176 if (!isLast) {
7177 this.raise(Errors.RestTrailingComma, {
7178 at: prop
7179 });
7180 }
7181 } else {
7182 this.toAssignable(prop, isLHS);
7183 }
7184 }
7185 toAssignableList(exprList, trailingCommaLoc, isLHS) {
7186 const end = exprList.length - 1;
7187 for (let i = 0; i <= end; i++) {
7188 const elt = exprList[i];
7189 if (!elt) continue;
7190 if (elt.type === "SpreadElement") {
7191 elt.type = "RestElement";
7192 const arg = elt.argument;
7193 this.checkToRestConversion(arg, true);
7194 this.toAssignable(arg, isLHS);
7195 } else {
7196 this.toAssignable(elt, isLHS);
7197 }
7198 if (elt.type === "RestElement") {
7199 if (i < end) {
7200 this.raise(Errors.RestTrailingComma, {
7201 at: elt
7202 });
7203 } else if (trailingCommaLoc) {
7204 this.raise(Errors.RestTrailingComma, {
7205 at: trailingCommaLoc
7206 });
7207 }
7208 }
7209 }
7210 }
7211 isAssignable(node, isBinding) {
7212 switch (node.type) {
7213 case "Identifier":
7214 case "ObjectPattern":
7215 case "ArrayPattern":
7216 case "AssignmentPattern":
7217 case "RestElement":
7218 return true;
7219 case "ObjectExpression":
7220 {
7221 const last = node.properties.length - 1;
7222 return node.properties.every((prop, i) => {
7223 return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
7224 });
7225 }
7226 case "ObjectProperty":
7227 return this.isAssignable(node.value);
7228 case "SpreadElement":
7229 return this.isAssignable(node.argument);
7230 case "ArrayExpression":
7231 return node.elements.every(element => element === null || this.isAssignable(element));
7232 case "AssignmentExpression":
7233 return node.operator === "=";
7234 case "ParenthesizedExpression":
7235 return this.isAssignable(node.expression);
7236 case "MemberExpression":
7237 case "OptionalMemberExpression":
7238 return !isBinding;
7239 default:
7240 return false;
7241 }
7242 }
7243 toReferencedList(exprList, isParenthesizedExpr) {
7244 return exprList;
7245 }
7246 toReferencedListDeep(exprList, isParenthesizedExpr) {
7247 this.toReferencedList(exprList, isParenthesizedExpr);
7248 for (const expr of exprList) {
7249 if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
7250 this.toReferencedListDeep(expr.elements);
7251 }
7252 }
7253 }
7254 parseSpread(refExpressionErrors) {
7255 const node = this.startNode();
7256 this.next();
7257 node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
7258 return this.finishNode(node, "SpreadElement");
7259 }
7260 parseRestBinding() {
7261 const node = this.startNode();
7262 this.next();
7263 node.argument = this.parseBindingAtom();
7264 return this.finishNode(node, "RestElement");
7265 }
7266 parseBindingAtom() {
7267 switch (this.state.type) {
7268 case 0:
7269 {
7270 const node = this.startNode();
7271 this.next();
7272 node.elements = this.parseBindingList(3, 93, 1);
7273 return this.finishNode(node, "ArrayPattern");
7274 }
7275 case 5:
7276 return this.parseObjectLike(8, true);
7277 }
7278 return this.parseIdentifier();
7279 }
7280 parseBindingList(close, closeCharCode, flags) {
7281 const allowEmpty = flags & 1;
7282 const elts = [];
7283 let first = true;
7284 while (!this.eat(close)) {
7285 if (first) {
7286 first = false;
7287 } else {
7288 this.expect(12);
7289 }
7290 if (allowEmpty && this.match(12)) {
7291 elts.push(null);
7292 } else if (this.eat(close)) {
7293 break;
7294 } else if (this.match(21)) {
7295 elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
7296 if (!this.checkCommaAfterRest(closeCharCode)) {
7297 this.expect(close);
7298 break;
7299 }
7300 } else {
7301 const decorators = [];
7302 if (this.match(26) && this.hasPlugin("decorators")) {
7303 this.raise(Errors.UnsupportedParameterDecorator, {
7304 at: this.state.startLoc
7305 });
7306 }
7307 while (this.match(26)) {
7308 decorators.push(this.parseDecorator());
7309 }
7310 elts.push(this.parseAssignableListItem(flags, decorators));
7311 }
7312 }
7313 return elts;
7314 }
7315 parseBindingRestProperty(prop) {
7316 this.next();
7317 prop.argument = this.parseIdentifier();
7318 this.checkCommaAfterRest(125);
7319 return this.finishNode(prop, "RestElement");
7320 }
7321 parseBindingProperty() {
7322 const prop = this.startNode();
7323 const {
7324 type,
7325 startLoc
7326 } = this.state;
7327 if (type === 21) {
7328 return this.parseBindingRestProperty(prop);
7329 } else if (type === 136) {
7330 this.expectPlugin("destructuringPrivate", startLoc);
7331 this.classScope.usePrivateName(this.state.value, startLoc);
7332 prop.key = this.parsePrivateName();
7333 } else {
7334 this.parsePropertyName(prop);
7335 }
7336 prop.method = false;
7337 return this.parseObjPropValue(prop, startLoc, false, false, true, false);
7338 }
7339 parseAssignableListItem(flags, decorators) {
7340 const left = this.parseMaybeDefault();
7341 this.parseAssignableListItemTypes(left, flags);
7342 const elt = this.parseMaybeDefault(left.loc.start, left);
7343 if (decorators.length) {
7344 left.decorators = decorators;
7345 }
7346 return elt;
7347 }
7348 parseAssignableListItemTypes(param, flags) {
7349 return param;
7350 }
7351 parseMaybeDefault(startLoc, left) {
7352 var _startLoc, _left;
7353 (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
7354 left = (_left = left) != null ? _left : this.parseBindingAtom();
7355 if (!this.eat(29)) return left;
7356 const node = this.startNodeAt(startLoc);
7357 node.left = left;
7358 node.right = this.parseMaybeAssignAllowIn();
7359 return this.finishNode(node, "AssignmentPattern");
7360 }
7361 isValidLVal(type, isUnparenthesizedInAssign, binding) {
7362 return getOwn$1({
7363 AssignmentPattern: "left",
7364 RestElement: "argument",
7365 ObjectProperty: "value",
7366 ParenthesizedExpression: "expression",
7367 ArrayPattern: "elements",
7368 ObjectPattern: "properties"
7369 }, type);
7370 }
7371 checkLVal(expression, {
7372 in: ancestor,
7373 binding = 64,
7374 checkClashes = false,
7375 strictModeChanged = false,
7376 hasParenthesizedAncestor = false
7377 }) {
7378 var _expression$extra;
7379 const type = expression.type;
7380 if (this.isObjectMethod(expression)) return;
7381 if (type === "MemberExpression") {
7382 if (binding !== 64) {
7383 this.raise(Errors.InvalidPropertyBindingPattern, {
7384 at: expression
7385 });
7386 }
7387 return;
7388 }
7389 if (type === "Identifier") {
7390 this.checkIdentifier(expression, binding, strictModeChanged);
7391 const {
7392 name
7393 } = expression;
7394 if (checkClashes) {
7395 if (checkClashes.has(name)) {
7396 this.raise(Errors.ParamDupe, {
7397 at: expression
7398 });
7399 } else {
7400 checkClashes.add(name);
7401 }
7402 }
7403 return;
7404 }
7405 const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
7406 if (validity === true) return;
7407 if (validity === false) {
7408 const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
7409 this.raise(ParseErrorClass, {
7410 at: expression,
7411 ancestor
7412 });
7413 return;
7414 }
7415 const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
7416 const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? {
7417 type
7418 } : ancestor;
7419 for (const child of [].concat(expression[key])) {
7420 if (child) {
7421 this.checkLVal(child, {
7422 in: nextAncestor,
7423 binding,
7424 checkClashes,
7425 strictModeChanged,
7426 hasParenthesizedAncestor: isParenthesizedExpression
7427 });
7428 }
7429 }
7430 }
7431 checkIdentifier(at, bindingType, strictModeChanged = false) {
7432 if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
7433 if (bindingType === 64) {
7434 this.raise(Errors.StrictEvalArguments, {
7435 at,
7436 referenceName: at.name
7437 });
7438 } else {
7439 this.raise(Errors.StrictEvalArgumentsBinding, {
7440 at,
7441 bindingName: at.name
7442 });
7443 }
7444 }
7445 if (bindingType & 8192 && at.name === "let") {
7446 this.raise(Errors.LetInLexicalBinding, {
7447 at
7448 });
7449 }
7450 if (!(bindingType & 64)) {
7451 this.declareNameFromIdentifier(at, bindingType);
7452 }
7453 }
7454 declareNameFromIdentifier(identifier, binding) {
7455 this.scope.declareName(identifier.name, binding, identifier.loc.start);
7456 }
7457 checkToRestConversion(node, allowPattern) {
7458 switch (node.type) {
7459 case "ParenthesizedExpression":
7460 this.checkToRestConversion(node.expression, allowPattern);
7461 break;
7462 case "Identifier":
7463 case "MemberExpression":
7464 break;
7465 case "ArrayExpression":
7466 case "ObjectExpression":
7467 if (allowPattern) break;
7468 default:
7469 this.raise(Errors.InvalidRestAssignmentPattern, {
7470 at: node
7471 });
7472 }
7473 }
7474 checkCommaAfterRest(close) {
7475 if (!this.match(12)) {
7476 return false;
7477 }
7478 this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
7479 at: this.state.startLoc
7480 });
7481 return true;
7482 }
7483}
7484const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
7485function nonNull(x) {
7486 if (x == null) {
7487 throw new Error(`Unexpected ${x} value.`);
7488 }
7489 return x;
7490}
7491function assert(x) {
7492 if (!x) {
7493 throw new Error("Assert fail");
7494 }
7495}
7496const TSErrors = ParseErrorEnum`typescript`({
7497 AbstractMethodHasImplementation: ({
7498 methodName
7499 }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
7500 AbstractPropertyHasInitializer: ({
7501 propertyName
7502 }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
7503 AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
7504 AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
7505 AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
7506 ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
7507 ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
7508 ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
7509 ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
7510 DeclareAccessor: ({
7511 kind
7512 }) => `'declare' is not allowed in ${kind}ters.`,
7513 DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
7514 DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
7515 DuplicateAccessibilityModifier: ({
7516 modifier
7517 }) => `Accessibility modifier already seen.`,
7518 DuplicateModifier: ({
7519 modifier
7520 }) => `Duplicate modifier: '${modifier}'.`,
7521 EmptyHeritageClauseType: ({
7522 token
7523 }) => `'${token}' list cannot be empty.`,
7524 EmptyTypeArguments: "Type argument list cannot be empty.",
7525 EmptyTypeParameters: "Type parameter list cannot be empty.",
7526 ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
7527 ImportAliasHasImportType: "An import alias can not use 'import type'.",
7528 ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
7529 IncompatibleModifiers: ({
7530 modifiers
7531 }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
7532 IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
7533 IndexSignatureHasAccessibility: ({
7534 modifier
7535 }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
7536 IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
7537 IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
7538 IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
7539 InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
7540 InvalidModifierOnTypeMember: ({
7541 modifier
7542 }) => `'${modifier}' modifier cannot appear on a type member.`,
7543 InvalidModifierOnTypeParameter: ({
7544 modifier
7545 }) => `'${modifier}' modifier cannot appear on a type parameter.`,
7546 InvalidModifierOnTypeParameterPositions: ({
7547 modifier
7548 }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
7549 InvalidModifiersOrder: ({
7550 orderedModifiers
7551 }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
7552 InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
7553 InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
7554 MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
7555 MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
7556 NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
7557 NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
7558 OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
7559 OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
7560 PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
7561 PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
7562 PrivateElementHasAccessibility: ({
7563 modifier
7564 }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
7565 ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
7566 ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
7567 ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
7568 SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
7569 SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
7570 SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
7571 SingleTypeParameterWithoutTrailingComma: ({
7572 typeParameterName
7573 }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
7574 StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
7575 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?`).",
7576 TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
7577 TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
7578 TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
7579 TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
7580 UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
7581 UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
7582 UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
7583 UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
7584 UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
7585 UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
7586 UnsupportedSignatureParameterKind: ({
7587 type
7588 }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
7589});
7590function keywordTypeFromName(value) {
7591 switch (value) {
7592 case "any":
7593 return "TSAnyKeyword";
7594 case "boolean":
7595 return "TSBooleanKeyword";
7596 case "bigint":
7597 return "TSBigIntKeyword";
7598 case "never":
7599 return "TSNeverKeyword";
7600 case "number":
7601 return "TSNumberKeyword";
7602 case "object":
7603 return "TSObjectKeyword";
7604 case "string":
7605 return "TSStringKeyword";
7606 case "symbol":
7607 return "TSSymbolKeyword";
7608 case "undefined":
7609 return "TSUndefinedKeyword";
7610 case "unknown":
7611 return "TSUnknownKeyword";
7612 default:
7613 return undefined;
7614 }
7615}
7616function tsIsAccessModifier(modifier) {
7617 return modifier === "private" || modifier === "public" || modifier === "protected";
7618}
7619function tsIsVarianceAnnotations(modifier) {
7620 return modifier === "in" || modifier === "out";
7621}
7622var typescript = superClass => class TypeScriptParserMixin extends superClass {
7623 constructor(...args) {
7624 super(...args);
7625 this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
7626 allowedModifiers: ["in", "out"],
7627 disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
7628 errorTemplate: TSErrors.InvalidModifierOnTypeParameter
7629 });
7630 this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
7631 allowedModifiers: ["const"],
7632 disallowedModifiers: ["in", "out"],
7633 errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
7634 });
7635 this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
7636 allowedModifiers: ["in", "out", "const"],
7637 disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
7638 errorTemplate: TSErrors.InvalidModifierOnTypeParameter
7639 });
7640 }
7641 getScopeHandler() {
7642 return TypeScriptScopeHandler;
7643 }
7644 tsIsIdentifier() {
7645 return tokenIsIdentifier(this.state.type);
7646 }
7647 tsTokenCanFollowModifier() {
7648 return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
7649 }
7650 tsNextTokenCanFollowModifier() {
7651 this.next();
7652 return this.tsTokenCanFollowModifier();
7653 }
7654 tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
7655 if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
7656 return undefined;
7657 }
7658 const modifier = this.state.value;
7659 if (allowedModifiers.indexOf(modifier) !== -1) {
7660 if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
7661 return undefined;
7662 }
7663 if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
7664 return modifier;
7665 }
7666 }
7667 return undefined;
7668 }
7669 tsParseModifiers({
7670 allowedModifiers,
7671 disallowedModifiers,
7672 stopOnStartOfClassStaticBlock,
7673 errorTemplate = TSErrors.InvalidModifierOnTypeMember
7674 }, modified) {
7675 const enforceOrder = (loc, modifier, before, after) => {
7676 if (modifier === before && modified[after]) {
7677 this.raise(TSErrors.InvalidModifiersOrder, {
7678 at: loc,
7679 orderedModifiers: [before, after]
7680 });
7681 }
7682 };
7683 const incompatible = (loc, modifier, mod1, mod2) => {
7684 if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
7685 this.raise(TSErrors.IncompatibleModifiers, {
7686 at: loc,
7687 modifiers: [mod1, mod2]
7688 });
7689 }
7690 };
7691 for (;;) {
7692 const {
7693 startLoc
7694 } = this.state;
7695 const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
7696 if (!modifier) break;
7697 if (tsIsAccessModifier(modifier)) {
7698 if (modified.accessibility) {
7699 this.raise(TSErrors.DuplicateAccessibilityModifier, {
7700 at: startLoc,
7701 modifier
7702 });
7703 } else {
7704 enforceOrder(startLoc, modifier, modifier, "override");
7705 enforceOrder(startLoc, modifier, modifier, "static");
7706 enforceOrder(startLoc, modifier, modifier, "readonly");
7707 modified.accessibility = modifier;
7708 }
7709 } else if (tsIsVarianceAnnotations(modifier)) {
7710 if (modified[modifier]) {
7711 this.raise(TSErrors.DuplicateModifier, {
7712 at: startLoc,
7713 modifier
7714 });
7715 }
7716 modified[modifier] = true;
7717 enforceOrder(startLoc, modifier, "in", "out");
7718 } else {
7719 if (Object.hasOwnProperty.call(modified, modifier)) {
7720 this.raise(TSErrors.DuplicateModifier, {
7721 at: startLoc,
7722 modifier
7723 });
7724 } else {
7725 enforceOrder(startLoc, modifier, "static", "readonly");
7726 enforceOrder(startLoc, modifier, "static", "override");
7727 enforceOrder(startLoc, modifier, "override", "readonly");
7728 enforceOrder(startLoc, modifier, "abstract", "override");
7729 incompatible(startLoc, modifier, "declare", "override");
7730 incompatible(startLoc, modifier, "static", "abstract");
7731 }
7732 modified[modifier] = true;
7733 }
7734 if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
7735 this.raise(errorTemplate, {
7736 at: startLoc,
7737 modifier
7738 });
7739 }
7740 }
7741 }
7742 tsIsListTerminator(kind) {
7743 switch (kind) {
7744 case "EnumMembers":
7745 case "TypeMembers":
7746 return this.match(8);
7747 case "HeritageClauseElement":
7748 return this.match(5);
7749 case "TupleElementTypes":
7750 return this.match(3);
7751 case "TypeParametersOrArguments":
7752 return this.match(48);
7753 }
7754 }
7755 tsParseList(kind, parseElement) {
7756 const result = [];
7757 while (!this.tsIsListTerminator(kind)) {
7758 result.push(parseElement());
7759 }
7760 return result;
7761 }
7762 tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
7763 return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
7764 }
7765 tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
7766 const result = [];
7767 let trailingCommaPos = -1;
7768 for (;;) {
7769 if (this.tsIsListTerminator(kind)) {
7770 break;
7771 }
7772 trailingCommaPos = -1;
7773 const element = parseElement();
7774 if (element == null) {
7775 return undefined;
7776 }
7777 result.push(element);
7778 if (this.eat(12)) {
7779 trailingCommaPos = this.state.lastTokStart;
7780 continue;
7781 }
7782 if (this.tsIsListTerminator(kind)) {
7783 break;
7784 }
7785 if (expectSuccess) {
7786 this.expect(12);
7787 }
7788 return undefined;
7789 }
7790 if (refTrailingCommaPos) {
7791 refTrailingCommaPos.value = trailingCommaPos;
7792 }
7793 return result;
7794 }
7795 tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
7796 if (!skipFirstToken) {
7797 if (bracket) {
7798 this.expect(0);
7799 } else {
7800 this.expect(47);
7801 }
7802 }
7803 const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
7804 if (bracket) {
7805 this.expect(3);
7806 } else {
7807 this.expect(48);
7808 }
7809 return result;
7810 }
7811 tsParseImportType() {
7812 const node = this.startNode();
7813 this.expect(83);
7814 this.expect(10);
7815 if (!this.match(131)) {
7816 this.raise(TSErrors.UnsupportedImportTypeArgument, {
7817 at: this.state.startLoc
7818 });
7819 }
7820 node.argument = super.parseExprAtom();
7821 this.expect(11);
7822 if (this.eat(16)) {
7823 node.qualifier = this.tsParseEntityName();
7824 }
7825 if (this.match(47)) {
7826 node.typeParameters = this.tsParseTypeArguments();
7827 }
7828 return this.finishNode(node, "TSImportType");
7829 }
7830 tsParseEntityName(allowReservedWords = true) {
7831 let entity = this.parseIdentifier(allowReservedWords);
7832 while (this.eat(16)) {
7833 const node = this.startNodeAtNode(entity);
7834 node.left = entity;
7835 node.right = this.parseIdentifier(allowReservedWords);
7836 entity = this.finishNode(node, "TSQualifiedName");
7837 }
7838 return entity;
7839 }
7840 tsParseTypeReference() {
7841 const node = this.startNode();
7842 node.typeName = this.tsParseEntityName();
7843 if (!this.hasPrecedingLineBreak() && this.match(47)) {
7844 node.typeParameters = this.tsParseTypeArguments();
7845 }
7846 return this.finishNode(node, "TSTypeReference");
7847 }
7848 tsParseThisTypePredicate(lhs) {
7849 this.next();
7850 const node = this.startNodeAtNode(lhs);
7851 node.parameterName = lhs;
7852 node.typeAnnotation = this.tsParseTypeAnnotation(false);
7853 node.asserts = false;
7854 return this.finishNode(node, "TSTypePredicate");
7855 }
7856 tsParseThisTypeNode() {
7857 const node = this.startNode();
7858 this.next();
7859 return this.finishNode(node, "TSThisType");
7860 }
7861 tsParseTypeQuery() {
7862 const node = this.startNode();
7863 this.expect(87);
7864 if (this.match(83)) {
7865 node.exprName = this.tsParseImportType();
7866 } else {
7867 node.exprName = this.tsParseEntityName();
7868 }
7869 if (!this.hasPrecedingLineBreak() && this.match(47)) {
7870 node.typeParameters = this.tsParseTypeArguments();
7871 }
7872 return this.finishNode(node, "TSTypeQuery");
7873 }
7874 tsParseTypeParameter(parseModifiers) {
7875 const node = this.startNode();
7876 parseModifiers(node);
7877 node.name = this.tsParseTypeParameterName();
7878 node.constraint = this.tsEatThenParseType(81);
7879 node.default = this.tsEatThenParseType(29);
7880 return this.finishNode(node, "TSTypeParameter");
7881 }
7882 tsTryParseTypeParameters(parseModifiers) {
7883 if (this.match(47)) {
7884 return this.tsParseTypeParameters(parseModifiers);
7885 }
7886 }
7887 tsParseTypeParameters(parseModifiers) {
7888 const node = this.startNode();
7889 if (this.match(47) || this.match(140)) {
7890 this.next();
7891 } else {
7892 this.unexpected();
7893 }
7894 const refTrailingCommaPos = {
7895 value: -1
7896 };
7897 node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
7898 if (node.params.length === 0) {
7899 this.raise(TSErrors.EmptyTypeParameters, {
7900 at: node
7901 });
7902 }
7903 if (refTrailingCommaPos.value !== -1) {
7904 this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
7905 }
7906 return this.finishNode(node, "TSTypeParameterDeclaration");
7907 }
7908 tsFillSignature(returnToken, signature) {
7909 const returnTokenRequired = returnToken === 19;
7910 const paramsKey = "parameters";
7911 const returnTypeKey = "typeAnnotation";
7912 signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
7913 this.expect(10);
7914 signature[paramsKey] = this.tsParseBindingListForSignature();
7915 if (returnTokenRequired) {
7916 signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
7917 } else if (this.match(returnToken)) {
7918 signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
7919 }
7920 }
7921 tsParseBindingListForSignature() {
7922 const list = super.parseBindingList(11, 41, 2);
7923 for (const pattern of list) {
7924 const {
7925 type
7926 } = pattern;
7927 if (type === "AssignmentPattern" || type === "TSParameterProperty") {
7928 this.raise(TSErrors.UnsupportedSignatureParameterKind, {
7929 at: pattern,
7930 type
7931 });
7932 }
7933 }
7934 return list;
7935 }
7936 tsParseTypeMemberSemicolon() {
7937 if (!this.eat(12) && !this.isLineTerminator()) {
7938 this.expect(13);
7939 }
7940 }
7941 tsParseSignatureMember(kind, node) {
7942 this.tsFillSignature(14, node);
7943 this.tsParseTypeMemberSemicolon();
7944 return this.finishNode(node, kind);
7945 }
7946 tsIsUnambiguouslyIndexSignature() {
7947 this.next();
7948 if (tokenIsIdentifier(this.state.type)) {
7949 this.next();
7950 return this.match(14);
7951 }
7952 return false;
7953 }
7954 tsTryParseIndexSignature(node) {
7955 if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
7956 return;
7957 }
7958 this.expect(0);
7959 const id = this.parseIdentifier();
7960 id.typeAnnotation = this.tsParseTypeAnnotation();
7961 this.resetEndLocation(id);
7962 this.expect(3);
7963 node.parameters = [id];
7964 const type = this.tsTryParseTypeAnnotation();
7965 if (type) node.typeAnnotation = type;
7966 this.tsParseTypeMemberSemicolon();
7967 return this.finishNode(node, "TSIndexSignature");
7968 }
7969 tsParsePropertyOrMethodSignature(node, readonly) {
7970 if (this.eat(17)) node.optional = true;
7971 const nodeAny = node;
7972 if (this.match(10) || this.match(47)) {
7973 if (readonly) {
7974 this.raise(TSErrors.ReadonlyForMethodSignature, {
7975 at: node
7976 });
7977 }
7978 const method = nodeAny;
7979 if (method.kind && this.match(47)) {
7980 this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
7981 at: this.state.curPosition()
7982 });
7983 }
7984 this.tsFillSignature(14, method);
7985 this.tsParseTypeMemberSemicolon();
7986 const paramsKey = "parameters";
7987 const returnTypeKey = "typeAnnotation";
7988 if (method.kind === "get") {
7989 if (method[paramsKey].length > 0) {
7990 this.raise(Errors.BadGetterArity, {
7991 at: this.state.curPosition()
7992 });
7993 if (this.isThisParam(method[paramsKey][0])) {
7994 this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
7995 at: this.state.curPosition()
7996 });
7997 }
7998 }
7999 } else if (method.kind === "set") {
8000 if (method[paramsKey].length !== 1) {
8001 this.raise(Errors.BadSetterArity, {
8002 at: this.state.curPosition()
8003 });
8004 } else {
8005 const firstParameter = method[paramsKey][0];
8006 if (this.isThisParam(firstParameter)) {
8007 this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
8008 at: this.state.curPosition()
8009 });
8010 }
8011 if (firstParameter.type === "Identifier" && firstParameter.optional) {
8012 this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
8013 at: this.state.curPosition()
8014 });
8015 }
8016 if (firstParameter.type === "RestElement") {
8017 this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
8018 at: this.state.curPosition()
8019 });
8020 }
8021 }
8022 if (method[returnTypeKey]) {
8023 this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
8024 at: method[returnTypeKey]
8025 });
8026 }
8027 } else {
8028 method.kind = "method";
8029 }
8030 return this.finishNode(method, "TSMethodSignature");
8031 } else {
8032 const property = nodeAny;
8033 if (readonly) property.readonly = true;
8034 const type = this.tsTryParseTypeAnnotation();
8035 if (type) property.typeAnnotation = type;
8036 this.tsParseTypeMemberSemicolon();
8037 return this.finishNode(property, "TSPropertySignature");
8038 }
8039 }
8040 tsParseTypeMember() {
8041 const node = this.startNode();
8042 if (this.match(10) || this.match(47)) {
8043 return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
8044 }
8045 if (this.match(77)) {
8046 const id = this.startNode();
8047 this.next();
8048 if (this.match(10) || this.match(47)) {
8049 return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
8050 } else {
8051 node.key = this.createIdentifier(id, "new");
8052 return this.tsParsePropertyOrMethodSignature(node, false);
8053 }
8054 }
8055 this.tsParseModifiers({
8056 allowedModifiers: ["readonly"],
8057 disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
8058 }, node);
8059 const idx = this.tsTryParseIndexSignature(node);
8060 if (idx) {
8061 return idx;
8062 }
8063 super.parsePropertyName(node);
8064 if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
8065 node.kind = node.key.name;
8066 super.parsePropertyName(node);
8067 }
8068 return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
8069 }
8070 tsParseTypeLiteral() {
8071 const node = this.startNode();
8072 node.members = this.tsParseObjectTypeMembers();
8073 return this.finishNode(node, "TSTypeLiteral");
8074 }
8075 tsParseObjectTypeMembers() {
8076 this.expect(5);
8077 const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
8078 this.expect(8);
8079 return members;
8080 }
8081 tsIsStartOfMappedType() {
8082 this.next();
8083 if (this.eat(53)) {
8084 return this.isContextual(120);
8085 }
8086 if (this.isContextual(120)) {
8087 this.next();
8088 }
8089 if (!this.match(0)) {
8090 return false;
8091 }
8092 this.next();
8093 if (!this.tsIsIdentifier()) {
8094 return false;
8095 }
8096 this.next();
8097 return this.match(58);
8098 }
8099 tsParseMappedTypeParameter() {
8100 const node = this.startNode();
8101 node.name = this.tsParseTypeParameterName();
8102 node.constraint = this.tsExpectThenParseType(58);
8103 return this.finishNode(node, "TSTypeParameter");
8104 }
8105 tsParseMappedType() {
8106 const node = this.startNode();
8107 this.expect(5);
8108 if (this.match(53)) {
8109 node.readonly = this.state.value;
8110 this.next();
8111 this.expectContextual(120);
8112 } else if (this.eatContextual(120)) {
8113 node.readonly = true;
8114 }
8115 this.expect(0);
8116 node.typeParameter = this.tsParseMappedTypeParameter();
8117 node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
8118 this.expect(3);
8119 if (this.match(53)) {
8120 node.optional = this.state.value;
8121 this.next();
8122 this.expect(17);
8123 } else if (this.eat(17)) {
8124 node.optional = true;
8125 }
8126 node.typeAnnotation = this.tsTryParseType();
8127 this.semicolon();
8128 this.expect(8);
8129 return this.finishNode(node, "TSMappedType");
8130 }
8131 tsParseTupleType() {
8132 const node = this.startNode();
8133 node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
8134 let seenOptionalElement = false;
8135 let labeledElements = null;
8136 node.elementTypes.forEach(elementNode => {
8137 var _labeledElements;
8138 const {
8139 type
8140 } = elementNode;
8141 if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
8142 this.raise(TSErrors.OptionalTypeBeforeRequired, {
8143 at: elementNode
8144 });
8145 }
8146 seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
8147 let checkType = type;
8148 if (type === "TSRestType") {
8149 elementNode = elementNode.typeAnnotation;
8150 checkType = elementNode.type;
8151 }
8152 const isLabeled = checkType === "TSNamedTupleMember";
8153 (_labeledElements = labeledElements) != null ? _labeledElements : labeledElements = isLabeled;
8154 if (labeledElements !== isLabeled) {
8155 this.raise(TSErrors.MixedLabeledAndUnlabeledElements, {
8156 at: elementNode
8157 });
8158 }
8159 });
8160 return this.finishNode(node, "TSTupleType");
8161 }
8162 tsParseTupleElementType() {
8163 const {
8164 startLoc
8165 } = this.state;
8166 const rest = this.eat(21);
8167 let labeled;
8168 let label;
8169 let optional;
8170 let type;
8171 const isWord = tokenIsKeywordOrIdentifier(this.state.type);
8172 const chAfterWord = isWord ? this.lookaheadCharCode() : null;
8173 if (chAfterWord === 58) {
8174 labeled = true;
8175 optional = false;
8176 label = this.parseIdentifier(true);
8177 this.expect(14);
8178 type = this.tsParseType();
8179 } else if (chAfterWord === 63) {
8180 optional = true;
8181 const startLoc = this.state.startLoc;
8182 const wordName = this.state.value;
8183 const typeOrLabel = this.tsParseNonArrayType();
8184 if (this.lookaheadCharCode() === 58) {
8185 labeled = true;
8186 label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
8187 this.expect(17);
8188 this.expect(14);
8189 type = this.tsParseType();
8190 } else {
8191 labeled = false;
8192 type = typeOrLabel;
8193 this.expect(17);
8194 }
8195 } else {
8196 type = this.tsParseType();
8197 optional = this.eat(17);
8198 labeled = this.eat(14);
8199 }
8200 if (labeled) {
8201 let labeledNode;
8202 if (label) {
8203 labeledNode = this.startNodeAtNode(label);
8204 labeledNode.optional = optional;
8205 labeledNode.label = label;
8206 labeledNode.elementType = type;
8207 if (this.eat(17)) {
8208 labeledNode.optional = true;
8209 this.raise(TSErrors.TupleOptionalAfterType, {
8210 at: this.state.lastTokStartLoc
8211 });
8212 }
8213 } else {
8214 labeledNode = this.startNodeAtNode(type);
8215 labeledNode.optional = optional;
8216 this.raise(TSErrors.InvalidTupleMemberLabel, {
8217 at: type
8218 });
8219 labeledNode.label = type;
8220 labeledNode.elementType = this.tsParseType();
8221 }
8222 type = this.finishNode(labeledNode, "TSNamedTupleMember");
8223 } else if (optional) {
8224 const optionalTypeNode = this.startNodeAtNode(type);
8225 optionalTypeNode.typeAnnotation = type;
8226 type = this.finishNode(optionalTypeNode, "TSOptionalType");
8227 }
8228 if (rest) {
8229 const restNode = this.startNodeAt(startLoc);
8230 restNode.typeAnnotation = type;
8231 type = this.finishNode(restNode, "TSRestType");
8232 }
8233 return type;
8234 }
8235 tsParseParenthesizedType() {
8236 const node = this.startNode();
8237 this.expect(10);
8238 node.typeAnnotation = this.tsParseType();
8239 this.expect(11);
8240 return this.finishNode(node, "TSParenthesizedType");
8241 }
8242 tsParseFunctionOrConstructorType(type, abstract) {
8243 const node = this.startNode();
8244 if (type === "TSConstructorType") {
8245 node.abstract = !!abstract;
8246 if (abstract) this.next();
8247 this.next();
8248 }
8249 this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
8250 return this.finishNode(node, type);
8251 }
8252 tsParseLiteralTypeNode() {
8253 const node = this.startNode();
8254 switch (this.state.type) {
8255 case 132:
8256 case 133:
8257 case 131:
8258 case 85:
8259 case 86:
8260 node.literal = super.parseExprAtom();
8261 break;
8262 default:
8263 this.unexpected();
8264 }
8265 return this.finishNode(node, "TSLiteralType");
8266 }
8267 tsParseTemplateLiteralType() {
8268 const node = this.startNode();
8269 node.literal = super.parseTemplate(false);
8270 return this.finishNode(node, "TSLiteralType");
8271 }
8272 parseTemplateSubstitution() {
8273 if (this.state.inType) return this.tsParseType();
8274 return super.parseTemplateSubstitution();
8275 }
8276 tsParseThisTypeOrThisTypePredicate() {
8277 const thisKeyword = this.tsParseThisTypeNode();
8278 if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
8279 return this.tsParseThisTypePredicate(thisKeyword);
8280 } else {
8281 return thisKeyword;
8282 }
8283 }
8284 tsParseNonArrayType() {
8285 switch (this.state.type) {
8286 case 131:
8287 case 132:
8288 case 133:
8289 case 85:
8290 case 86:
8291 return this.tsParseLiteralTypeNode();
8292 case 53:
8293 if (this.state.value === "-") {
8294 const node = this.startNode();
8295 const nextToken = this.lookahead();
8296 if (nextToken.type !== 132 && nextToken.type !== 133) {
8297 this.unexpected();
8298 }
8299 node.literal = this.parseMaybeUnary();
8300 return this.finishNode(node, "TSLiteralType");
8301 }
8302 break;
8303 case 78:
8304 return this.tsParseThisTypeOrThisTypePredicate();
8305 case 87:
8306 return this.tsParseTypeQuery();
8307 case 83:
8308 return this.tsParseImportType();
8309 case 5:
8310 return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
8311 case 0:
8312 return this.tsParseTupleType();
8313 case 10:
8314 return this.tsParseParenthesizedType();
8315 case 25:
8316 case 24:
8317 return this.tsParseTemplateLiteralType();
8318 default:
8319 {
8320 const {
8321 type
8322 } = this.state;
8323 if (tokenIsIdentifier(type) || type === 88 || type === 84) {
8324 const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
8325 if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
8326 const node = this.startNode();
8327 this.next();
8328 return this.finishNode(node, nodeType);
8329 }
8330 return this.tsParseTypeReference();
8331 }
8332 }
8333 }
8334 this.unexpected();
8335 }
8336 tsParseArrayTypeOrHigher() {
8337 let type = this.tsParseNonArrayType();
8338 while (!this.hasPrecedingLineBreak() && this.eat(0)) {
8339 if (this.match(3)) {
8340 const node = this.startNodeAtNode(type);
8341 node.elementType = type;
8342 this.expect(3);
8343 type = this.finishNode(node, "TSArrayType");
8344 } else {
8345 const node = this.startNodeAtNode(type);
8346 node.objectType = type;
8347 node.indexType = this.tsParseType();
8348 this.expect(3);
8349 type = this.finishNode(node, "TSIndexedAccessType");
8350 }
8351 }
8352 return type;
8353 }
8354 tsParseTypeOperator() {
8355 const node = this.startNode();
8356 const operator = this.state.value;
8357 this.next();
8358 node.operator = operator;
8359 node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
8360 if (operator === "readonly") {
8361 this.tsCheckTypeAnnotationForReadOnly(node);
8362 }
8363 return this.finishNode(node, "TSTypeOperator");
8364 }
8365 tsCheckTypeAnnotationForReadOnly(node) {
8366 switch (node.typeAnnotation.type) {
8367 case "TSTupleType":
8368 case "TSArrayType":
8369 return;
8370 default:
8371 this.raise(TSErrors.UnexpectedReadonly, {
8372 at: node
8373 });
8374 }
8375 }
8376 tsParseInferType() {
8377 const node = this.startNode();
8378 this.expectContextual(113);
8379 const typeParameter = this.startNode();
8380 typeParameter.name = this.tsParseTypeParameterName();
8381 typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
8382 node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
8383 return this.finishNode(node, "TSInferType");
8384 }
8385 tsParseConstraintForInferType() {
8386 if (this.eat(81)) {
8387 const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
8388 if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
8389 return constraint;
8390 }
8391 }
8392 }
8393 tsParseTypeOperatorOrHigher() {
8394 const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
8395 return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(113) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
8396 }
8397 tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
8398 const node = this.startNode();
8399 const hasLeadingOperator = this.eat(operator);
8400 const types = [];
8401 do {
8402 types.push(parseConstituentType());
8403 } while (this.eat(operator));
8404 if (types.length === 1 && !hasLeadingOperator) {
8405 return types[0];
8406 }
8407 node.types = types;
8408 return this.finishNode(node, kind);
8409 }
8410 tsParseIntersectionTypeOrHigher() {
8411 return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
8412 }
8413 tsParseUnionTypeOrHigher() {
8414 return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
8415 }
8416 tsIsStartOfFunctionType() {
8417 if (this.match(47)) {
8418 return true;
8419 }
8420 return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
8421 }
8422 tsSkipParameterStart() {
8423 if (tokenIsIdentifier(this.state.type) || this.match(78)) {
8424 this.next();
8425 return true;
8426 }
8427 if (this.match(5)) {
8428 const {
8429 errors
8430 } = this.state;
8431 const previousErrorCount = errors.length;
8432 try {
8433 this.parseObjectLike(8, true);
8434 return errors.length === previousErrorCount;
8435 } catch (_unused) {
8436 return false;
8437 }
8438 }
8439 if (this.match(0)) {
8440 this.next();
8441 const {
8442 errors
8443 } = this.state;
8444 const previousErrorCount = errors.length;
8445 try {
8446 super.parseBindingList(3, 93, 1);
8447 return errors.length === previousErrorCount;
8448 } catch (_unused2) {
8449 return false;
8450 }
8451 }
8452 return false;
8453 }
8454 tsIsUnambiguouslyStartOfFunctionType() {
8455 this.next();
8456 if (this.match(11) || this.match(21)) {
8457 return true;
8458 }
8459 if (this.tsSkipParameterStart()) {
8460 if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
8461 return true;
8462 }
8463 if (this.match(11)) {
8464 this.next();
8465 if (this.match(19)) {
8466 return true;
8467 }
8468 }
8469 }
8470 return false;
8471 }
8472 tsParseTypeOrTypePredicateAnnotation(returnToken) {
8473 return this.tsInType(() => {
8474 const t = this.startNode();
8475 this.expect(returnToken);
8476 const node = this.startNode();
8477 const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
8478 if (asserts && this.match(78)) {
8479 let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
8480 if (thisTypePredicate.type === "TSThisType") {
8481 node.parameterName = thisTypePredicate;
8482 node.asserts = true;
8483 node.typeAnnotation = null;
8484 thisTypePredicate = this.finishNode(node, "TSTypePredicate");
8485 } else {
8486 this.resetStartLocationFromNode(thisTypePredicate, node);
8487 thisTypePredicate.asserts = true;
8488 }
8489 t.typeAnnotation = thisTypePredicate;
8490 return this.finishNode(t, "TSTypeAnnotation");
8491 }
8492 const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
8493 if (!typePredicateVariable) {
8494 if (!asserts) {
8495 return this.tsParseTypeAnnotation(false, t);
8496 }
8497 node.parameterName = this.parseIdentifier();
8498 node.asserts = asserts;
8499 node.typeAnnotation = null;
8500 t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
8501 return this.finishNode(t, "TSTypeAnnotation");
8502 }
8503 const type = this.tsParseTypeAnnotation(false);
8504 node.parameterName = typePredicateVariable;
8505 node.typeAnnotation = type;
8506 node.asserts = asserts;
8507 t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
8508 return this.finishNode(t, "TSTypeAnnotation");
8509 });
8510 }
8511 tsTryParseTypeOrTypePredicateAnnotation() {
8512 if (this.match(14)) {
8513 return this.tsParseTypeOrTypePredicateAnnotation(14);
8514 }
8515 }
8516 tsTryParseTypeAnnotation() {
8517 if (this.match(14)) {
8518 return this.tsParseTypeAnnotation();
8519 }
8520 }
8521 tsTryParseType() {
8522 return this.tsEatThenParseType(14);
8523 }
8524 tsParseTypePredicatePrefix() {
8525 const id = this.parseIdentifier();
8526 if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
8527 this.next();
8528 return id;
8529 }
8530 }
8531 tsParseTypePredicateAsserts() {
8532 if (this.state.type !== 107) {
8533 return false;
8534 }
8535 const containsEsc = this.state.containsEsc;
8536 this.next();
8537 if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
8538 return false;
8539 }
8540 if (containsEsc) {
8541 this.raise(Errors.InvalidEscapedReservedWord, {
8542 at: this.state.lastTokStartLoc,
8543 reservedWord: "asserts"
8544 });
8545 }
8546 return true;
8547 }
8548 tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
8549 this.tsInType(() => {
8550 if (eatColon) this.expect(14);
8551 t.typeAnnotation = this.tsParseType();
8552 });
8553 return this.finishNode(t, "TSTypeAnnotation");
8554 }
8555 tsParseType() {
8556 assert(this.state.inType);
8557 const type = this.tsParseNonConditionalType();
8558 if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
8559 return type;
8560 }
8561 const node = this.startNodeAtNode(type);
8562 node.checkType = type;
8563 node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
8564 this.expect(17);
8565 node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
8566 this.expect(14);
8567 node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
8568 return this.finishNode(node, "TSConditionalType");
8569 }
8570 isAbstractConstructorSignature() {
8571 return this.isContextual(122) && this.lookahead().type === 77;
8572 }
8573 tsParseNonConditionalType() {
8574 if (this.tsIsStartOfFunctionType()) {
8575 return this.tsParseFunctionOrConstructorType("TSFunctionType");
8576 }
8577 if (this.match(77)) {
8578 return this.tsParseFunctionOrConstructorType("TSConstructorType");
8579 } else if (this.isAbstractConstructorSignature()) {
8580 return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
8581 }
8582 return this.tsParseUnionTypeOrHigher();
8583 }
8584 tsParseTypeAssertion() {
8585 if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
8586 this.raise(TSErrors.ReservedTypeAssertion, {
8587 at: this.state.startLoc
8588 });
8589 }
8590 const node = this.startNode();
8591 node.typeAnnotation = this.tsInType(() => {
8592 this.next();
8593 return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
8594 });
8595 this.expect(48);
8596 node.expression = this.parseMaybeUnary();
8597 return this.finishNode(node, "TSTypeAssertion");
8598 }
8599 tsParseHeritageClause(token) {
8600 const originalStartLoc = this.state.startLoc;
8601 const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
8602 const node = this.startNode();
8603 node.expression = this.tsParseEntityName();
8604 if (this.match(47)) {
8605 node.typeParameters = this.tsParseTypeArguments();
8606 }
8607 return this.finishNode(node, "TSExpressionWithTypeArguments");
8608 });
8609 if (!delimitedList.length) {
8610 this.raise(TSErrors.EmptyHeritageClauseType, {
8611 at: originalStartLoc,
8612 token
8613 });
8614 }
8615 return delimitedList;
8616 }
8617 tsParseInterfaceDeclaration(node, properties = {}) {
8618 if (this.hasFollowingLineBreak()) return null;
8619 this.expectContextual(127);
8620 if (properties.declare) node.declare = true;
8621 if (tokenIsIdentifier(this.state.type)) {
8622 node.id = this.parseIdentifier();
8623 this.checkIdentifier(node.id, 130);
8624 } else {
8625 node.id = null;
8626 this.raise(TSErrors.MissingInterfaceName, {
8627 at: this.state.startLoc
8628 });
8629 }
8630 node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
8631 if (this.eat(81)) {
8632 node.extends = this.tsParseHeritageClause("extends");
8633 }
8634 const body = this.startNode();
8635 body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
8636 node.body = this.finishNode(body, "TSInterfaceBody");
8637 return this.finishNode(node, "TSInterfaceDeclaration");
8638 }
8639 tsParseTypeAliasDeclaration(node) {
8640 node.id = this.parseIdentifier();
8641 this.checkIdentifier(node.id, 2);
8642 node.typeAnnotation = this.tsInType(() => {
8643 node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
8644 this.expect(29);
8645 if (this.isContextual(112) && this.lookahead().type !== 16) {
8646 const node = this.startNode();
8647 this.next();
8648 return this.finishNode(node, "TSIntrinsicKeyword");
8649 }
8650 return this.tsParseType();
8651 });
8652 this.semicolon();
8653 return this.finishNode(node, "TSTypeAliasDeclaration");
8654 }
8655 tsInNoContext(cb) {
8656 const oldContext = this.state.context;
8657 this.state.context = [oldContext[0]];
8658 try {
8659 return cb();
8660 } finally {
8661 this.state.context = oldContext;
8662 }
8663 }
8664 tsInType(cb) {
8665 const oldInType = this.state.inType;
8666 this.state.inType = true;
8667 try {
8668 return cb();
8669 } finally {
8670 this.state.inType = oldInType;
8671 }
8672 }
8673 tsInDisallowConditionalTypesContext(cb) {
8674 const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
8675 this.state.inDisallowConditionalTypesContext = true;
8676 try {
8677 return cb();
8678 } finally {
8679 this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
8680 }
8681 }
8682 tsInAllowConditionalTypesContext(cb) {
8683 const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
8684 this.state.inDisallowConditionalTypesContext = false;
8685 try {
8686 return cb();
8687 } finally {
8688 this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
8689 }
8690 }
8691 tsEatThenParseType(token) {
8692 if (this.match(token)) {
8693 return this.tsNextThenParseType();
8694 }
8695 }
8696 tsExpectThenParseType(token) {
8697 return this.tsInType(() => {
8698 this.expect(token);
8699 return this.tsParseType();
8700 });
8701 }
8702 tsNextThenParseType() {
8703 return this.tsInType(() => {
8704 this.next();
8705 return this.tsParseType();
8706 });
8707 }
8708 tsParseEnumMember() {
8709 const node = this.startNode();
8710 node.id = this.match(131) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
8711 if (this.eat(29)) {
8712 node.initializer = super.parseMaybeAssignAllowIn();
8713 }
8714 return this.finishNode(node, "TSEnumMember");
8715 }
8716 tsParseEnumDeclaration(node, properties = {}) {
8717 if (properties.const) node.const = true;
8718 if (properties.declare) node.declare = true;
8719 this.expectContextual(124);
8720 node.id = this.parseIdentifier();
8721 this.checkIdentifier(node.id, node.const ? 8971 : 8459);
8722 this.expect(5);
8723 node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
8724 this.expect(8);
8725 return this.finishNode(node, "TSEnumDeclaration");
8726 }
8727 tsParseModuleBlock() {
8728 const node = this.startNode();
8729 this.scope.enter(0);
8730 this.expect(5);
8731 super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
8732 this.scope.exit();
8733 return this.finishNode(node, "TSModuleBlock");
8734 }
8735 tsParseModuleOrNamespaceDeclaration(node, nested = false) {
8736 node.id = this.parseIdentifier();
8737 if (!nested) {
8738 this.checkIdentifier(node.id, 1024);
8739 }
8740 if (this.eat(16)) {
8741 const inner = this.startNode();
8742 this.tsParseModuleOrNamespaceDeclaration(inner, true);
8743 node.body = inner;
8744 } else {
8745 this.scope.enter(256);
8746 this.prodParam.enter(PARAM);
8747 node.body = this.tsParseModuleBlock();
8748 this.prodParam.exit();
8749 this.scope.exit();
8750 }
8751 return this.finishNode(node, "TSModuleDeclaration");
8752 }
8753 tsParseAmbientExternalModuleDeclaration(node) {
8754 if (this.isContextual(110)) {
8755 node.global = true;
8756 node.id = this.parseIdentifier();
8757 } else if (this.match(131)) {
8758 node.id = super.parseStringLiteral(this.state.value);
8759 } else {
8760 this.unexpected();
8761 }
8762 if (this.match(5)) {
8763 this.scope.enter(256);
8764 this.prodParam.enter(PARAM);
8765 node.body = this.tsParseModuleBlock();
8766 this.prodParam.exit();
8767 this.scope.exit();
8768 } else {
8769 this.semicolon();
8770 }
8771 return this.finishNode(node, "TSModuleDeclaration");
8772 }
8773 tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
8774 node.isExport = isExport || false;
8775 node.id = maybeDefaultIdentifier || this.parseIdentifier();
8776 this.checkIdentifier(node.id, 4096);
8777 this.expect(29);
8778 const moduleReference = this.tsParseModuleReference();
8779 if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
8780 this.raise(TSErrors.ImportAliasHasImportType, {
8781 at: moduleReference
8782 });
8783 }
8784 node.moduleReference = moduleReference;
8785 this.semicolon();
8786 return this.finishNode(node, "TSImportEqualsDeclaration");
8787 }
8788 tsIsExternalModuleReference() {
8789 return this.isContextual(117) && this.lookaheadCharCode() === 40;
8790 }
8791 tsParseModuleReference() {
8792 return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
8793 }
8794 tsParseExternalModuleReference() {
8795 const node = this.startNode();
8796 this.expectContextual(117);
8797 this.expect(10);
8798 if (!this.match(131)) {
8799 this.unexpected();
8800 }
8801 node.expression = super.parseExprAtom();
8802 this.expect(11);
8803 this.sawUnambiguousESM = true;
8804 return this.finishNode(node, "TSExternalModuleReference");
8805 }
8806 tsLookAhead(f) {
8807 const state = this.state.clone();
8808 const res = f();
8809 this.state = state;
8810 return res;
8811 }
8812 tsTryParseAndCatch(f) {
8813 const result = this.tryParse(abort => f() || abort());
8814 if (result.aborted || !result.node) return;
8815 if (result.error) this.state = result.failState;
8816 return result.node;
8817 }
8818 tsTryParse(f) {
8819 const state = this.state.clone();
8820 const result = f();
8821 if (result !== undefined && result !== false) {
8822 return result;
8823 }
8824 this.state = state;
8825 }
8826 tsTryParseDeclare(nany) {
8827 if (this.isLineTerminator()) {
8828 return;
8829 }
8830 let startType = this.state.type;
8831 let kind;
8832 if (this.isContextual(99)) {
8833 startType = 74;
8834 kind = "let";
8835 }
8836 return this.tsInAmbientContext(() => {
8837 switch (startType) {
8838 case 68:
8839 nany.declare = true;
8840 return super.parseFunctionStatement(nany, false, false);
8841 case 80:
8842 nany.declare = true;
8843 return this.parseClass(nany, true, false);
8844 case 124:
8845 return this.tsParseEnumDeclaration(nany, {
8846 declare: true
8847 });
8848 case 110:
8849 return this.tsParseAmbientExternalModuleDeclaration(nany);
8850 case 75:
8851 case 74:
8852 if (!this.match(75) || !this.isLookaheadContextual("enum")) {
8853 nany.declare = true;
8854 return this.parseVarStatement(nany, kind || this.state.value, true);
8855 }
8856 this.expect(75);
8857 return this.tsParseEnumDeclaration(nany, {
8858 const: true,
8859 declare: true
8860 });
8861 case 127:
8862 {
8863 const result = this.tsParseInterfaceDeclaration(nany, {
8864 declare: true
8865 });
8866 if (result) return result;
8867 }
8868 default:
8869 if (tokenIsIdentifier(startType)) {
8870 return this.tsParseDeclaration(nany, this.state.value, true, null);
8871 }
8872 }
8873 });
8874 }
8875 tsTryParseExportDeclaration() {
8876 return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
8877 }
8878 tsParseExpressionStatement(node, expr, decorators) {
8879 switch (expr.name) {
8880 case "declare":
8881 {
8882 const declaration = this.tsTryParseDeclare(node);
8883 if (declaration) {
8884 declaration.declare = true;
8885 }
8886 return declaration;
8887 }
8888 case "global":
8889 if (this.match(5)) {
8890 this.scope.enter(256);
8891 this.prodParam.enter(PARAM);
8892 const mod = node;
8893 mod.global = true;
8894 mod.id = expr;
8895 mod.body = this.tsParseModuleBlock();
8896 this.scope.exit();
8897 this.prodParam.exit();
8898 return this.finishNode(mod, "TSModuleDeclaration");
8899 }
8900 break;
8901 default:
8902 return this.tsParseDeclaration(node, expr.name, false, decorators);
8903 }
8904 }
8905 tsParseDeclaration(node, value, next, decorators) {
8906 switch (value) {
8907 case "abstract":
8908 if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
8909 return this.tsParseAbstractDeclaration(node, decorators);
8910 }
8911 break;
8912 case "module":
8913 if (this.tsCheckLineTerminator(next)) {
8914 if (this.match(131)) {
8915 return this.tsParseAmbientExternalModuleDeclaration(node);
8916 } else if (tokenIsIdentifier(this.state.type)) {
8917 return this.tsParseModuleOrNamespaceDeclaration(node);
8918 }
8919 }
8920 break;
8921 case "namespace":
8922 if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
8923 return this.tsParseModuleOrNamespaceDeclaration(node);
8924 }
8925 break;
8926 case "type":
8927 if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
8928 return this.tsParseTypeAliasDeclaration(node);
8929 }
8930 break;
8931 }
8932 }
8933 tsCheckLineTerminator(next) {
8934 if (next) {
8935 if (this.hasFollowingLineBreak()) return false;
8936 this.next();
8937 return true;
8938 }
8939 return !this.isLineTerminator();
8940 }
8941 tsTryParseGenericAsyncArrowFunction(startLoc) {
8942 if (!this.match(47)) return;
8943 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
8944 this.state.maybeInArrowParameters = true;
8945 const res = this.tsTryParseAndCatch(() => {
8946 const node = this.startNodeAt(startLoc);
8947 node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
8948 super.parseFunctionParams(node);
8949 node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
8950 this.expect(19);
8951 return node;
8952 });
8953 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
8954 if (!res) return;
8955 return super.parseArrowExpression(res, null, true);
8956 }
8957 tsParseTypeArgumentsInExpression() {
8958 if (this.reScan_lt() !== 47) return;
8959 return this.tsParseTypeArguments();
8960 }
8961 tsParseTypeArguments() {
8962 const node = this.startNode();
8963 node.params = this.tsInType(() => this.tsInNoContext(() => {
8964 this.expect(47);
8965 return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
8966 }));
8967 if (node.params.length === 0) {
8968 this.raise(TSErrors.EmptyTypeArguments, {
8969 at: node
8970 });
8971 } else if (!this.state.inType && this.curContext() === types.brace) {
8972 this.reScan_lt_gt();
8973 }
8974 this.expect(48);
8975 return this.finishNode(node, "TSTypeParameterInstantiation");
8976 }
8977 tsIsDeclarationStart() {
8978 return tokenIsTSDeclarationStart(this.state.type);
8979 }
8980 isExportDefaultSpecifier() {
8981 if (this.tsIsDeclarationStart()) return false;
8982 return super.isExportDefaultSpecifier();
8983 }
8984 parseAssignableListItem(flags, decorators) {
8985 const startLoc = this.state.startLoc;
8986 const modified = {};
8987 this.tsParseModifiers({
8988 allowedModifiers: ["public", "private", "protected", "override", "readonly"]
8989 }, modified);
8990 const accessibility = modified.accessibility;
8991 const override = modified.override;
8992 const readonly = modified.readonly;
8993 if (!(flags & 4) && (accessibility || readonly || override)) {
8994 this.raise(TSErrors.UnexpectedParameterModifier, {
8995 at: startLoc
8996 });
8997 }
8998 const left = this.parseMaybeDefault();
8999 this.parseAssignableListItemTypes(left, flags);
9000 const elt = this.parseMaybeDefault(left.loc.start, left);
9001 if (accessibility || readonly || override) {
9002 const pp = this.startNodeAt(startLoc);
9003 if (decorators.length) {
9004 pp.decorators = decorators;
9005 }
9006 if (accessibility) pp.accessibility = accessibility;
9007 if (readonly) pp.readonly = readonly;
9008 if (override) pp.override = override;
9009 if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
9010 this.raise(TSErrors.UnsupportedParameterPropertyKind, {
9011 at: pp
9012 });
9013 }
9014 pp.parameter = elt;
9015 return this.finishNode(pp, "TSParameterProperty");
9016 }
9017 if (decorators.length) {
9018 left.decorators = decorators;
9019 }
9020 return elt;
9021 }
9022 isSimpleParameter(node) {
9023 return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
9024 }
9025 tsDisallowOptionalPattern(node) {
9026 for (const param of node.params) {
9027 if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
9028 this.raise(TSErrors.PatternIsOptional, {
9029 at: param
9030 });
9031 }
9032 }
9033 }
9034 setArrowFunctionParameters(node, params, trailingCommaLoc) {
9035 super.setArrowFunctionParameters(node, params, trailingCommaLoc);
9036 this.tsDisallowOptionalPattern(node);
9037 }
9038 parseFunctionBodyAndFinish(node, type, isMethod = false) {
9039 if (this.match(14)) {
9040 node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
9041 }
9042 const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
9043 if (bodilessType && !this.match(5) && this.isLineTerminator()) {
9044 return this.finishNode(node, bodilessType);
9045 }
9046 if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
9047 this.raise(TSErrors.DeclareFunctionHasImplementation, {
9048 at: node
9049 });
9050 if (node.declare) {
9051 return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
9052 }
9053 }
9054 this.tsDisallowOptionalPattern(node);
9055 return super.parseFunctionBodyAndFinish(node, type, isMethod);
9056 }
9057 registerFunctionStatementId(node) {
9058 if (!node.body && node.id) {
9059 this.checkIdentifier(node.id, 1024);
9060 } else {
9061 super.registerFunctionStatementId(node);
9062 }
9063 }
9064 tsCheckForInvalidTypeCasts(items) {
9065 items.forEach(node => {
9066 if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
9067 this.raise(TSErrors.UnexpectedTypeAnnotation, {
9068 at: node.typeAnnotation
9069 });
9070 }
9071 });
9072 }
9073 toReferencedList(exprList, isInParens) {
9074 this.tsCheckForInvalidTypeCasts(exprList);
9075 return exprList;
9076 }
9077 parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
9078 const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
9079 if (node.type === "ArrayExpression") {
9080 this.tsCheckForInvalidTypeCasts(node.elements);
9081 }
9082 return node;
9083 }
9084 parseSubscript(base, startLoc, noCalls, state) {
9085 if (!this.hasPrecedingLineBreak() && this.match(35)) {
9086 this.state.canStartJSXElement = false;
9087 this.next();
9088 const nonNullExpression = this.startNodeAt(startLoc);
9089 nonNullExpression.expression = base;
9090 return this.finishNode(nonNullExpression, "TSNonNullExpression");
9091 }
9092 let isOptionalCall = false;
9093 if (this.match(18) && this.lookaheadCharCode() === 60) {
9094 if (noCalls) {
9095 state.stop = true;
9096 return base;
9097 }
9098 state.optionalChainMember = isOptionalCall = true;
9099 this.next();
9100 }
9101 if (this.match(47) || this.match(51)) {
9102 let missingParenErrorLoc;
9103 const result = this.tsTryParseAndCatch(() => {
9104 if (!noCalls && this.atPossibleAsyncArrow(base)) {
9105 const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
9106 if (asyncArrowFn) {
9107 return asyncArrowFn;
9108 }
9109 }
9110 const typeArguments = this.tsParseTypeArgumentsInExpression();
9111 if (!typeArguments) return;
9112 if (isOptionalCall && !this.match(10)) {
9113 missingParenErrorLoc = this.state.curPosition();
9114 return;
9115 }
9116 if (tokenIsTemplate(this.state.type)) {
9117 const result = super.parseTaggedTemplateExpression(base, startLoc, state);
9118 result.typeParameters = typeArguments;
9119 return result;
9120 }
9121 if (!noCalls && this.eat(10)) {
9122 const node = this.startNodeAt(startLoc);
9123 node.callee = base;
9124 node.arguments = this.parseCallExpressionArguments(11, false);
9125 this.tsCheckForInvalidTypeCasts(node.arguments);
9126 node.typeParameters = typeArguments;
9127 if (state.optionalChainMember) {
9128 node.optional = isOptionalCall;
9129 }
9130 return this.finishCallExpression(node, state.optionalChainMember);
9131 }
9132 const tokenType = this.state.type;
9133 if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
9134 return;
9135 }
9136 const node = this.startNodeAt(startLoc);
9137 node.expression = base;
9138 node.typeParameters = typeArguments;
9139 return this.finishNode(node, "TSInstantiationExpression");
9140 });
9141 if (missingParenErrorLoc) {
9142 this.unexpected(missingParenErrorLoc, 10);
9143 }
9144 if (result) {
9145 if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
9146 this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
9147 at: this.state.startLoc
9148 });
9149 }
9150 return result;
9151 }
9152 }
9153 return super.parseSubscript(base, startLoc, noCalls, state);
9154 }
9155 parseNewCallee(node) {
9156 var _callee$extra;
9157 super.parseNewCallee(node);
9158 const {
9159 callee
9160 } = node;
9161 if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
9162 node.typeParameters = callee.typeParameters;
9163 node.callee = callee.expression;
9164 }
9165 }
9166 parseExprOp(left, leftStartLoc, minPrec) {
9167 let isSatisfies;
9168 if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(118)))) {
9169 const node = this.startNodeAt(leftStartLoc);
9170 node.expression = left;
9171 node.typeAnnotation = this.tsInType(() => {
9172 this.next();
9173 if (this.match(75)) {
9174 if (isSatisfies) {
9175 this.raise(Errors.UnexpectedKeyword, {
9176 at: this.state.startLoc,
9177 keyword: "const"
9178 });
9179 }
9180 return this.tsParseTypeReference();
9181 }
9182 return this.tsParseType();
9183 });
9184 this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
9185 this.reScan_lt_gt();
9186 return this.parseExprOp(node, leftStartLoc, minPrec);
9187 }
9188 return super.parseExprOp(left, leftStartLoc, minPrec);
9189 }
9190 checkReservedWord(word, startLoc, checkKeywords, isBinding) {
9191 if (!this.state.isAmbientContext) {
9192 super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
9193 }
9194 }
9195 checkImportReflection(node) {
9196 super.checkImportReflection(node);
9197 if (node.module && node.importKind !== "value") {
9198 this.raise(TSErrors.ImportReflectionHasImportType, {
9199 at: node.specifiers[0].loc.start
9200 });
9201 }
9202 }
9203 checkDuplicateExports() {}
9204 isPotentialImportPhase(isExport) {
9205 if (super.isPotentialImportPhase(isExport)) return true;
9206 if (this.isContextual(128)) {
9207 const ch = this.lookaheadCharCode();
9208 return isExport ? ch === 123 || ch === 42 : ch !== 61;
9209 }
9210 return !isExport && this.isContextual(87);
9211 }
9212 applyImportPhase(node, isExport, phase, loc) {
9213 super.applyImportPhase(node, isExport, phase, loc);
9214 if (isExport) {
9215 node.exportKind = phase === "type" ? "type" : "value";
9216 } else {
9217 node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
9218 }
9219 }
9220 parseImport(node) {
9221 if (this.match(131)) {
9222 node.importKind = "value";
9223 return super.parseImport(node);
9224 }
9225 let importNode;
9226 if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
9227 node.importKind = "value";
9228 return this.tsParseImportEqualsDeclaration(node);
9229 } else if (this.isContextual(128)) {
9230 const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
9231 if (this.lookaheadCharCode() === 61) {
9232 return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
9233 } else {
9234 importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
9235 }
9236 } else {
9237 importNode = super.parseImport(node);
9238 }
9239 if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
9240 this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
9241 at: importNode
9242 });
9243 }
9244 return importNode;
9245 }
9246 parseExport(node, decorators) {
9247 if (this.match(83)) {
9248 this.next();
9249 let maybeDefaultIdentifier = null;
9250 if (this.isContextual(128) && this.isPotentialImportPhase(false)) {
9251 maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
9252 } else {
9253 node.importKind = "value";
9254 }
9255 return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true);
9256 } else if (this.eat(29)) {
9257 const assign = node;
9258 assign.expression = super.parseExpression();
9259 this.semicolon();
9260 this.sawUnambiguousESM = true;
9261 return this.finishNode(assign, "TSExportAssignment");
9262 } else if (this.eatContextual(93)) {
9263 const decl = node;
9264 this.expectContextual(126);
9265 decl.id = this.parseIdentifier();
9266 this.semicolon();
9267 return this.finishNode(decl, "TSNamespaceExportDeclaration");
9268 } else {
9269 return super.parseExport(node, decorators);
9270 }
9271 }
9272 isAbstractClass() {
9273 return this.isContextual(122) && this.lookahead().type === 80;
9274 }
9275 parseExportDefaultExpression() {
9276 if (this.isAbstractClass()) {
9277 const cls = this.startNode();
9278 this.next();
9279 cls.abstract = true;
9280 return this.parseClass(cls, true, true);
9281 }
9282 if (this.match(127)) {
9283 const result = this.tsParseInterfaceDeclaration(this.startNode());
9284 if (result) return result;
9285 }
9286 return super.parseExportDefaultExpression();
9287 }
9288 parseVarStatement(node, kind, allowMissingInitializer = false) {
9289 const {
9290 isAmbientContext
9291 } = this.state;
9292 const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
9293 if (!isAmbientContext) return declaration;
9294 for (const {
9295 id,
9296 init
9297 } of declaration.declarations) {
9298 if (!init) continue;
9299 if (kind !== "const" || !!id.typeAnnotation) {
9300 this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
9301 at: init
9302 });
9303 } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
9304 this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
9305 at: init
9306 });
9307 }
9308 }
9309 return declaration;
9310 }
9311 parseStatementContent(flags, decorators) {
9312 if (this.match(75) && this.isLookaheadContextual("enum")) {
9313 const node = this.startNode();
9314 this.expect(75);
9315 return this.tsParseEnumDeclaration(node, {
9316 const: true
9317 });
9318 }
9319 if (this.isContextual(124)) {
9320 return this.tsParseEnumDeclaration(this.startNode());
9321 }
9322 if (this.isContextual(127)) {
9323 const result = this.tsParseInterfaceDeclaration(this.startNode());
9324 if (result) return result;
9325 }
9326 return super.parseStatementContent(flags, decorators);
9327 }
9328 parseAccessModifier() {
9329 return this.tsParseModifier(["public", "protected", "private"]);
9330 }
9331 tsHasSomeModifiers(member, modifiers) {
9332 return modifiers.some(modifier => {
9333 if (tsIsAccessModifier(modifier)) {
9334 return member.accessibility === modifier;
9335 }
9336 return !!member[modifier];
9337 });
9338 }
9339 tsIsStartOfStaticBlocks() {
9340 return this.isContextual(104) && this.lookaheadCharCode() === 123;
9341 }
9342 parseClassMember(classBody, member, state) {
9343 const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
9344 this.tsParseModifiers({
9345 allowedModifiers: modifiers,
9346 disallowedModifiers: ["in", "out"],
9347 stopOnStartOfClassStaticBlock: true,
9348 errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
9349 }, member);
9350 const callParseClassMemberWithIsStatic = () => {
9351 if (this.tsIsStartOfStaticBlocks()) {
9352 this.next();
9353 this.next();
9354 if (this.tsHasSomeModifiers(member, modifiers)) {
9355 this.raise(TSErrors.StaticBlockCannotHaveModifier, {
9356 at: this.state.curPosition()
9357 });
9358 }
9359 super.parseClassStaticBlock(classBody, member);
9360 } else {
9361 this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
9362 }
9363 };
9364 if (member.declare) {
9365 this.tsInAmbientContext(callParseClassMemberWithIsStatic);
9366 } else {
9367 callParseClassMemberWithIsStatic();
9368 }
9369 }
9370 parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
9371 const idx = this.tsTryParseIndexSignature(member);
9372 if (idx) {
9373 classBody.body.push(idx);
9374 if (member.abstract) {
9375 this.raise(TSErrors.IndexSignatureHasAbstract, {
9376 at: member
9377 });
9378 }
9379 if (member.accessibility) {
9380 this.raise(TSErrors.IndexSignatureHasAccessibility, {
9381 at: member,
9382 modifier: member.accessibility
9383 });
9384 }
9385 if (member.declare) {
9386 this.raise(TSErrors.IndexSignatureHasDeclare, {
9387 at: member
9388 });
9389 }
9390 if (member.override) {
9391 this.raise(TSErrors.IndexSignatureHasOverride, {
9392 at: member
9393 });
9394 }
9395 return;
9396 }
9397 if (!this.state.inAbstractClass && member.abstract) {
9398 this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
9399 at: member
9400 });
9401 }
9402 if (member.override) {
9403 if (!state.hadSuperClass) {
9404 this.raise(TSErrors.OverrideNotInSubClass, {
9405 at: member
9406 });
9407 }
9408 }
9409 super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
9410 }
9411 parsePostMemberNameModifiers(methodOrProp) {
9412 const optional = this.eat(17);
9413 if (optional) methodOrProp.optional = true;
9414 if (methodOrProp.readonly && this.match(10)) {
9415 this.raise(TSErrors.ClassMethodHasReadonly, {
9416 at: methodOrProp
9417 });
9418 }
9419 if (methodOrProp.declare && this.match(10)) {
9420 this.raise(TSErrors.ClassMethodHasDeclare, {
9421 at: methodOrProp
9422 });
9423 }
9424 }
9425 parseExpressionStatement(node, expr, decorators) {
9426 const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
9427 return decl || super.parseExpressionStatement(node, expr, decorators);
9428 }
9429 shouldParseExportDeclaration() {
9430 if (this.tsIsDeclarationStart()) return true;
9431 return super.shouldParseExportDeclaration();
9432 }
9433 parseConditional(expr, startLoc, refExpressionErrors) {
9434 if (!this.state.maybeInArrowParameters || !this.match(17)) {
9435 return super.parseConditional(expr, startLoc, refExpressionErrors);
9436 }
9437 const result = this.tryParse(() => super.parseConditional(expr, startLoc));
9438 if (!result.node) {
9439 if (result.error) {
9440 super.setOptionalParametersError(refExpressionErrors, result.error);
9441 }
9442 return expr;
9443 }
9444 if (result.error) this.state = result.failState;
9445 return result.node;
9446 }
9447 parseParenItem(node, startLoc) {
9448 node = super.parseParenItem(node, startLoc);
9449 if (this.eat(17)) {
9450 node.optional = true;
9451 this.resetEndLocation(node);
9452 }
9453 if (this.match(14)) {
9454 const typeCastNode = this.startNodeAt(startLoc);
9455 typeCastNode.expression = node;
9456 typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
9457 return this.finishNode(typeCastNode, "TSTypeCastExpression");
9458 }
9459 return node;
9460 }
9461 parseExportDeclaration(node) {
9462 if (!this.state.isAmbientContext && this.isContextual(123)) {
9463 return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
9464 }
9465 const startLoc = this.state.startLoc;
9466 const isDeclare = this.eatContextual(123);
9467 if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
9468 throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
9469 at: this.state.startLoc
9470 });
9471 }
9472 const isIdentifier = tokenIsIdentifier(this.state.type);
9473 const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
9474 if (!declaration) return null;
9475 if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
9476 node.exportKind = "type";
9477 }
9478 if (isDeclare) {
9479 this.resetStartLocation(declaration, startLoc);
9480 declaration.declare = true;
9481 }
9482 return declaration;
9483 }
9484 parseClassId(node, isStatement, optionalId, bindingType) {
9485 if ((!isStatement || optionalId) && this.isContextual(111)) {
9486 return;
9487 }
9488 super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
9489 const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
9490 if (typeParameters) node.typeParameters = typeParameters;
9491 }
9492 parseClassPropertyAnnotation(node) {
9493 if (!node.optional) {
9494 if (this.eat(35)) {
9495 node.definite = true;
9496 } else if (this.eat(17)) {
9497 node.optional = true;
9498 }
9499 }
9500 const type = this.tsTryParseTypeAnnotation();
9501 if (type) node.typeAnnotation = type;
9502 }
9503 parseClassProperty(node) {
9504 this.parseClassPropertyAnnotation(node);
9505 if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
9506 this.raise(TSErrors.DeclareClassFieldHasInitializer, {
9507 at: this.state.startLoc
9508 });
9509 }
9510 if (node.abstract && this.match(29)) {
9511 const {
9512 key
9513 } = node;
9514 this.raise(TSErrors.AbstractPropertyHasInitializer, {
9515 at: this.state.startLoc,
9516 propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
9517 });
9518 }
9519 return super.parseClassProperty(node);
9520 }
9521 parseClassPrivateProperty(node) {
9522 if (node.abstract) {
9523 this.raise(TSErrors.PrivateElementHasAbstract, {
9524 at: node
9525 });
9526 }
9527 if (node.accessibility) {
9528 this.raise(TSErrors.PrivateElementHasAccessibility, {
9529 at: node,
9530 modifier: node.accessibility
9531 });
9532 }
9533 this.parseClassPropertyAnnotation(node);
9534 return super.parseClassPrivateProperty(node);
9535 }
9536 parseClassAccessorProperty(node) {
9537 this.parseClassPropertyAnnotation(node);
9538 if (node.optional) {
9539 this.raise(TSErrors.AccessorCannotBeOptional, {
9540 at: node
9541 });
9542 }
9543 return super.parseClassAccessorProperty(node);
9544 }
9545 pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
9546 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9547 if (typeParameters && isConstructor) {
9548 this.raise(TSErrors.ConstructorHasTypeParameters, {
9549 at: typeParameters
9550 });
9551 }
9552 const {
9553 declare = false,
9554 kind
9555 } = method;
9556 if (declare && (kind === "get" || kind === "set")) {
9557 this.raise(TSErrors.DeclareAccessor, {
9558 at: method,
9559 kind
9560 });
9561 }
9562 if (typeParameters) method.typeParameters = typeParameters;
9563 super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
9564 }
9565 pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
9566 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9567 if (typeParameters) method.typeParameters = typeParameters;
9568 super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
9569 }
9570 declareClassPrivateMethodInScope(node, kind) {
9571 if (node.type === "TSDeclareMethod") return;
9572 if (node.type === "MethodDefinition" && !node.value.body) return;
9573 super.declareClassPrivateMethodInScope(node, kind);
9574 }
9575 parseClassSuper(node) {
9576 super.parseClassSuper(node);
9577 if (node.superClass && (this.match(47) || this.match(51))) {
9578 node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
9579 }
9580 if (this.eatContextual(111)) {
9581 node.implements = this.tsParseHeritageClause("implements");
9582 }
9583 }
9584 parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
9585 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9586 if (typeParameters) prop.typeParameters = typeParameters;
9587 return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
9588 }
9589 parseFunctionParams(node, isConstructor) {
9590 const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9591 if (typeParameters) node.typeParameters = typeParameters;
9592 super.parseFunctionParams(node, isConstructor);
9593 }
9594 parseVarId(decl, kind) {
9595 super.parseVarId(decl, kind);
9596 if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
9597 decl.definite = true;
9598 }
9599 const type = this.tsTryParseTypeAnnotation();
9600 if (type) {
9601 decl.id.typeAnnotation = type;
9602 this.resetEndLocation(decl.id);
9603 }
9604 }
9605 parseAsyncArrowFromCallExpression(node, call) {
9606 if (this.match(14)) {
9607 node.returnType = this.tsParseTypeAnnotation();
9608 }
9609 return super.parseAsyncArrowFromCallExpression(node, call);
9610 }
9611 parseMaybeAssign(refExpressionErrors, afterLeftParse) {
9612 var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
9613 let state;
9614 let jsx;
9615 let typeCast;
9616 if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
9617 state = this.state.clone();
9618 jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9619 if (!jsx.error) return jsx.node;
9620 const {
9621 context
9622 } = this.state;
9623 const currentContext = context[context.length - 1];
9624 if (currentContext === types.j_oTag || currentContext === types.j_expr) {
9625 context.pop();
9626 }
9627 }
9628 if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
9629 return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9630 }
9631 if (!state || state === this.state) state = this.state.clone();
9632 let typeParameters;
9633 const arrow = this.tryParse(abort => {
9634 var _expr$extra, _typeParameters;
9635 typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
9636 const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9637 if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
9638 abort();
9639 }
9640 if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
9641 this.resetStartLocationFromNode(expr, typeParameters);
9642 }
9643 expr.typeParameters = typeParameters;
9644 return expr;
9645 }, state);
9646 if (!arrow.error && !arrow.aborted) {
9647 if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9648 return arrow.node;
9649 }
9650 if (!jsx) {
9651 assert(!this.hasPlugin("jsx"));
9652 typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9653 if (!typeCast.error) return typeCast.node;
9654 }
9655 if ((_jsx2 = jsx) != null && _jsx2.node) {
9656 this.state = jsx.failState;
9657 return jsx.node;
9658 }
9659 if (arrow.node) {
9660 this.state = arrow.failState;
9661 if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9662 return arrow.node;
9663 }
9664 if ((_typeCast = typeCast) != null && _typeCast.node) {
9665 this.state = typeCast.failState;
9666 return typeCast.node;
9667 }
9668 throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
9669 }
9670 reportReservedArrowTypeParam(node) {
9671 var _node$extra;
9672 if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
9673 this.raise(TSErrors.ReservedArrowTypeParam, {
9674 at: node
9675 });
9676 }
9677 }
9678 parseMaybeUnary(refExpressionErrors, sawUnary) {
9679 if (!this.hasPlugin("jsx") && this.match(47)) {
9680 return this.tsParseTypeAssertion();
9681 }
9682 return super.parseMaybeUnary(refExpressionErrors, sawUnary);
9683 }
9684 parseArrow(node) {
9685 if (this.match(14)) {
9686 const result = this.tryParse(abort => {
9687 const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
9688 if (this.canInsertSemicolon() || !this.match(19)) abort();
9689 return returnType;
9690 });
9691 if (result.aborted) return;
9692 if (!result.thrown) {
9693 if (result.error) this.state = result.failState;
9694 node.returnType = result.node;
9695 }
9696 }
9697 return super.parseArrow(node);
9698 }
9699 parseAssignableListItemTypes(param, flags) {
9700 if (!(flags & 2)) return param;
9701 if (this.eat(17)) {
9702 param.optional = true;
9703 }
9704 const type = this.tsTryParseTypeAnnotation();
9705 if (type) param.typeAnnotation = type;
9706 this.resetEndLocation(param);
9707 return param;
9708 }
9709 isAssignable(node, isBinding) {
9710 switch (node.type) {
9711 case "TSTypeCastExpression":
9712 return this.isAssignable(node.expression, isBinding);
9713 case "TSParameterProperty":
9714 return true;
9715 default:
9716 return super.isAssignable(node, isBinding);
9717 }
9718 }
9719 toAssignable(node, isLHS = false) {
9720 switch (node.type) {
9721 case "ParenthesizedExpression":
9722 this.toAssignableParenthesizedExpression(node, isLHS);
9723 break;
9724 case "TSAsExpression":
9725 case "TSSatisfiesExpression":
9726 case "TSNonNullExpression":
9727 case "TSTypeAssertion":
9728 if (isLHS) {
9729 this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
9730 at: node
9731 });
9732 } else {
9733 this.raise(TSErrors.UnexpectedTypeCastInParameter, {
9734 at: node
9735 });
9736 }
9737 this.toAssignable(node.expression, isLHS);
9738 break;
9739 case "AssignmentExpression":
9740 if (!isLHS && node.left.type === "TSTypeCastExpression") {
9741 node.left = this.typeCastToParameter(node.left);
9742 }
9743 default:
9744 super.toAssignable(node, isLHS);
9745 }
9746 }
9747 toAssignableParenthesizedExpression(node, isLHS) {
9748 switch (node.expression.type) {
9749 case "TSAsExpression":
9750 case "TSSatisfiesExpression":
9751 case "TSNonNullExpression":
9752 case "TSTypeAssertion":
9753 case "ParenthesizedExpression":
9754 this.toAssignable(node.expression, isLHS);
9755 break;
9756 default:
9757 super.toAssignable(node, isLHS);
9758 }
9759 }
9760 checkToRestConversion(node, allowPattern) {
9761 switch (node.type) {
9762 case "TSAsExpression":
9763 case "TSSatisfiesExpression":
9764 case "TSTypeAssertion":
9765 case "TSNonNullExpression":
9766 this.checkToRestConversion(node.expression, false);
9767 break;
9768 default:
9769 super.checkToRestConversion(node, allowPattern);
9770 }
9771 }
9772 isValidLVal(type, isUnparenthesizedInAssign, binding) {
9773 return getOwn({
9774 TSTypeCastExpression: true,
9775 TSParameterProperty: "parameter",
9776 TSNonNullExpression: "expression",
9777 TSAsExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
9778 TSSatisfiesExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
9779 TSTypeAssertion: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true]
9780 }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
9781 }
9782 parseBindingAtom() {
9783 if (this.state.type === 78) {
9784 return this.parseIdentifier(true);
9785 }
9786 return super.parseBindingAtom();
9787 }
9788 parseMaybeDecoratorArguments(expr) {
9789 if (this.match(47) || this.match(51)) {
9790 const typeArguments = this.tsParseTypeArgumentsInExpression();
9791 if (this.match(10)) {
9792 const call = super.parseMaybeDecoratorArguments(expr);
9793 call.typeParameters = typeArguments;
9794 return call;
9795 }
9796 this.unexpected(null, 10);
9797 }
9798 return super.parseMaybeDecoratorArguments(expr);
9799 }
9800 checkCommaAfterRest(close) {
9801 if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
9802 this.next();
9803 return false;
9804 }
9805 return super.checkCommaAfterRest(close);
9806 }
9807 isClassMethod() {
9808 return this.match(47) || super.isClassMethod();
9809 }
9810 isClassProperty() {
9811 return this.match(35) || this.match(14) || super.isClassProperty();
9812 }
9813 parseMaybeDefault(startLoc, left) {
9814 const node = super.parseMaybeDefault(startLoc, left);
9815 if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
9816 this.raise(TSErrors.TypeAnnotationAfterAssign, {
9817 at: node.typeAnnotation
9818 });
9819 }
9820 return node;
9821 }
9822 getTokenFromCode(code) {
9823 if (this.state.inType) {
9824 if (code === 62) {
9825 this.finishOp(48, 1);
9826 return;
9827 }
9828 if (code === 60) {
9829 this.finishOp(47, 1);
9830 return;
9831 }
9832 }
9833 super.getTokenFromCode(code);
9834 }
9835 reScan_lt_gt() {
9836 const {
9837 type
9838 } = this.state;
9839 if (type === 47) {
9840 this.state.pos -= 1;
9841 this.readToken_lt();
9842 } else if (type === 48) {
9843 this.state.pos -= 1;
9844 this.readToken_gt();
9845 }
9846 }
9847 reScan_lt() {
9848 const {
9849 type
9850 } = this.state;
9851 if (type === 51) {
9852 this.state.pos -= 2;
9853 this.finishOp(47, 1);
9854 return 47;
9855 }
9856 return type;
9857 }
9858 toAssignableList(exprList, trailingCommaLoc, isLHS) {
9859 for (let i = 0; i < exprList.length; i++) {
9860 const expr = exprList[i];
9861 if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
9862 exprList[i] = this.typeCastToParameter(expr);
9863 }
9864 }
9865 super.toAssignableList(exprList, trailingCommaLoc, isLHS);
9866 }
9867 typeCastToParameter(node) {
9868 node.expression.typeAnnotation = node.typeAnnotation;
9869 this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
9870 return node.expression;
9871 }
9872 shouldParseArrow(params) {
9873 if (this.match(14)) {
9874 return params.every(expr => this.isAssignable(expr, true));
9875 }
9876 return super.shouldParseArrow(params);
9877 }
9878 shouldParseAsyncArrow() {
9879 return this.match(14) || super.shouldParseAsyncArrow();
9880 }
9881 canHaveLeadingDecorator() {
9882 return super.canHaveLeadingDecorator() || this.isAbstractClass();
9883 }
9884 jsxParseOpeningElementAfterName(node) {
9885 if (this.match(47) || this.match(51)) {
9886 const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
9887 if (typeArguments) node.typeParameters = typeArguments;
9888 }
9889 return super.jsxParseOpeningElementAfterName(node);
9890 }
9891 getGetterSetterExpectedParamCount(method) {
9892 const baseCount = super.getGetterSetterExpectedParamCount(method);
9893 const params = this.getObjectOrClassMethodParams(method);
9894 const firstParam = params[0];
9895 const hasContextParam = firstParam && this.isThisParam(firstParam);
9896 return hasContextParam ? baseCount + 1 : baseCount;
9897 }
9898 parseCatchClauseParam() {
9899 const param = super.parseCatchClauseParam();
9900 const type = this.tsTryParseTypeAnnotation();
9901 if (type) {
9902 param.typeAnnotation = type;
9903 this.resetEndLocation(param);
9904 }
9905 return param;
9906 }
9907 tsInAmbientContext(cb) {
9908 const oldIsAmbientContext = this.state.isAmbientContext;
9909 this.state.isAmbientContext = true;
9910 try {
9911 return cb();
9912 } finally {
9913 this.state.isAmbientContext = oldIsAmbientContext;
9914 }
9915 }
9916 parseClass(node, isStatement, optionalId) {
9917 const oldInAbstractClass = this.state.inAbstractClass;
9918 this.state.inAbstractClass = !!node.abstract;
9919 try {
9920 return super.parseClass(node, isStatement, optionalId);
9921 } finally {
9922 this.state.inAbstractClass = oldInAbstractClass;
9923 }
9924 }
9925 tsParseAbstractDeclaration(node, decorators) {
9926 if (this.match(80)) {
9927 node.abstract = true;
9928 return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
9929 } else if (this.isContextual(127)) {
9930 if (!this.hasFollowingLineBreak()) {
9931 node.abstract = true;
9932 this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
9933 at: node
9934 });
9935 return this.tsParseInterfaceDeclaration(node);
9936 }
9937 } else {
9938 this.unexpected(null, 80);
9939 }
9940 }
9941 parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
9942 const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
9943 if (method.abstract) {
9944 const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
9945 if (hasBody) {
9946 const {
9947 key
9948 } = method;
9949 this.raise(TSErrors.AbstractMethodHasImplementation, {
9950 at: method,
9951 methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
9952 });
9953 }
9954 }
9955 return method;
9956 }
9957 tsParseTypeParameterName() {
9958 const typeName = this.parseIdentifier();
9959 return typeName.name;
9960 }
9961 shouldParseAsAmbientContext() {
9962 return !!this.getPluginOption("typescript", "dts");
9963 }
9964 parse() {
9965 if (this.shouldParseAsAmbientContext()) {
9966 this.state.isAmbientContext = true;
9967 }
9968 return super.parse();
9969 }
9970 getExpression() {
9971 if (this.shouldParseAsAmbientContext()) {
9972 this.state.isAmbientContext = true;
9973 }
9974 return super.getExpression();
9975 }
9976 parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
9977 if (!isString && isMaybeTypeOnly) {
9978 this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
9979 return this.finishNode(node, "ExportSpecifier");
9980 }
9981 node.exportKind = "value";
9982 return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
9983 }
9984 parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
9985 if (!importedIsString && isMaybeTypeOnly) {
9986 this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
9987 return this.finishNode(specifier, "ImportSpecifier");
9988 }
9989 specifier.importKind = "value";
9990 return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
9991 }
9992 parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
9993 const leftOfAsKey = isImport ? "imported" : "local";
9994 const rightOfAsKey = isImport ? "local" : "exported";
9995 let leftOfAs = node[leftOfAsKey];
9996 let rightOfAs;
9997 let hasTypeSpecifier = false;
9998 let canParseAsKeyword = true;
9999 const loc = leftOfAs.loc.start;
10000 if (this.isContextual(93)) {
10001 const firstAs = this.parseIdentifier();
10002 if (this.isContextual(93)) {
10003 const secondAs = this.parseIdentifier();
10004 if (tokenIsKeywordOrIdentifier(this.state.type)) {
10005 hasTypeSpecifier = true;
10006 leftOfAs = firstAs;
10007 rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10008 canParseAsKeyword = false;
10009 } else {
10010 rightOfAs = secondAs;
10011 canParseAsKeyword = false;
10012 }
10013 } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
10014 canParseAsKeyword = false;
10015 rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10016 } else {
10017 hasTypeSpecifier = true;
10018 leftOfAs = firstAs;
10019 }
10020 } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
10021 hasTypeSpecifier = true;
10022 if (isImport) {
10023 leftOfAs = this.parseIdentifier(true);
10024 if (!this.isContextual(93)) {
10025 this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
10026 }
10027 } else {
10028 leftOfAs = this.parseModuleExportName();
10029 }
10030 }
10031 if (hasTypeSpecifier && isInTypeOnlyImportExport) {
10032 this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
10033 at: loc
10034 });
10035 }
10036 node[leftOfAsKey] = leftOfAs;
10037 node[rightOfAsKey] = rightOfAs;
10038 const kindKey = isImport ? "importKind" : "exportKind";
10039 node[kindKey] = hasTypeSpecifier ? "type" : "value";
10040 if (canParseAsKeyword && this.eatContextual(93)) {
10041 node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10042 }
10043 if (!node[rightOfAsKey]) {
10044 node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
10045 }
10046 if (isImport) {
10047 this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
10048 }
10049 }
10050};
10051function isPossiblyLiteralEnum(expression) {
10052 if (expression.type !== "MemberExpression") return false;
10053 const {
10054 computed,
10055 property
10056 } = expression;
10057 if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
10058 return false;
10059 }
10060 return isUncomputedMemberExpressionChain(expression.object);
10061}
10062function isValidAmbientConstInitializer(expression, estree) {
10063 var _expression$extra;
10064 const {
10065 type
10066 } = expression;
10067 if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
10068 return false;
10069 }
10070 if (estree) {
10071 if (type === "Literal") {
10072 const {
10073 value
10074 } = expression;
10075 if (typeof value === "string" || typeof value === "boolean") {
10076 return true;
10077 }
10078 }
10079 } else {
10080 if (type === "StringLiteral" || type === "BooleanLiteral") {
10081 return true;
10082 }
10083 }
10084 if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
10085 return true;
10086 }
10087 if (type === "TemplateLiteral" && expression.expressions.length === 0) {
10088 return true;
10089 }
10090 if (isPossiblyLiteralEnum(expression)) {
10091 return true;
10092 }
10093 return false;
10094}
10095function isNumber(expression, estree) {
10096 if (estree) {
10097 return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
10098 }
10099 return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
10100}
10101function isNegativeNumber(expression, estree) {
10102 if (expression.type === "UnaryExpression") {
10103 const {
10104 operator,
10105 argument
10106 } = expression;
10107 if (operator === "-" && isNumber(argument, estree)) {
10108 return true;
10109 }
10110 }
10111 return false;
10112}
10113function isUncomputedMemberExpressionChain(expression) {
10114 if (expression.type === "Identifier") return true;
10115 if (expression.type !== "MemberExpression" || expression.computed) {
10116 return false;
10117 }
10118 return isUncomputedMemberExpressionChain(expression.object);
10119}
10120const PlaceholderErrors = ParseErrorEnum`placeholders`({
10121 ClassNameIsRequired: "A class name is required.",
10122 UnexpectedSpace: "Unexpected space in placeholder."
10123});
10124var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
10125 parsePlaceholder(expectedNode) {
10126 if (this.match(142)) {
10127 const node = this.startNode();
10128 this.next();
10129 this.assertNoSpace();
10130 node.name = super.parseIdentifier(true);
10131 this.assertNoSpace();
10132 this.expect(142);
10133 return this.finishPlaceholder(node, expectedNode);
10134 }
10135 }
10136 finishPlaceholder(node, expectedNode) {
10137 const isFinished = !!(node.expectedNode && node.type === "Placeholder");
10138 node.expectedNode = expectedNode;
10139 return isFinished ? node : this.finishNode(node, "Placeholder");
10140 }
10141 getTokenFromCode(code) {
10142 if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
10143 this.finishOp(142, 2);
10144 } else {
10145 super.getTokenFromCode(code);
10146 }
10147 }
10148 parseExprAtom(refExpressionErrors) {
10149 return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
10150 }
10151 parseIdentifier(liberal) {
10152 return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
10153 }
10154 checkReservedWord(word, startLoc, checkKeywords, isBinding) {
10155 if (word !== undefined) {
10156 super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
10157 }
10158 }
10159 parseBindingAtom() {
10160 return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
10161 }
10162 isValidLVal(type, isParenthesized, binding) {
10163 return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
10164 }
10165 toAssignable(node, isLHS) {
10166 if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
10167 node.expectedNode = "Pattern";
10168 } else {
10169 super.toAssignable(node, isLHS);
10170 }
10171 }
10172 chStartsBindingIdentifier(ch, pos) {
10173 if (super.chStartsBindingIdentifier(ch, pos)) {
10174 return true;
10175 }
10176 const nextToken = this.lookahead();
10177 if (nextToken.type === 142) {
10178 return true;
10179 }
10180 return false;
10181 }
10182 verifyBreakContinue(node, isBreak) {
10183 if (node.label && node.label.type === "Placeholder") return;
10184 super.verifyBreakContinue(node, isBreak);
10185 }
10186 parseExpressionStatement(node, expr) {
10187 var _expr$extra;
10188 if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
10189 return super.parseExpressionStatement(node, expr);
10190 }
10191 if (this.match(14)) {
10192 const stmt = node;
10193 stmt.label = this.finishPlaceholder(expr, "Identifier");
10194 this.next();
10195 stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
10196 return this.finishNode(stmt, "LabeledStatement");
10197 }
10198 this.semicolon();
10199 node.name = expr.name;
10200 return this.finishPlaceholder(node, "Statement");
10201 }
10202 parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
10203 return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
10204 }
10205 parseFunctionId(requireId) {
10206 return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
10207 }
10208 parseClass(node, isStatement, optionalId) {
10209 const type = isStatement ? "ClassDeclaration" : "ClassExpression";
10210 this.next();
10211 const oldStrict = this.state.strict;
10212 const placeholder = this.parsePlaceholder("Identifier");
10213 if (placeholder) {
10214 if (this.match(81) || this.match(142) || this.match(5)) {
10215 node.id = placeholder;
10216 } else if (optionalId || !isStatement) {
10217 node.id = null;
10218 node.body = this.finishPlaceholder(placeholder, "ClassBody");
10219 return this.finishNode(node, type);
10220 } else {
10221 throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
10222 at: this.state.startLoc
10223 });
10224 }
10225 } else {
10226 this.parseClassId(node, isStatement, optionalId);
10227 }
10228 super.parseClassSuper(node);
10229 node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
10230 return this.finishNode(node, type);
10231 }
10232 parseExport(node, decorators) {
10233 const placeholder = this.parsePlaceholder("Identifier");
10234 if (!placeholder) return super.parseExport(node, decorators);
10235 if (!this.isContextual(97) && !this.match(12)) {
10236 node.specifiers = [];
10237 node.source = null;
10238 node.declaration = this.finishPlaceholder(placeholder, "Declaration");
10239 return this.finishNode(node, "ExportNamedDeclaration");
10240 }
10241 this.expectPlugin("exportDefaultFrom");
10242 const specifier = this.startNode();
10243 specifier.exported = placeholder;
10244 node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
10245 return super.parseExport(node, decorators);
10246 }
10247 isExportDefaultSpecifier() {
10248 if (this.match(65)) {
10249 const next = this.nextTokenStart();
10250 if (this.isUnparsedContextual(next, "from")) {
10251 if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
10252 return true;
10253 }
10254 }
10255 }
10256 return super.isExportDefaultSpecifier();
10257 }
10258 maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
10259 var _specifiers;
10260 if ((_specifiers = node.specifiers) != null && _specifiers.length) {
10261 return true;
10262 }
10263 return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
10264 }
10265 checkExport(node) {
10266 const {
10267 specifiers
10268 } = node;
10269 if (specifiers != null && specifiers.length) {
10270 node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
10271 }
10272 super.checkExport(node);
10273 node.specifiers = specifiers;
10274 }
10275 parseImport(node) {
10276 const placeholder = this.parsePlaceholder("Identifier");
10277 if (!placeholder) return super.parseImport(node);
10278 node.specifiers = [];
10279 if (!this.isContextual(97) && !this.match(12)) {
10280 node.source = this.finishPlaceholder(placeholder, "StringLiteral");
10281 this.semicolon();
10282 return this.finishNode(node, "ImportDeclaration");
10283 }
10284 const specifier = this.startNodeAtNode(placeholder);
10285 specifier.local = placeholder;
10286 node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
10287 if (this.eat(12)) {
10288 const hasStarImport = this.maybeParseStarImportSpecifier(node);
10289 if (!hasStarImport) this.parseNamedImportSpecifiers(node);
10290 }
10291 this.expectContextual(97);
10292 node.source = this.parseImportSource();
10293 this.semicolon();
10294 return this.finishNode(node, "ImportDeclaration");
10295 }
10296 parseImportSource() {
10297 return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
10298 }
10299 assertNoSpace() {
10300 if (this.state.start > this.state.lastTokEndLoc.index) {
10301 this.raise(PlaceholderErrors.UnexpectedSpace, {
10302 at: this.state.lastTokEndLoc
10303 });
10304 }
10305 }
10306};
10307var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
10308 parseV8Intrinsic() {
10309 if (this.match(54)) {
10310 const v8IntrinsicStartLoc = this.state.startLoc;
10311 const node = this.startNode();
10312 this.next();
10313 if (tokenIsIdentifier(this.state.type)) {
10314 const name = this.parseIdentifierName();
10315 const identifier = this.createIdentifier(node, name);
10316 identifier.type = "V8IntrinsicIdentifier";
10317 if (this.match(10)) {
10318 return identifier;
10319 }
10320 }
10321 this.unexpected(v8IntrinsicStartLoc);
10322 }
10323 }
10324 parseExprAtom(refExpressionErrors) {
10325 return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
10326 }
10327};
10328function hasPlugin(plugins, expectedConfig) {
10329 const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
10330 const expectedKeys = Object.keys(expectedOptions);
10331 const expectedOptionsIsEmpty = expectedKeys.length === 0;
10332 return plugins.some(p => {
10333 if (typeof p === "string") {
10334 return expectedOptionsIsEmpty && p === expectedName;
10335 } else {
10336 const [pluginName, pluginOptions] = p;
10337 if (pluginName !== expectedName) {
10338 return false;
10339 }
10340 for (const key of expectedKeys) {
10341 if (pluginOptions[key] !== expectedOptions[key]) {
10342 return false;
10343 }
10344 }
10345 return true;
10346 }
10347 });
10348}
10349function getPluginOption(plugins, name, option) {
10350 const plugin = plugins.find(plugin => {
10351 if (Array.isArray(plugin)) {
10352 return plugin[0] === name;
10353 } else {
10354 return plugin === name;
10355 }
10356 });
10357 if (plugin && Array.isArray(plugin) && plugin.length > 1) {
10358 return plugin[1][option];
10359 }
10360 return null;
10361}
10362const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
10363const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
10364const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
10365function validatePlugins(plugins) {
10366 if (hasPlugin(plugins, "decorators")) {
10367 if (hasPlugin(plugins, "decorators-legacy")) {
10368 throw new Error("Cannot use the decorators and decorators-legacy plugin together");
10369 }
10370 const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
10371 if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
10372 throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
10373 }
10374 const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
10375 if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
10376 throw new Error("'allowCallParenthesized' must be a boolean.");
10377 }
10378 }
10379 if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
10380 throw new Error("Cannot combine flow and typescript plugins.");
10381 }
10382 if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
10383 throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
10384 }
10385 if (hasPlugin(plugins, "pipelineOperator")) {
10386 const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
10387 if (!PIPELINE_PROPOSALS.includes(proposal)) {
10388 const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
10389 throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
10390 }
10391 const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
10392 syntaxType: "hash"
10393 }]);
10394 if (proposal === "hack") {
10395 if (hasPlugin(plugins, "placeholders")) {
10396 throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
10397 }
10398 if (hasPlugin(plugins, "v8intrinsic")) {
10399 throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
10400 }
10401 const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
10402 if (!TOPIC_TOKENS.includes(topicToken)) {
10403 const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
10404 throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
10405 }
10406 if (topicToken === "#" && tupleSyntaxIsHash) {
10407 throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
10408 }
10409 } else if (proposal === "smart" && tupleSyntaxIsHash) {
10410 throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
10411 }
10412 }
10413 if (hasPlugin(plugins, "moduleAttributes")) {
10414 {
10415 if (hasPlugin(plugins, "importAssertions") || hasPlugin(plugins, "importAttributes")) {
10416 throw new Error("Cannot combine importAssertions, importAttributes and moduleAttributes plugins.");
10417 }
10418 const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
10419 if (moduleAttributesVersionPluginOption !== "may-2020") {
10420 throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
10421 }
10422 }
10423 }
10424 if (hasPlugin(plugins, "importAssertions") && hasPlugin(plugins, "importAttributes")) {
10425 throw new Error("Cannot combine importAssertions and importAttributes plugins.");
10426 }
10427 if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
10428 throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
10429 }
10430 if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
10431 const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
10432 error.missingPlugins = "doExpressions";
10433 throw error;
10434 }
10435}
10436const mixinPlugins = {
10437 estree,
10438 jsx,
10439 flow,
10440 typescript,
10441 v8intrinsic,
10442 placeholders
10443};
10444const mixinPluginNames = Object.keys(mixinPlugins);
10445const defaultOptions = {
10446 sourceType: "script",
10447 sourceFilename: undefined,
10448 startColumn: 0,
10449 startLine: 1,
10450 allowAwaitOutsideFunction: false,
10451 allowReturnOutsideFunction: false,
10452 allowNewTargetOutsideFunction: false,
10453 allowImportExportEverywhere: false,
10454 allowSuperOutsideMethod: false,
10455 allowUndeclaredExports: false,
10456 plugins: [],
10457 strictMode: null,
10458 ranges: false,
10459 tokens: false,
10460 createParenthesizedExpressions: false,
10461 errorRecovery: false,
10462 attachComment: true,
10463 annexB: true
10464};
10465function getOptions(opts) {
10466 if (opts == null) {
10467 return Object.assign({}, defaultOptions);
10468 }
10469 if (opts.annexB != null && opts.annexB !== false) {
10470 throw new Error("The `annexB` option can only be set to `false`.");
10471 }
10472 const options = {};
10473 for (const key of Object.keys(defaultOptions)) {
10474 var _opts$key;
10475 options[key] = (_opts$key = opts[key]) != null ? _opts$key : defaultOptions[key];
10476 }
10477 return options;
10478}
10479class ExpressionParser extends LValParser {
10480 checkProto(prop, isRecord, protoRef, refExpressionErrors) {
10481 if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
10482 return;
10483 }
10484 const key = prop.key;
10485 const name = key.type === "Identifier" ? key.name : key.value;
10486 if (name === "__proto__") {
10487 if (isRecord) {
10488 this.raise(Errors.RecordNoProto, {
10489 at: key
10490 });
10491 return;
10492 }
10493 if (protoRef.used) {
10494 if (refExpressionErrors) {
10495 if (refExpressionErrors.doubleProtoLoc === null) {
10496 refExpressionErrors.doubleProtoLoc = key.loc.start;
10497 }
10498 } else {
10499 this.raise(Errors.DuplicateProto, {
10500 at: key
10501 });
10502 }
10503 }
10504 protoRef.used = true;
10505 }
10506 }
10507 shouldExitDescending(expr, potentialArrowAt) {
10508 return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
10509 }
10510 getExpression() {
10511 this.enterInitialScopes();
10512 this.nextToken();
10513 const expr = this.parseExpression();
10514 if (!this.match(137)) {
10515 this.unexpected();
10516 }
10517 this.finalizeRemainingComments();
10518 expr.comments = this.state.comments;
10519 expr.errors = this.state.errors;
10520 if (this.options.tokens) {
10521 expr.tokens = this.tokens;
10522 }
10523 return expr;
10524 }
10525 parseExpression(disallowIn, refExpressionErrors) {
10526 if (disallowIn) {
10527 return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
10528 }
10529 return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
10530 }
10531 parseExpressionBase(refExpressionErrors) {
10532 const startLoc = this.state.startLoc;
10533 const expr = this.parseMaybeAssign(refExpressionErrors);
10534 if (this.match(12)) {
10535 const node = this.startNodeAt(startLoc);
10536 node.expressions = [expr];
10537 while (this.eat(12)) {
10538 node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
10539 }
10540 this.toReferencedList(node.expressions);
10541 return this.finishNode(node, "SequenceExpression");
10542 }
10543 return expr;
10544 }
10545 parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
10546 return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
10547 }
10548 parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
10549 return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
10550 }
10551 setOptionalParametersError(refExpressionErrors, resultError) {
10552 var _resultError$loc;
10553 refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
10554 }
10555 parseMaybeAssign(refExpressionErrors, afterLeftParse) {
10556 const startLoc = this.state.startLoc;
10557 if (this.isContextual(106)) {
10558 if (this.prodParam.hasYield) {
10559 let left = this.parseYield();
10560 if (afterLeftParse) {
10561 left = afterLeftParse.call(this, left, startLoc);
10562 }
10563 return left;
10564 }
10565 }
10566 let ownExpressionErrors;
10567 if (refExpressionErrors) {
10568 ownExpressionErrors = false;
10569 } else {
10570 refExpressionErrors = new ExpressionErrors();
10571 ownExpressionErrors = true;
10572 }
10573 const {
10574 type
10575 } = this.state;
10576 if (type === 10 || tokenIsIdentifier(type)) {
10577 this.state.potentialArrowAt = this.state.start;
10578 }
10579 let left = this.parseMaybeConditional(refExpressionErrors);
10580 if (afterLeftParse) {
10581 left = afterLeftParse.call(this, left, startLoc);
10582 }
10583 if (tokenIsAssignment(this.state.type)) {
10584 const node = this.startNodeAt(startLoc);
10585 const operator = this.state.value;
10586 node.operator = operator;
10587 if (this.match(29)) {
10588 this.toAssignable(left, true);
10589 node.left = left;
10590 const startIndex = startLoc.index;
10591 if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
10592 refExpressionErrors.doubleProtoLoc = null;
10593 }
10594 if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
10595 refExpressionErrors.shorthandAssignLoc = null;
10596 }
10597 if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
10598 this.checkDestructuringPrivate(refExpressionErrors);
10599 refExpressionErrors.privateKeyLoc = null;
10600 }
10601 } else {
10602 node.left = left;
10603 }
10604 this.next();
10605 node.right = this.parseMaybeAssign();
10606 this.checkLVal(left, {
10607 in: this.finishNode(node, "AssignmentExpression")
10608 });
10609 return node;
10610 } else if (ownExpressionErrors) {
10611 this.checkExpressionErrors(refExpressionErrors, true);
10612 }
10613 return left;
10614 }
10615 parseMaybeConditional(refExpressionErrors) {
10616 const startLoc = this.state.startLoc;
10617 const potentialArrowAt = this.state.potentialArrowAt;
10618 const expr = this.parseExprOps(refExpressionErrors);
10619 if (this.shouldExitDescending(expr, potentialArrowAt)) {
10620 return expr;
10621 }
10622 return this.parseConditional(expr, startLoc, refExpressionErrors);
10623 }
10624 parseConditional(expr, startLoc, refExpressionErrors) {
10625 if (this.eat(17)) {
10626 const node = this.startNodeAt(startLoc);
10627 node.test = expr;
10628 node.consequent = this.parseMaybeAssignAllowIn();
10629 this.expect(14);
10630 node.alternate = this.parseMaybeAssign();
10631 return this.finishNode(node, "ConditionalExpression");
10632 }
10633 return expr;
10634 }
10635 parseMaybeUnaryOrPrivate(refExpressionErrors) {
10636 return this.match(136) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
10637 }
10638 parseExprOps(refExpressionErrors) {
10639 const startLoc = this.state.startLoc;
10640 const potentialArrowAt = this.state.potentialArrowAt;
10641 const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
10642 if (this.shouldExitDescending(expr, potentialArrowAt)) {
10643 return expr;
10644 }
10645 return this.parseExprOp(expr, startLoc, -1);
10646 }
10647 parseExprOp(left, leftStartLoc, minPrec) {
10648 if (this.isPrivateName(left)) {
10649 const value = this.getPrivateNameSV(left);
10650 if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
10651 this.raise(Errors.PrivateInExpectedIn, {
10652 at: left,
10653 identifierName: value
10654 });
10655 }
10656 this.classScope.usePrivateName(value, left.loc.start);
10657 }
10658 const op = this.state.type;
10659 if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
10660 let prec = tokenOperatorPrecedence(op);
10661 if (prec > minPrec) {
10662 if (op === 39) {
10663 this.expectPlugin("pipelineOperator");
10664 if (this.state.inFSharpPipelineDirectBody) {
10665 return left;
10666 }
10667 this.checkPipelineAtInfixOperator(left, leftStartLoc);
10668 }
10669 const node = this.startNodeAt(leftStartLoc);
10670 node.left = left;
10671 node.operator = this.state.value;
10672 const logical = op === 41 || op === 42;
10673 const coalesce = op === 40;
10674 if (coalesce) {
10675 prec = tokenOperatorPrecedence(42);
10676 }
10677 this.next();
10678 if (op === 39 && this.hasPlugin(["pipelineOperator", {
10679 proposal: "minimal"
10680 }])) {
10681 if (this.state.type === 96 && this.prodParam.hasAwait) {
10682 throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
10683 at: this.state.startLoc
10684 });
10685 }
10686 }
10687 node.right = this.parseExprOpRightExpr(op, prec);
10688 const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
10689 const nextOp = this.state.type;
10690 if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
10691 throw this.raise(Errors.MixingCoalesceWithLogical, {
10692 at: this.state.startLoc
10693 });
10694 }
10695 return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
10696 }
10697 }
10698 return left;
10699 }
10700 parseExprOpRightExpr(op, prec) {
10701 const startLoc = this.state.startLoc;
10702 switch (op) {
10703 case 39:
10704 switch (this.getPluginOption("pipelineOperator", "proposal")) {
10705 case "hack":
10706 return this.withTopicBindingContext(() => {
10707 return this.parseHackPipeBody();
10708 });
10709 case "smart":
10710 return this.withTopicBindingContext(() => {
10711 if (this.prodParam.hasYield && this.isContextual(106)) {
10712 throw this.raise(Errors.PipeBodyIsTighter, {
10713 at: this.state.startLoc
10714 });
10715 }
10716 return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
10717 });
10718 case "fsharp":
10719 return this.withSoloAwaitPermittingContext(() => {
10720 return this.parseFSharpPipelineBody(prec);
10721 });
10722 }
10723 default:
10724 return this.parseExprOpBaseRightExpr(op, prec);
10725 }
10726 }
10727 parseExprOpBaseRightExpr(op, prec) {
10728 const startLoc = this.state.startLoc;
10729 return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
10730 }
10731 parseHackPipeBody() {
10732 var _body$extra;
10733 const {
10734 startLoc
10735 } = this.state;
10736 const body = this.parseMaybeAssign();
10737 const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
10738 if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
10739 this.raise(Errors.PipeUnparenthesizedBody, {
10740 at: startLoc,
10741 type: body.type
10742 });
10743 }
10744 if (!this.topicReferenceWasUsedInCurrentContext()) {
10745 this.raise(Errors.PipeTopicUnused, {
10746 at: startLoc
10747 });
10748 }
10749 return body;
10750 }
10751 checkExponentialAfterUnary(node) {
10752 if (this.match(57)) {
10753 this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
10754 at: node.argument
10755 });
10756 }
10757 }
10758 parseMaybeUnary(refExpressionErrors, sawUnary) {
10759 const startLoc = this.state.startLoc;
10760 const isAwait = this.isContextual(96);
10761 if (isAwait && this.isAwaitAllowed()) {
10762 this.next();
10763 const expr = this.parseAwait(startLoc);
10764 if (!sawUnary) this.checkExponentialAfterUnary(expr);
10765 return expr;
10766 }
10767 const update = this.match(34);
10768 const node = this.startNode();
10769 if (tokenIsPrefix(this.state.type)) {
10770 node.operator = this.state.value;
10771 node.prefix = true;
10772 if (this.match(72)) {
10773 this.expectPlugin("throwExpressions");
10774 }
10775 const isDelete = this.match(89);
10776 this.next();
10777 node.argument = this.parseMaybeUnary(null, true);
10778 this.checkExpressionErrors(refExpressionErrors, true);
10779 if (this.state.strict && isDelete) {
10780 const arg = node.argument;
10781 if (arg.type === "Identifier") {
10782 this.raise(Errors.StrictDelete, {
10783 at: node
10784 });
10785 } else if (this.hasPropertyAsPrivateName(arg)) {
10786 this.raise(Errors.DeletePrivateField, {
10787 at: node
10788 });
10789 }
10790 }
10791 if (!update) {
10792 if (!sawUnary) {
10793 this.checkExponentialAfterUnary(node);
10794 }
10795 return this.finishNode(node, "UnaryExpression");
10796 }
10797 }
10798 const expr = this.parseUpdate(node, update, refExpressionErrors);
10799 if (isAwait) {
10800 const {
10801 type
10802 } = this.state;
10803 const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
10804 if (startsExpr && !this.isAmbiguousAwait()) {
10805 this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
10806 at: startLoc
10807 });
10808 return this.parseAwait(startLoc);
10809 }
10810 }
10811 return expr;
10812 }
10813 parseUpdate(node, update, refExpressionErrors) {
10814 if (update) {
10815 const updateExpressionNode = node;
10816 this.checkLVal(updateExpressionNode.argument, {
10817 in: this.finishNode(updateExpressionNode, "UpdateExpression")
10818 });
10819 return node;
10820 }
10821 const startLoc = this.state.startLoc;
10822 let expr = this.parseExprSubscripts(refExpressionErrors);
10823 if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
10824 while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
10825 const node = this.startNodeAt(startLoc);
10826 node.operator = this.state.value;
10827 node.prefix = false;
10828 node.argument = expr;
10829 this.next();
10830 this.checkLVal(expr, {
10831 in: expr = this.finishNode(node, "UpdateExpression")
10832 });
10833 }
10834 return expr;
10835 }
10836 parseExprSubscripts(refExpressionErrors) {
10837 const startLoc = this.state.startLoc;
10838 const potentialArrowAt = this.state.potentialArrowAt;
10839 const expr = this.parseExprAtom(refExpressionErrors);
10840 if (this.shouldExitDescending(expr, potentialArrowAt)) {
10841 return expr;
10842 }
10843 return this.parseSubscripts(expr, startLoc);
10844 }
10845 parseSubscripts(base, startLoc, noCalls) {
10846 const state = {
10847 optionalChainMember: false,
10848 maybeAsyncArrow: this.atPossibleAsyncArrow(base),
10849 stop: false
10850 };
10851 do {
10852 base = this.parseSubscript(base, startLoc, noCalls, state);
10853 state.maybeAsyncArrow = false;
10854 } while (!state.stop);
10855 return base;
10856 }
10857 parseSubscript(base, startLoc, noCalls, state) {
10858 const {
10859 type
10860 } = this.state;
10861 if (!noCalls && type === 15) {
10862 return this.parseBind(base, startLoc, noCalls, state);
10863 } else if (tokenIsTemplate(type)) {
10864 return this.parseTaggedTemplateExpression(base, startLoc, state);
10865 }
10866 let optional = false;
10867 if (type === 18) {
10868 if (noCalls) {
10869 this.raise(Errors.OptionalChainingNoNew, {
10870 at: this.state.startLoc
10871 });
10872 if (this.lookaheadCharCode() === 40) {
10873 state.stop = true;
10874 return base;
10875 }
10876 }
10877 state.optionalChainMember = optional = true;
10878 this.next();
10879 }
10880 if (!noCalls && this.match(10)) {
10881 return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
10882 } else {
10883 const computed = this.eat(0);
10884 if (computed || optional || this.eat(16)) {
10885 return this.parseMember(base, startLoc, state, computed, optional);
10886 } else {
10887 state.stop = true;
10888 return base;
10889 }
10890 }
10891 }
10892 parseMember(base, startLoc, state, computed, optional) {
10893 const node = this.startNodeAt(startLoc);
10894 node.object = base;
10895 node.computed = computed;
10896 if (computed) {
10897 node.property = this.parseExpression();
10898 this.expect(3);
10899 } else if (this.match(136)) {
10900 if (base.type === "Super") {
10901 this.raise(Errors.SuperPrivateField, {
10902 at: startLoc
10903 });
10904 }
10905 this.classScope.usePrivateName(this.state.value, this.state.startLoc);
10906 node.property = this.parsePrivateName();
10907 } else {
10908 node.property = this.parseIdentifier(true);
10909 }
10910 if (state.optionalChainMember) {
10911 node.optional = optional;
10912 return this.finishNode(node, "OptionalMemberExpression");
10913 } else {
10914 return this.finishNode(node, "MemberExpression");
10915 }
10916 }
10917 parseBind(base, startLoc, noCalls, state) {
10918 const node = this.startNodeAt(startLoc);
10919 node.object = base;
10920 this.next();
10921 node.callee = this.parseNoCallExpr();
10922 state.stop = true;
10923 return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
10924 }
10925 parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
10926 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
10927 let refExpressionErrors = null;
10928 this.state.maybeInArrowParameters = true;
10929 this.next();
10930 const node = this.startNodeAt(startLoc);
10931 node.callee = base;
10932 const {
10933 maybeAsyncArrow,
10934 optionalChainMember
10935 } = state;
10936 if (maybeAsyncArrow) {
10937 this.expressionScope.enter(newAsyncArrowScope());
10938 refExpressionErrors = new ExpressionErrors();
10939 }
10940 if (optionalChainMember) {
10941 node.optional = optional;
10942 }
10943 if (optional) {
10944 node.arguments = this.parseCallExpressionArguments(11);
10945 } else {
10946 node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
10947 }
10948 let finishedNode = this.finishCallExpression(node, optionalChainMember);
10949 if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
10950 state.stop = true;
10951 this.checkDestructuringPrivate(refExpressionErrors);
10952 this.expressionScope.validateAsPattern();
10953 this.expressionScope.exit();
10954 finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
10955 } else {
10956 if (maybeAsyncArrow) {
10957 this.checkExpressionErrors(refExpressionErrors, true);
10958 this.expressionScope.exit();
10959 }
10960 this.toReferencedArguments(finishedNode);
10961 }
10962 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
10963 return finishedNode;
10964 }
10965 toReferencedArguments(node, isParenthesizedExpr) {
10966 this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
10967 }
10968 parseTaggedTemplateExpression(base, startLoc, state) {
10969 const node = this.startNodeAt(startLoc);
10970 node.tag = base;
10971 node.quasi = this.parseTemplate(true);
10972 if (state.optionalChainMember) {
10973 this.raise(Errors.OptionalChainingNoTemplate, {
10974 at: startLoc
10975 });
10976 }
10977 return this.finishNode(node, "TaggedTemplateExpression");
10978 }
10979 atPossibleAsyncArrow(base) {
10980 return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
10981 }
10982 expectImportAttributesPlugin() {
10983 if (!this.hasPlugin("importAssertions")) {
10984 this.expectPlugin("importAttributes");
10985 }
10986 }
10987 finishCallExpression(node, optional) {
10988 if (node.callee.type === "Import") {
10989 if (node.arguments.length === 2) {
10990 {
10991 if (!this.hasPlugin("moduleAttributes")) {
10992 this.expectImportAttributesPlugin();
10993 }
10994 }
10995 }
10996 if (node.arguments.length === 0 || node.arguments.length > 2) {
10997 this.raise(Errors.ImportCallArity, {
10998 at: node,
10999 maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
11000 });
11001 } else {
11002 for (const arg of node.arguments) {
11003 if (arg.type === "SpreadElement") {
11004 this.raise(Errors.ImportCallSpreadArgument, {
11005 at: arg
11006 });
11007 }
11008 }
11009 }
11010 }
11011 return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
11012 }
11013 parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
11014 const elts = [];
11015 let first = true;
11016 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
11017 this.state.inFSharpPipelineDirectBody = false;
11018 while (!this.eat(close)) {
11019 if (first) {
11020 first = false;
11021 } else {
11022 this.expect(12);
11023 if (this.match(close)) {
11024 if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
11025 this.raise(Errors.ImportCallArgumentTrailingComma, {
11026 at: this.state.lastTokStartLoc
11027 });
11028 }
11029 if (nodeForExtra) {
11030 this.addTrailingCommaExtraToNode(nodeForExtra);
11031 }
11032 this.next();
11033 break;
11034 }
11035 }
11036 elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
11037 }
11038 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
11039 return elts;
11040 }
11041 shouldParseAsyncArrow() {
11042 return this.match(19) && !this.canInsertSemicolon();
11043 }
11044 parseAsyncArrowFromCallExpression(node, call) {
11045 var _call$extra;
11046 this.resetPreviousNodeTrailingComments(call);
11047 this.expect(19);
11048 this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
11049 if (call.innerComments) {
11050 setInnerComments(node, call.innerComments);
11051 }
11052 if (call.callee.trailingComments) {
11053 setInnerComments(node, call.callee.trailingComments);
11054 }
11055 return node;
11056 }
11057 parseNoCallExpr() {
11058 const startLoc = this.state.startLoc;
11059 return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
11060 }
11061 parseExprAtom(refExpressionErrors) {
11062 let node;
11063 let decorators = null;
11064 const {
11065 type
11066 } = this.state;
11067 switch (type) {
11068 case 79:
11069 return this.parseSuper();
11070 case 83:
11071 node = this.startNode();
11072 this.next();
11073 if (this.match(16)) {
11074 return this.parseImportMetaProperty(node);
11075 }
11076 if (!this.match(10)) {
11077 this.raise(Errors.UnsupportedImport, {
11078 at: this.state.lastTokStartLoc
11079 });
11080 }
11081 return this.finishNode(node, "Import");
11082 case 78:
11083 node = this.startNode();
11084 this.next();
11085 return this.finishNode(node, "ThisExpression");
11086 case 90:
11087 {
11088 return this.parseDo(this.startNode(), false);
11089 }
11090 case 56:
11091 case 31:
11092 {
11093 this.readRegexp();
11094 return this.parseRegExpLiteral(this.state.value);
11095 }
11096 case 132:
11097 return this.parseNumericLiteral(this.state.value);
11098 case 133:
11099 return this.parseBigIntLiteral(this.state.value);
11100 case 134:
11101 return this.parseDecimalLiteral(this.state.value);
11102 case 131:
11103 return this.parseStringLiteral(this.state.value);
11104 case 84:
11105 return this.parseNullLiteral();
11106 case 85:
11107 return this.parseBooleanLiteral(true);
11108 case 86:
11109 return this.parseBooleanLiteral(false);
11110 case 10:
11111 {
11112 const canBeArrow = this.state.potentialArrowAt === this.state.start;
11113 return this.parseParenAndDistinguishExpression(canBeArrow);
11114 }
11115 case 2:
11116 case 1:
11117 {
11118 return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
11119 }
11120 case 0:
11121 {
11122 return this.parseArrayLike(3, true, false, refExpressionErrors);
11123 }
11124 case 6:
11125 case 7:
11126 {
11127 return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
11128 }
11129 case 5:
11130 {
11131 return this.parseObjectLike(8, false, false, refExpressionErrors);
11132 }
11133 case 68:
11134 return this.parseFunctionOrFunctionSent();
11135 case 26:
11136 decorators = this.parseDecorators();
11137 case 80:
11138 return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
11139 case 77:
11140 return this.parseNewOrNewTarget();
11141 case 25:
11142 case 24:
11143 return this.parseTemplate(false);
11144 case 15:
11145 {
11146 node = this.startNode();
11147 this.next();
11148 node.object = null;
11149 const callee = node.callee = this.parseNoCallExpr();
11150 if (callee.type === "MemberExpression") {
11151 return this.finishNode(node, "BindExpression");
11152 } else {
11153 throw this.raise(Errors.UnsupportedBind, {
11154 at: callee
11155 });
11156 }
11157 }
11158 case 136:
11159 {
11160 this.raise(Errors.PrivateInExpectedIn, {
11161 at: this.state.startLoc,
11162 identifierName: this.state.value
11163 });
11164 return this.parsePrivateName();
11165 }
11166 case 33:
11167 {
11168 return this.parseTopicReferenceThenEqualsSign(54, "%");
11169 }
11170 case 32:
11171 {
11172 return this.parseTopicReferenceThenEqualsSign(44, "^");
11173 }
11174 case 37:
11175 case 38:
11176 {
11177 return this.parseTopicReference("hack");
11178 }
11179 case 44:
11180 case 54:
11181 case 27:
11182 {
11183 const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
11184 if (pipeProposal) {
11185 return this.parseTopicReference(pipeProposal);
11186 }
11187 this.unexpected();
11188 break;
11189 }
11190 case 47:
11191 {
11192 const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
11193 if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
11194 this.expectOnePlugin(["jsx", "flow", "typescript"]);
11195 } else {
11196 this.unexpected();
11197 }
11198 break;
11199 }
11200 default:
11201 if (tokenIsIdentifier(type)) {
11202 if (this.isContextual(125) && this.lookaheadInLineCharCode() === 123) {
11203 return this.parseModuleExpression();
11204 }
11205 const canBeArrow = this.state.potentialArrowAt === this.state.start;
11206 const containsEsc = this.state.containsEsc;
11207 const id = this.parseIdentifier();
11208 if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
11209 const {
11210 type
11211 } = this.state;
11212 if (type === 68) {
11213 this.resetPreviousNodeTrailingComments(id);
11214 this.next();
11215 return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
11216 } else if (tokenIsIdentifier(type)) {
11217 if (this.lookaheadCharCode() === 61) {
11218 return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
11219 } else {
11220 return id;
11221 }
11222 } else if (type === 90) {
11223 this.resetPreviousNodeTrailingComments(id);
11224 return this.parseDo(this.startNodeAtNode(id), true);
11225 }
11226 }
11227 if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
11228 this.next();
11229 return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
11230 }
11231 return id;
11232 } else {
11233 this.unexpected();
11234 }
11235 }
11236 }
11237 parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
11238 const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
11239 if (pipeProposal) {
11240 this.state.type = topicTokenType;
11241 this.state.value = topicTokenValue;
11242 this.state.pos--;
11243 this.state.end--;
11244 this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
11245 return this.parseTopicReference(pipeProposal);
11246 } else {
11247 this.unexpected();
11248 }
11249 }
11250 parseTopicReference(pipeProposal) {
11251 const node = this.startNode();
11252 const startLoc = this.state.startLoc;
11253 const tokenType = this.state.type;
11254 this.next();
11255 return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
11256 }
11257 finishTopicReference(node, startLoc, pipeProposal, tokenType) {
11258 if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
11259 const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
11260 if (!this.topicReferenceIsAllowedInCurrentContext()) {
11261 this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
11262 at: startLoc
11263 });
11264 }
11265 this.registerTopicReference();
11266 return this.finishNode(node, nodeType);
11267 } else {
11268 throw this.raise(Errors.PipeTopicUnconfiguredToken, {
11269 at: startLoc,
11270 token: tokenLabelName(tokenType)
11271 });
11272 }
11273 }
11274 testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
11275 switch (pipeProposal) {
11276 case "hack":
11277 {
11278 return this.hasPlugin(["pipelineOperator", {
11279 topicToken: tokenLabelName(tokenType)
11280 }]);
11281 }
11282 case "smart":
11283 return tokenType === 27;
11284 default:
11285 throw this.raise(Errors.PipeTopicRequiresHackPipes, {
11286 at: startLoc
11287 });
11288 }
11289 }
11290 parseAsyncArrowUnaryFunction(node) {
11291 this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
11292 const params = [this.parseIdentifier()];
11293 this.prodParam.exit();
11294 if (this.hasPrecedingLineBreak()) {
11295 this.raise(Errors.LineTerminatorBeforeArrow, {
11296 at: this.state.curPosition()
11297 });
11298 }
11299 this.expect(19);
11300 return this.parseArrowExpression(node, params, true);
11301 }
11302 parseDo(node, isAsync) {
11303 this.expectPlugin("doExpressions");
11304 if (isAsync) {
11305 this.expectPlugin("asyncDoExpressions");
11306 }
11307 node.async = isAsync;
11308 this.next();
11309 const oldLabels = this.state.labels;
11310 this.state.labels = [];
11311 if (isAsync) {
11312 this.prodParam.enter(PARAM_AWAIT);
11313 node.body = this.parseBlock();
11314 this.prodParam.exit();
11315 } else {
11316 node.body = this.parseBlock();
11317 }
11318 this.state.labels = oldLabels;
11319 return this.finishNode(node, "DoExpression");
11320 }
11321 parseSuper() {
11322 const node = this.startNode();
11323 this.next();
11324 if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
11325 this.raise(Errors.SuperNotAllowed, {
11326 at: node
11327 });
11328 } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
11329 this.raise(Errors.UnexpectedSuper, {
11330 at: node
11331 });
11332 }
11333 if (!this.match(10) && !this.match(0) && !this.match(16)) {
11334 this.raise(Errors.UnsupportedSuper, {
11335 at: node
11336 });
11337 }
11338 return this.finishNode(node, "Super");
11339 }
11340 parsePrivateName() {
11341 const node = this.startNode();
11342 const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
11343 const name = this.state.value;
11344 this.next();
11345 node.id = this.createIdentifier(id, name);
11346 return this.finishNode(node, "PrivateName");
11347 }
11348 parseFunctionOrFunctionSent() {
11349 const node = this.startNode();
11350 this.next();
11351 if (this.prodParam.hasYield && this.match(16)) {
11352 const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
11353 this.next();
11354 if (this.match(102)) {
11355 this.expectPlugin("functionSent");
11356 } else if (!this.hasPlugin("functionSent")) {
11357 this.unexpected();
11358 }
11359 return this.parseMetaProperty(node, meta, "sent");
11360 }
11361 return this.parseFunction(node);
11362 }
11363 parseMetaProperty(node, meta, propertyName) {
11364 node.meta = meta;
11365 const containsEsc = this.state.containsEsc;
11366 node.property = this.parseIdentifier(true);
11367 if (node.property.name !== propertyName || containsEsc) {
11368 this.raise(Errors.UnsupportedMetaProperty, {
11369 at: node.property,
11370 target: meta.name,
11371 onlyValidPropertyName: propertyName
11372 });
11373 }
11374 return this.finishNode(node, "MetaProperty");
11375 }
11376 parseImportMetaProperty(node) {
11377 const id = this.createIdentifier(this.startNodeAtNode(node), "import");
11378 this.next();
11379 if (this.isContextual(100)) {
11380 if (!this.inModule) {
11381 this.raise(Errors.ImportMetaOutsideModule, {
11382 at: id
11383 });
11384 }
11385 this.sawUnambiguousESM = true;
11386 }
11387 return this.parseMetaProperty(node, id, "meta");
11388 }
11389 parseLiteralAtNode(value, type, node) {
11390 this.addExtra(node, "rawValue", value);
11391 this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
11392 node.value = value;
11393 this.next();
11394 return this.finishNode(node, type);
11395 }
11396 parseLiteral(value, type) {
11397 const node = this.startNode();
11398 return this.parseLiteralAtNode(value, type, node);
11399 }
11400 parseStringLiteral(value) {
11401 return this.parseLiteral(value, "StringLiteral");
11402 }
11403 parseNumericLiteral(value) {
11404 return this.parseLiteral(value, "NumericLiteral");
11405 }
11406 parseBigIntLiteral(value) {
11407 return this.parseLiteral(value, "BigIntLiteral");
11408 }
11409 parseDecimalLiteral(value) {
11410 return this.parseLiteral(value, "DecimalLiteral");
11411 }
11412 parseRegExpLiteral(value) {
11413 const node = this.parseLiteral(value.value, "RegExpLiteral");
11414 node.pattern = value.pattern;
11415 node.flags = value.flags;
11416 return node;
11417 }
11418 parseBooleanLiteral(value) {
11419 const node = this.startNode();
11420 node.value = value;
11421 this.next();
11422 return this.finishNode(node, "BooleanLiteral");
11423 }
11424 parseNullLiteral() {
11425 const node = this.startNode();
11426 this.next();
11427 return this.finishNode(node, "NullLiteral");
11428 }
11429 parseParenAndDistinguishExpression(canBeArrow) {
11430 const startLoc = this.state.startLoc;
11431 let val;
11432 this.next();
11433 this.expressionScope.enter(newArrowHeadScope());
11434 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
11435 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
11436 this.state.maybeInArrowParameters = true;
11437 this.state.inFSharpPipelineDirectBody = false;
11438 const innerStartLoc = this.state.startLoc;
11439 const exprList = [];
11440 const refExpressionErrors = new ExpressionErrors();
11441 let first = true;
11442 let spreadStartLoc;
11443 let optionalCommaStartLoc;
11444 while (!this.match(11)) {
11445 if (first) {
11446 first = false;
11447 } else {
11448 this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
11449 if (this.match(11)) {
11450 optionalCommaStartLoc = this.state.startLoc;
11451 break;
11452 }
11453 }
11454 if (this.match(21)) {
11455 const spreadNodeStartLoc = this.state.startLoc;
11456 spreadStartLoc = this.state.startLoc;
11457 exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
11458 if (!this.checkCommaAfterRest(41)) {
11459 break;
11460 }
11461 } else {
11462 exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
11463 }
11464 }
11465 const innerEndLoc = this.state.lastTokEndLoc;
11466 this.expect(11);
11467 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
11468 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
11469 let arrowNode = this.startNodeAt(startLoc);
11470 if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
11471 this.checkDestructuringPrivate(refExpressionErrors);
11472 this.expressionScope.validateAsPattern();
11473 this.expressionScope.exit();
11474 this.parseArrowExpression(arrowNode, exprList, false);
11475 return arrowNode;
11476 }
11477 this.expressionScope.exit();
11478 if (!exprList.length) {
11479 this.unexpected(this.state.lastTokStartLoc);
11480 }
11481 if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
11482 if (spreadStartLoc) this.unexpected(spreadStartLoc);
11483 this.checkExpressionErrors(refExpressionErrors, true);
11484 this.toReferencedListDeep(exprList, true);
11485 if (exprList.length > 1) {
11486 val = this.startNodeAt(innerStartLoc);
11487 val.expressions = exprList;
11488 this.finishNode(val, "SequenceExpression");
11489 this.resetEndLocation(val, innerEndLoc);
11490 } else {
11491 val = exprList[0];
11492 }
11493 return this.wrapParenthesis(startLoc, val);
11494 }
11495 wrapParenthesis(startLoc, expression) {
11496 if (!this.options.createParenthesizedExpressions) {
11497 this.addExtra(expression, "parenthesized", true);
11498 this.addExtra(expression, "parenStart", startLoc.index);
11499 this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
11500 return expression;
11501 }
11502 const parenExpression = this.startNodeAt(startLoc);
11503 parenExpression.expression = expression;
11504 return this.finishNode(parenExpression, "ParenthesizedExpression");
11505 }
11506 shouldParseArrow(params) {
11507 return !this.canInsertSemicolon();
11508 }
11509 parseArrow(node) {
11510 if (this.eat(19)) {
11511 return node;
11512 }
11513 }
11514 parseParenItem(node, startLoc) {
11515 return node;
11516 }
11517 parseNewOrNewTarget() {
11518 const node = this.startNode();
11519 this.next();
11520 if (this.match(16)) {
11521 const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
11522 this.next();
11523 const metaProp = this.parseMetaProperty(node, meta, "target");
11524 if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
11525 this.raise(Errors.UnexpectedNewTarget, {
11526 at: metaProp
11527 });
11528 }
11529 return metaProp;
11530 }
11531 return this.parseNew(node);
11532 }
11533 parseNew(node) {
11534 this.parseNewCallee(node);
11535 if (this.eat(10)) {
11536 const args = this.parseExprList(11);
11537 this.toReferencedList(args);
11538 node.arguments = args;
11539 } else {
11540 node.arguments = [];
11541 }
11542 return this.finishNode(node, "NewExpression");
11543 }
11544 parseNewCallee(node) {
11545 node.callee = this.parseNoCallExpr();
11546 if (node.callee.type === "Import") {
11547 this.raise(Errors.ImportCallNotNewExpression, {
11548 at: node.callee
11549 });
11550 }
11551 }
11552 parseTemplateElement(isTagged) {
11553 const {
11554 start,
11555 startLoc,
11556 end,
11557 value
11558 } = this.state;
11559 const elemStart = start + 1;
11560 const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
11561 if (value === null) {
11562 if (!isTagged) {
11563 this.raise(Errors.InvalidEscapeSequenceTemplate, {
11564 at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
11565 });
11566 }
11567 }
11568 const isTail = this.match(24);
11569 const endOffset = isTail ? -1 : -2;
11570 const elemEnd = end + endOffset;
11571 elem.value = {
11572 raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
11573 cooked: value === null ? null : value.slice(1, endOffset)
11574 };
11575 elem.tail = isTail;
11576 this.next();
11577 const finishedNode = this.finishNode(elem, "TemplateElement");
11578 this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
11579 return finishedNode;
11580 }
11581 parseTemplate(isTagged) {
11582 const node = this.startNode();
11583 node.expressions = [];
11584 let curElt = this.parseTemplateElement(isTagged);
11585 node.quasis = [curElt];
11586 while (!curElt.tail) {
11587 node.expressions.push(this.parseTemplateSubstitution());
11588 this.readTemplateContinuation();
11589 node.quasis.push(curElt = this.parseTemplateElement(isTagged));
11590 }
11591 return this.finishNode(node, "TemplateLiteral");
11592 }
11593 parseTemplateSubstitution() {
11594 return this.parseExpression();
11595 }
11596 parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
11597 if (isRecord) {
11598 this.expectPlugin("recordAndTuple");
11599 }
11600 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
11601 this.state.inFSharpPipelineDirectBody = false;
11602 const propHash = Object.create(null);
11603 let first = true;
11604 const node = this.startNode();
11605 node.properties = [];
11606 this.next();
11607 while (!this.match(close)) {
11608 if (first) {
11609 first = false;
11610 } else {
11611 this.expect(12);
11612 if (this.match(close)) {
11613 this.addTrailingCommaExtraToNode(node);
11614 break;
11615 }
11616 }
11617 let prop;
11618 if (isPattern) {
11619 prop = this.parseBindingProperty();
11620 } else {
11621 prop = this.parsePropertyDefinition(refExpressionErrors);
11622 this.checkProto(prop, isRecord, propHash, refExpressionErrors);
11623 }
11624 if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
11625 this.raise(Errors.InvalidRecordProperty, {
11626 at: prop
11627 });
11628 }
11629 if (prop.shorthand) {
11630 this.addExtra(prop, "shorthand", true);
11631 }
11632 node.properties.push(prop);
11633 }
11634 this.next();
11635 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
11636 let type = "ObjectExpression";
11637 if (isPattern) {
11638 type = "ObjectPattern";
11639 } else if (isRecord) {
11640 type = "RecordExpression";
11641 }
11642 return this.finishNode(node, type);
11643 }
11644 addTrailingCommaExtraToNode(node) {
11645 this.addExtra(node, "trailingComma", this.state.lastTokStart);
11646 this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
11647 }
11648 maybeAsyncOrAccessorProp(prop) {
11649 return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
11650 }
11651 parsePropertyDefinition(refExpressionErrors) {
11652 let decorators = [];
11653 if (this.match(26)) {
11654 if (this.hasPlugin("decorators")) {
11655 this.raise(Errors.UnsupportedPropertyDecorator, {
11656 at: this.state.startLoc
11657 });
11658 }
11659 while (this.match(26)) {
11660 decorators.push(this.parseDecorator());
11661 }
11662 }
11663 const prop = this.startNode();
11664 let isAsync = false;
11665 let isAccessor = false;
11666 let startLoc;
11667 if (this.match(21)) {
11668 if (decorators.length) this.unexpected();
11669 return this.parseSpread();
11670 }
11671 if (decorators.length) {
11672 prop.decorators = decorators;
11673 decorators = [];
11674 }
11675 prop.method = false;
11676 if (refExpressionErrors) {
11677 startLoc = this.state.startLoc;
11678 }
11679 let isGenerator = this.eat(55);
11680 this.parsePropertyNamePrefixOperator(prop);
11681 const containsEsc = this.state.containsEsc;
11682 const key = this.parsePropertyName(prop, refExpressionErrors);
11683 if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
11684 const keyName = key.name;
11685 if (keyName === "async" && !this.hasPrecedingLineBreak()) {
11686 isAsync = true;
11687 this.resetPreviousNodeTrailingComments(key);
11688 isGenerator = this.eat(55);
11689 this.parsePropertyName(prop);
11690 }
11691 if (keyName === "get" || keyName === "set") {
11692 isAccessor = true;
11693 this.resetPreviousNodeTrailingComments(key);
11694 prop.kind = keyName;
11695 if (this.match(55)) {
11696 isGenerator = true;
11697 this.raise(Errors.AccessorIsGenerator, {
11698 at: this.state.curPosition(),
11699 kind: keyName
11700 });
11701 this.next();
11702 }
11703 this.parsePropertyName(prop);
11704 }
11705 }
11706 return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
11707 }
11708 getGetterSetterExpectedParamCount(method) {
11709 return method.kind === "get" ? 0 : 1;
11710 }
11711 getObjectOrClassMethodParams(method) {
11712 return method.params;
11713 }
11714 checkGetterSetterParams(method) {
11715 var _params;
11716 const paramCount = this.getGetterSetterExpectedParamCount(method);
11717 const params = this.getObjectOrClassMethodParams(method);
11718 if (params.length !== paramCount) {
11719 this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
11720 at: method
11721 });
11722 }
11723 if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
11724 this.raise(Errors.BadSetterRestParameter, {
11725 at: method
11726 });
11727 }
11728 }
11729 parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
11730 if (isAccessor) {
11731 const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
11732 this.checkGetterSetterParams(finishedProp);
11733 return finishedProp;
11734 }
11735 if (isAsync || isGenerator || this.match(10)) {
11736 if (isPattern) this.unexpected();
11737 prop.kind = "method";
11738 prop.method = true;
11739 return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
11740 }
11741 }
11742 parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
11743 prop.shorthand = false;
11744 if (this.eat(14)) {
11745 prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
11746 return this.finishNode(prop, "ObjectProperty");
11747 }
11748 if (!prop.computed && prop.key.type === "Identifier") {
11749 this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
11750 if (isPattern) {
11751 prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
11752 } else if (this.match(29)) {
11753 const shorthandAssignLoc = this.state.startLoc;
11754 if (refExpressionErrors != null) {
11755 if (refExpressionErrors.shorthandAssignLoc === null) {
11756 refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
11757 }
11758 } else {
11759 this.raise(Errors.InvalidCoverInitializedName, {
11760 at: shorthandAssignLoc
11761 });
11762 }
11763 prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
11764 } else {
11765 prop.value = cloneIdentifier(prop.key);
11766 }
11767 prop.shorthand = true;
11768 return this.finishNode(prop, "ObjectProperty");
11769 }
11770 }
11771 parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
11772 const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
11773 if (!node) this.unexpected();
11774 return node;
11775 }
11776 parsePropertyName(prop, refExpressionErrors) {
11777 if (this.eat(0)) {
11778 prop.computed = true;
11779 prop.key = this.parseMaybeAssignAllowIn();
11780 this.expect(3);
11781 } else {
11782 const {
11783 type,
11784 value
11785 } = this.state;
11786 let key;
11787 if (tokenIsKeywordOrIdentifier(type)) {
11788 key = this.parseIdentifier(true);
11789 } else {
11790 switch (type) {
11791 case 132:
11792 key = this.parseNumericLiteral(value);
11793 break;
11794 case 131:
11795 key = this.parseStringLiteral(value);
11796 break;
11797 case 133:
11798 key = this.parseBigIntLiteral(value);
11799 break;
11800 case 134:
11801 key = this.parseDecimalLiteral(value);
11802 break;
11803 case 136:
11804 {
11805 const privateKeyLoc = this.state.startLoc;
11806 if (refExpressionErrors != null) {
11807 if (refExpressionErrors.privateKeyLoc === null) {
11808 refExpressionErrors.privateKeyLoc = privateKeyLoc;
11809 }
11810 } else {
11811 this.raise(Errors.UnexpectedPrivateField, {
11812 at: privateKeyLoc
11813 });
11814 }
11815 key = this.parsePrivateName();
11816 break;
11817 }
11818 default:
11819 this.unexpected();
11820 }
11821 }
11822 prop.key = key;
11823 if (type !== 136) {
11824 prop.computed = false;
11825 }
11826 }
11827 return prop.key;
11828 }
11829 initFunction(node, isAsync) {
11830 node.id = null;
11831 node.generator = false;
11832 node.async = isAsync;
11833 }
11834 parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
11835 this.initFunction(node, isAsync);
11836 node.generator = isGenerator;
11837 this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
11838 this.prodParam.enter(functionFlags(isAsync, node.generator));
11839 this.parseFunctionParams(node, isConstructor);
11840 const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
11841 this.prodParam.exit();
11842 this.scope.exit();
11843 return finishedNode;
11844 }
11845 parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
11846 if (isTuple) {
11847 this.expectPlugin("recordAndTuple");
11848 }
11849 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
11850 this.state.inFSharpPipelineDirectBody = false;
11851 const node = this.startNode();
11852 this.next();
11853 node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
11854 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
11855 return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
11856 }
11857 parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
11858 this.scope.enter(2 | 4);
11859 let flags = functionFlags(isAsync, false);
11860 if (!this.match(5) && this.prodParam.hasIn) {
11861 flags |= PARAM_IN;
11862 }
11863 this.prodParam.enter(flags);
11864 this.initFunction(node, isAsync);
11865 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
11866 if (params) {
11867 this.state.maybeInArrowParameters = true;
11868 this.setArrowFunctionParameters(node, params, trailingCommaLoc);
11869 }
11870 this.state.maybeInArrowParameters = false;
11871 this.parseFunctionBody(node, true);
11872 this.prodParam.exit();
11873 this.scope.exit();
11874 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
11875 return this.finishNode(node, "ArrowFunctionExpression");
11876 }
11877 setArrowFunctionParameters(node, params, trailingCommaLoc) {
11878 this.toAssignableList(params, trailingCommaLoc, false);
11879 node.params = params;
11880 }
11881 parseFunctionBodyAndFinish(node, type, isMethod = false) {
11882 this.parseFunctionBody(node, false, isMethod);
11883 return this.finishNode(node, type);
11884 }
11885 parseFunctionBody(node, allowExpression, isMethod = false) {
11886 const isExpression = allowExpression && !this.match(5);
11887 this.expressionScope.enter(newExpressionScope());
11888 if (isExpression) {
11889 node.body = this.parseMaybeAssign();
11890 this.checkParams(node, false, allowExpression, false);
11891 } else {
11892 const oldStrict = this.state.strict;
11893 const oldLabels = this.state.labels;
11894 this.state.labels = [];
11895 this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
11896 node.body = this.parseBlock(true, false, hasStrictModeDirective => {
11897 const nonSimple = !this.isSimpleParamList(node.params);
11898 if (hasStrictModeDirective && nonSimple) {
11899 this.raise(Errors.IllegalLanguageModeDirective, {
11900 at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
11901 });
11902 }
11903 const strictModeChanged = !oldStrict && this.state.strict;
11904 this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
11905 if (this.state.strict && node.id) {
11906 this.checkIdentifier(node.id, 65, strictModeChanged);
11907 }
11908 });
11909 this.prodParam.exit();
11910 this.state.labels = oldLabels;
11911 }
11912 this.expressionScope.exit();
11913 }
11914 isSimpleParameter(node) {
11915 return node.type === "Identifier";
11916 }
11917 isSimpleParamList(params) {
11918 for (let i = 0, len = params.length; i < len; i++) {
11919 if (!this.isSimpleParameter(params[i])) return false;
11920 }
11921 return true;
11922 }
11923 checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
11924 const checkClashes = !allowDuplicates && new Set();
11925 const formalParameters = {
11926 type: "FormalParameters"
11927 };
11928 for (const param of node.params) {
11929 this.checkLVal(param, {
11930 in: formalParameters,
11931 binding: 5,
11932 checkClashes,
11933 strictModeChanged
11934 });
11935 }
11936 }
11937 parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
11938 const elts = [];
11939 let first = true;
11940 while (!this.eat(close)) {
11941 if (first) {
11942 first = false;
11943 } else {
11944 this.expect(12);
11945 if (this.match(close)) {
11946 if (nodeForExtra) {
11947 this.addTrailingCommaExtraToNode(nodeForExtra);
11948 }
11949 this.next();
11950 break;
11951 }
11952 }
11953 elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
11954 }
11955 return elts;
11956 }
11957 parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
11958 let elt;
11959 if (this.match(12)) {
11960 if (!allowEmpty) {
11961 this.raise(Errors.UnexpectedToken, {
11962 at: this.state.curPosition(),
11963 unexpected: ","
11964 });
11965 }
11966 elt = null;
11967 } else if (this.match(21)) {
11968 const spreadNodeStartLoc = this.state.startLoc;
11969 elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
11970 } else if (this.match(17)) {
11971 this.expectPlugin("partialApplication");
11972 if (!allowPlaceholder) {
11973 this.raise(Errors.UnexpectedArgumentPlaceholder, {
11974 at: this.state.startLoc
11975 });
11976 }
11977 const node = this.startNode();
11978 this.next();
11979 elt = this.finishNode(node, "ArgumentPlaceholder");
11980 } else {
11981 elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
11982 }
11983 return elt;
11984 }
11985 parseIdentifier(liberal) {
11986 const node = this.startNode();
11987 const name = this.parseIdentifierName(liberal);
11988 return this.createIdentifier(node, name);
11989 }
11990 createIdentifier(node, name) {
11991 node.name = name;
11992 node.loc.identifierName = name;
11993 return this.finishNode(node, "Identifier");
11994 }
11995 parseIdentifierName(liberal) {
11996 let name;
11997 const {
11998 startLoc,
11999 type
12000 } = this.state;
12001 if (tokenIsKeywordOrIdentifier(type)) {
12002 name = this.state.value;
12003 } else {
12004 this.unexpected();
12005 }
12006 const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
12007 if (liberal) {
12008 if (tokenIsKeyword) {
12009 this.replaceToken(130);
12010 }
12011 } else {
12012 this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
12013 }
12014 this.next();
12015 return name;
12016 }
12017 checkReservedWord(word, startLoc, checkKeywords, isBinding) {
12018 if (word.length > 10) {
12019 return;
12020 }
12021 if (!canBeReservedWord(word)) {
12022 return;
12023 }
12024 if (checkKeywords && isKeyword(word)) {
12025 this.raise(Errors.UnexpectedKeyword, {
12026 at: startLoc,
12027 keyword: word
12028 });
12029 return;
12030 }
12031 const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
12032 if (reservedTest(word, this.inModule)) {
12033 this.raise(Errors.UnexpectedReservedWord, {
12034 at: startLoc,
12035 reservedWord: word
12036 });
12037 return;
12038 } else if (word === "yield") {
12039 if (this.prodParam.hasYield) {
12040 this.raise(Errors.YieldBindingIdentifier, {
12041 at: startLoc
12042 });
12043 return;
12044 }
12045 } else if (word === "await") {
12046 if (this.prodParam.hasAwait) {
12047 this.raise(Errors.AwaitBindingIdentifier, {
12048 at: startLoc
12049 });
12050 return;
12051 }
12052 if (this.scope.inStaticBlock) {
12053 this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
12054 at: startLoc
12055 });
12056 return;
12057 }
12058 this.expressionScope.recordAsyncArrowParametersError({
12059 at: startLoc
12060 });
12061 } else if (word === "arguments") {
12062 if (this.scope.inClassAndNotInNonArrowFunction) {
12063 this.raise(Errors.ArgumentsInClass, {
12064 at: startLoc
12065 });
12066 return;
12067 }
12068 }
12069 }
12070 isAwaitAllowed() {
12071 if (this.prodParam.hasAwait) return true;
12072 if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
12073 return true;
12074 }
12075 return false;
12076 }
12077 parseAwait(startLoc) {
12078 const node = this.startNodeAt(startLoc);
12079 this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
12080 at: node
12081 });
12082 if (this.eat(55)) {
12083 this.raise(Errors.ObsoleteAwaitStar, {
12084 at: node
12085 });
12086 }
12087 if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
12088 if (this.isAmbiguousAwait()) {
12089 this.ambiguousScriptDifferentAst = true;
12090 } else {
12091 this.sawUnambiguousESM = true;
12092 }
12093 }
12094 if (!this.state.soloAwait) {
12095 node.argument = this.parseMaybeUnary(null, true);
12096 }
12097 return this.finishNode(node, "AwaitExpression");
12098 }
12099 isAmbiguousAwait() {
12100 if (this.hasPrecedingLineBreak()) return true;
12101 const {
12102 type
12103 } = this.state;
12104 return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 101 && !this.state.containsEsc || type === 135 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
12105 }
12106 parseYield() {
12107 const node = this.startNode();
12108 this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
12109 at: node
12110 });
12111 this.next();
12112 let delegating = false;
12113 let argument = null;
12114 if (!this.hasPrecedingLineBreak()) {
12115 delegating = this.eat(55);
12116 switch (this.state.type) {
12117 case 13:
12118 case 137:
12119 case 8:
12120 case 11:
12121 case 3:
12122 case 9:
12123 case 14:
12124 case 12:
12125 if (!delegating) break;
12126 default:
12127 argument = this.parseMaybeAssign();
12128 }
12129 }
12130 node.delegate = delegating;
12131 node.argument = argument;
12132 return this.finishNode(node, "YieldExpression");
12133 }
12134 checkPipelineAtInfixOperator(left, leftStartLoc) {
12135 if (this.hasPlugin(["pipelineOperator", {
12136 proposal: "smart"
12137 }])) {
12138 if (left.type === "SequenceExpression") {
12139 this.raise(Errors.PipelineHeadSequenceExpression, {
12140 at: leftStartLoc
12141 });
12142 }
12143 }
12144 }
12145 parseSmartPipelineBodyInStyle(childExpr, startLoc) {
12146 if (this.isSimpleReference(childExpr)) {
12147 const bodyNode = this.startNodeAt(startLoc);
12148 bodyNode.callee = childExpr;
12149 return this.finishNode(bodyNode, "PipelineBareFunction");
12150 } else {
12151 const bodyNode = this.startNodeAt(startLoc);
12152 this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
12153 bodyNode.expression = childExpr;
12154 return this.finishNode(bodyNode, "PipelineTopicExpression");
12155 }
12156 }
12157 isSimpleReference(expression) {
12158 switch (expression.type) {
12159 case "MemberExpression":
12160 return !expression.computed && this.isSimpleReference(expression.object);
12161 case "Identifier":
12162 return true;
12163 default:
12164 return false;
12165 }
12166 }
12167 checkSmartPipeTopicBodyEarlyErrors(startLoc) {
12168 if (this.match(19)) {
12169 throw this.raise(Errors.PipelineBodyNoArrow, {
12170 at: this.state.startLoc
12171 });
12172 }
12173 if (!this.topicReferenceWasUsedInCurrentContext()) {
12174 this.raise(Errors.PipelineTopicUnused, {
12175 at: startLoc
12176 });
12177 }
12178 }
12179 withTopicBindingContext(callback) {
12180 const outerContextTopicState = this.state.topicContext;
12181 this.state.topicContext = {
12182 maxNumOfResolvableTopics: 1,
12183 maxTopicIndex: null
12184 };
12185 try {
12186 return callback();
12187 } finally {
12188 this.state.topicContext = outerContextTopicState;
12189 }
12190 }
12191 withSmartMixTopicForbiddingContext(callback) {
12192 if (this.hasPlugin(["pipelineOperator", {
12193 proposal: "smart"
12194 }])) {
12195 const outerContextTopicState = this.state.topicContext;
12196 this.state.topicContext = {
12197 maxNumOfResolvableTopics: 0,
12198 maxTopicIndex: null
12199 };
12200 try {
12201 return callback();
12202 } finally {
12203 this.state.topicContext = outerContextTopicState;
12204 }
12205 } else {
12206 return callback();
12207 }
12208 }
12209 withSoloAwaitPermittingContext(callback) {
12210 const outerContextSoloAwaitState = this.state.soloAwait;
12211 this.state.soloAwait = true;
12212 try {
12213 return callback();
12214 } finally {
12215 this.state.soloAwait = outerContextSoloAwaitState;
12216 }
12217 }
12218 allowInAnd(callback) {
12219 const flags = this.prodParam.currentFlags();
12220 const prodParamToSet = PARAM_IN & ~flags;
12221 if (prodParamToSet) {
12222 this.prodParam.enter(flags | PARAM_IN);
12223 try {
12224 return callback();
12225 } finally {
12226 this.prodParam.exit();
12227 }
12228 }
12229 return callback();
12230 }
12231 disallowInAnd(callback) {
12232 const flags = this.prodParam.currentFlags();
12233 const prodParamToClear = PARAM_IN & flags;
12234 if (prodParamToClear) {
12235 this.prodParam.enter(flags & ~PARAM_IN);
12236 try {
12237 return callback();
12238 } finally {
12239 this.prodParam.exit();
12240 }
12241 }
12242 return callback();
12243 }
12244 registerTopicReference() {
12245 this.state.topicContext.maxTopicIndex = 0;
12246 }
12247 topicReferenceIsAllowedInCurrentContext() {
12248 return this.state.topicContext.maxNumOfResolvableTopics >= 1;
12249 }
12250 topicReferenceWasUsedInCurrentContext() {
12251 return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
12252 }
12253 parseFSharpPipelineBody(prec) {
12254 const startLoc = this.state.startLoc;
12255 this.state.potentialArrowAt = this.state.start;
12256 const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
12257 this.state.inFSharpPipelineDirectBody = true;
12258 const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
12259 this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
12260 return ret;
12261 }
12262 parseModuleExpression() {
12263 this.expectPlugin("moduleBlocks");
12264 const node = this.startNode();
12265 this.next();
12266 if (!this.match(5)) {
12267 this.unexpected(null, 5);
12268 }
12269 const program = this.startNodeAt(this.state.endLoc);
12270 this.next();
12271 const revertScopes = this.initializeScopes(true);
12272 this.enterInitialScopes();
12273 try {
12274 node.body = this.parseProgram(program, 8, "module");
12275 } finally {
12276 revertScopes();
12277 }
12278 return this.finishNode(node, "ModuleExpression");
12279 }
12280 parsePropertyNamePrefixOperator(prop) {}
12281}
12282const loopLabel = {
12283 kind: "loop"
12284 },
12285 switchLabel = {
12286 kind: "switch"
12287 };
12288const loneSurrogate = /[\uD800-\uDFFF]/u;
12289const keywordRelationalOperator = /in(?:stanceof)?/y;
12290function babel7CompatTokens(tokens, input) {
12291 for (let i = 0; i < tokens.length; i++) {
12292 const token = tokens[i];
12293 const {
12294 type
12295 } = token;
12296 if (typeof type === "number") {
12297 {
12298 if (type === 136) {
12299 const {
12300 loc,
12301 start,
12302 value,
12303 end
12304 } = token;
12305 const hashEndPos = start + 1;
12306 const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
12307 tokens.splice(i, 1, new Token({
12308 type: getExportedToken(27),
12309 value: "#",
12310 start: start,
12311 end: hashEndPos,
12312 startLoc: loc.start,
12313 endLoc: hashEndLoc
12314 }), new Token({
12315 type: getExportedToken(130),
12316 value: value,
12317 start: hashEndPos,
12318 end: end,
12319 startLoc: hashEndLoc,
12320 endLoc: loc.end
12321 }));
12322 i++;
12323 continue;
12324 }
12325 if (tokenIsTemplate(type)) {
12326 const {
12327 loc,
12328 start,
12329 value,
12330 end
12331 } = token;
12332 const backquoteEnd = start + 1;
12333 const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
12334 let startToken;
12335 if (input.charCodeAt(start) === 96) {
12336 startToken = new Token({
12337 type: getExportedToken(22),
12338 value: "`",
12339 start: start,
12340 end: backquoteEnd,
12341 startLoc: loc.start,
12342 endLoc: backquoteEndLoc
12343 });
12344 } else {
12345 startToken = new Token({
12346 type: getExportedToken(8),
12347 value: "}",
12348 start: start,
12349 end: backquoteEnd,
12350 startLoc: loc.start,
12351 endLoc: backquoteEndLoc
12352 });
12353 }
12354 let templateValue, templateElementEnd, templateElementEndLoc, endToken;
12355 if (type === 24) {
12356 templateElementEnd = end - 1;
12357 templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
12358 templateValue = value === null ? null : value.slice(1, -1);
12359 endToken = new Token({
12360 type: getExportedToken(22),
12361 value: "`",
12362 start: templateElementEnd,
12363 end: end,
12364 startLoc: templateElementEndLoc,
12365 endLoc: loc.end
12366 });
12367 } else {
12368 templateElementEnd = end - 2;
12369 templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
12370 templateValue = value === null ? null : value.slice(1, -2);
12371 endToken = new Token({
12372 type: getExportedToken(23),
12373 value: "${",
12374 start: templateElementEnd,
12375 end: end,
12376 startLoc: templateElementEndLoc,
12377 endLoc: loc.end
12378 });
12379 }
12380 tokens.splice(i, 1, startToken, new Token({
12381 type: getExportedToken(20),
12382 value: templateValue,
12383 start: backquoteEnd,
12384 end: templateElementEnd,
12385 startLoc: backquoteEndLoc,
12386 endLoc: templateElementEndLoc
12387 }), endToken);
12388 i += 2;
12389 continue;
12390 }
12391 }
12392 token.type = getExportedToken(type);
12393 }
12394 }
12395 return tokens;
12396}
12397class StatementParser extends ExpressionParser {
12398 parseTopLevel(file, program) {
12399 file.program = this.parseProgram(program);
12400 file.comments = this.state.comments;
12401 if (this.options.tokens) {
12402 file.tokens = babel7CompatTokens(this.tokens, this.input);
12403 }
12404 return this.finishNode(file, "File");
12405 }
12406 parseProgram(program, end = 137, sourceType = this.options.sourceType) {
12407 program.sourceType = sourceType;
12408 program.interpreter = this.parseInterpreterDirective();
12409 this.parseBlockBody(program, true, true, end);
12410 if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
12411 for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
12412 this.raise(Errors.ModuleExportUndefined, {
12413 at,
12414 localName
12415 });
12416 }
12417 }
12418 let finishedProgram;
12419 if (end === 137) {
12420 finishedProgram = this.finishNode(program, "Program");
12421 } else {
12422 finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
12423 }
12424 return finishedProgram;
12425 }
12426 stmtToDirective(stmt) {
12427 const directive = stmt;
12428 directive.type = "Directive";
12429 directive.value = directive.expression;
12430 delete directive.expression;
12431 const directiveLiteral = directive.value;
12432 const expressionValue = directiveLiteral.value;
12433 const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
12434 const val = directiveLiteral.value = raw.slice(1, -1);
12435 this.addExtra(directiveLiteral, "raw", raw);
12436 this.addExtra(directiveLiteral, "rawValue", val);
12437 this.addExtra(directiveLiteral, "expressionValue", expressionValue);
12438 directiveLiteral.type = "DirectiveLiteral";
12439 return directive;
12440 }
12441 parseInterpreterDirective() {
12442 if (!this.match(28)) {
12443 return null;
12444 }
12445 const node = this.startNode();
12446 node.value = this.state.value;
12447 this.next();
12448 return this.finishNode(node, "InterpreterDirective");
12449 }
12450 isLet() {
12451 if (!this.isContextual(99)) {
12452 return false;
12453 }
12454 return this.hasFollowingBindingAtom();
12455 }
12456 chStartsBindingIdentifier(ch, pos) {
12457 if (isIdentifierStart(ch)) {
12458 keywordRelationalOperator.lastIndex = pos;
12459 if (keywordRelationalOperator.test(this.input)) {
12460 const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
12461 if (!isIdentifierChar(endCh) && endCh !== 92) {
12462 return false;
12463 }
12464 }
12465 return true;
12466 } else if (ch === 92) {
12467 return true;
12468 } else {
12469 return false;
12470 }
12471 }
12472 chStartsBindingPattern(ch) {
12473 return ch === 91 || ch === 123;
12474 }
12475 hasFollowingBindingAtom() {
12476 const next = this.nextTokenStart();
12477 const nextCh = this.codePointAtPos(next);
12478 return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
12479 }
12480 hasInLineFollowingBindingIdentifier() {
12481 const next = this.nextTokenInLineStart();
12482 const nextCh = this.codePointAtPos(next);
12483 return this.chStartsBindingIdentifier(nextCh, next);
12484 }
12485 startsUsingForOf() {
12486 const {
12487 type,
12488 containsEsc
12489 } = this.lookahead();
12490 if (type === 101 && !containsEsc) {
12491 return false;
12492 } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
12493 this.expectPlugin("explicitResourceManagement");
12494 return true;
12495 }
12496 }
12497 startsAwaitUsing() {
12498 let next = this.nextTokenInLineStart();
12499 if (this.isUnparsedContextual(next, "using")) {
12500 next = this.nextTokenInLineStartSince(next + 5);
12501 const nextCh = this.codePointAtPos(next);
12502 if (this.chStartsBindingIdentifier(nextCh, next)) {
12503 this.expectPlugin("explicitResourceManagement");
12504 return true;
12505 }
12506 }
12507 return false;
12508 }
12509 parseModuleItem() {
12510 return this.parseStatementLike(1 | 2 | 4 | 8);
12511 }
12512 parseStatementListItem() {
12513 return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
12514 }
12515 parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
12516 let flags = 0;
12517 if (this.options.annexB && !this.state.strict) {
12518 flags |= 4;
12519 if (allowLabeledFunction) {
12520 flags |= 8;
12521 }
12522 }
12523 return this.parseStatementLike(flags);
12524 }
12525 parseStatement() {
12526 return this.parseStatementLike(0);
12527 }
12528 parseStatementLike(flags) {
12529 let decorators = null;
12530 if (this.match(26)) {
12531 decorators = this.parseDecorators(true);
12532 }
12533 return this.parseStatementContent(flags, decorators);
12534 }
12535 parseStatementContent(flags, decorators) {
12536 const starttype = this.state.type;
12537 const node = this.startNode();
12538 const allowDeclaration = !!(flags & 2);
12539 const allowFunctionDeclaration = !!(flags & 4);
12540 const topLevel = flags & 1;
12541 switch (starttype) {
12542 case 60:
12543 return this.parseBreakContinueStatement(node, true);
12544 case 63:
12545 return this.parseBreakContinueStatement(node, false);
12546 case 64:
12547 return this.parseDebuggerStatement(node);
12548 case 90:
12549 return this.parseDoWhileStatement(node);
12550 case 91:
12551 return this.parseForStatement(node);
12552 case 68:
12553 if (this.lookaheadCharCode() === 46) break;
12554 if (!allowFunctionDeclaration) {
12555 this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
12556 at: this.state.startLoc
12557 });
12558 }
12559 return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
12560 case 80:
12561 if (!allowDeclaration) this.unexpected();
12562 return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
12563 case 69:
12564 return this.parseIfStatement(node);
12565 case 70:
12566 return this.parseReturnStatement(node);
12567 case 71:
12568 return this.parseSwitchStatement(node);
12569 case 72:
12570 return this.parseThrowStatement(node);
12571 case 73:
12572 return this.parseTryStatement(node);
12573 case 96:
12574 if (!this.state.containsEsc && this.startsAwaitUsing()) {
12575 if (!this.isAwaitAllowed()) {
12576 this.raise(Errors.AwaitUsingNotInAsyncContext, {
12577 at: node
12578 });
12579 } else if (!allowDeclaration) {
12580 this.raise(Errors.UnexpectedLexicalDeclaration, {
12581 at: node
12582 });
12583 }
12584 this.next();
12585 return this.parseVarStatement(node, "await using");
12586 }
12587 break;
12588 case 105:
12589 if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
12590 break;
12591 }
12592 this.expectPlugin("explicitResourceManagement");
12593 if (!this.scope.inModule && this.scope.inTopLevel) {
12594 this.raise(Errors.UnexpectedUsingDeclaration, {
12595 at: this.state.startLoc
12596 });
12597 } else if (!allowDeclaration) {
12598 this.raise(Errors.UnexpectedLexicalDeclaration, {
12599 at: this.state.startLoc
12600 });
12601 }
12602 return this.parseVarStatement(node, "using");
12603 case 99:
12604 {
12605 if (this.state.containsEsc) {
12606 break;
12607 }
12608 const next = this.nextTokenStart();
12609 const nextCh = this.codePointAtPos(next);
12610 if (nextCh !== 91) {
12611 if (!allowDeclaration && this.hasFollowingLineBreak()) break;
12612 if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
12613 break;
12614 }
12615 }
12616 }
12617 case 75:
12618 {
12619 if (!allowDeclaration) {
12620 this.raise(Errors.UnexpectedLexicalDeclaration, {
12621 at: this.state.startLoc
12622 });
12623 }
12624 }
12625 case 74:
12626 {
12627 const kind = this.state.value;
12628 return this.parseVarStatement(node, kind);
12629 }
12630 case 92:
12631 return this.parseWhileStatement(node);
12632 case 76:
12633 return this.parseWithStatement(node);
12634 case 5:
12635 return this.parseBlock();
12636 case 13:
12637 return this.parseEmptyStatement(node);
12638 case 83:
12639 {
12640 const nextTokenCharCode = this.lookaheadCharCode();
12641 if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
12642 break;
12643 }
12644 }
12645 case 82:
12646 {
12647 if (!this.options.allowImportExportEverywhere && !topLevel) {
12648 this.raise(Errors.UnexpectedImportExport, {
12649 at: this.state.startLoc
12650 });
12651 }
12652 this.next();
12653 let result;
12654 if (starttype === 83) {
12655 result = this.parseImport(node);
12656 if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
12657 this.sawUnambiguousESM = true;
12658 }
12659 } else {
12660 result = this.parseExport(node, decorators);
12661 if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
12662 this.sawUnambiguousESM = true;
12663 }
12664 }
12665 this.assertModuleNodeAllowed(result);
12666 return result;
12667 }
12668 default:
12669 {
12670 if (this.isAsyncFunction()) {
12671 if (!allowDeclaration) {
12672 this.raise(Errors.AsyncFunctionInSingleStatementContext, {
12673 at: this.state.startLoc
12674 });
12675 }
12676 this.next();
12677 return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
12678 }
12679 }
12680 }
12681 const maybeName = this.state.value;
12682 const expr = this.parseExpression();
12683 if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
12684 return this.parseLabeledStatement(node, maybeName, expr, flags);
12685 } else {
12686 return this.parseExpressionStatement(node, expr, decorators);
12687 }
12688 }
12689 assertModuleNodeAllowed(node) {
12690 if (!this.options.allowImportExportEverywhere && !this.inModule) {
12691 this.raise(Errors.ImportOutsideModule, {
12692 at: node
12693 });
12694 }
12695 }
12696 decoratorsEnabledBeforeExport() {
12697 if (this.hasPlugin("decorators-legacy")) return true;
12698 return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
12699 }
12700 maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
12701 if (maybeDecorators) {
12702 if (classNode.decorators && classNode.decorators.length > 0) {
12703 if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
12704 this.raise(Errors.DecoratorsBeforeAfterExport, {
12705 at: classNode.decorators[0]
12706 });
12707 }
12708 classNode.decorators.unshift(...maybeDecorators);
12709 } else {
12710 classNode.decorators = maybeDecorators;
12711 }
12712 this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
12713 if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
12714 }
12715 return classNode;
12716 }
12717 canHaveLeadingDecorator() {
12718 return this.match(80);
12719 }
12720 parseDecorators(allowExport) {
12721 const decorators = [];
12722 do {
12723 decorators.push(this.parseDecorator());
12724 } while (this.match(26));
12725 if (this.match(82)) {
12726 if (!allowExport) {
12727 this.unexpected();
12728 }
12729 if (!this.decoratorsEnabledBeforeExport()) {
12730 this.raise(Errors.DecoratorExportClass, {
12731 at: this.state.startLoc
12732 });
12733 }
12734 } else if (!this.canHaveLeadingDecorator()) {
12735 throw this.raise(Errors.UnexpectedLeadingDecorator, {
12736 at: this.state.startLoc
12737 });
12738 }
12739 return decorators;
12740 }
12741 parseDecorator() {
12742 this.expectOnePlugin(["decorators", "decorators-legacy"]);
12743 const node = this.startNode();
12744 this.next();
12745 if (this.hasPlugin("decorators")) {
12746 const startLoc = this.state.startLoc;
12747 let expr;
12748 if (this.match(10)) {
12749 const startLoc = this.state.startLoc;
12750 this.next();
12751 expr = this.parseExpression();
12752 this.expect(11);
12753 expr = this.wrapParenthesis(startLoc, expr);
12754 const paramsStartLoc = this.state.startLoc;
12755 node.expression = this.parseMaybeDecoratorArguments(expr);
12756 if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
12757 this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
12758 at: paramsStartLoc
12759 });
12760 }
12761 } else {
12762 expr = this.parseIdentifier(false);
12763 while (this.eat(16)) {
12764 const node = this.startNodeAt(startLoc);
12765 node.object = expr;
12766 if (this.match(136)) {
12767 this.classScope.usePrivateName(this.state.value, this.state.startLoc);
12768 node.property = this.parsePrivateName();
12769 } else {
12770 node.property = this.parseIdentifier(true);
12771 }
12772 node.computed = false;
12773 expr = this.finishNode(node, "MemberExpression");
12774 }
12775 node.expression = this.parseMaybeDecoratorArguments(expr);
12776 }
12777 } else {
12778 node.expression = this.parseExprSubscripts();
12779 }
12780 return this.finishNode(node, "Decorator");
12781 }
12782 parseMaybeDecoratorArguments(expr) {
12783 if (this.eat(10)) {
12784 const node = this.startNodeAtNode(expr);
12785 node.callee = expr;
12786 node.arguments = this.parseCallExpressionArguments(11, false);
12787 this.toReferencedList(node.arguments);
12788 return this.finishNode(node, "CallExpression");
12789 }
12790 return expr;
12791 }
12792 parseBreakContinueStatement(node, isBreak) {
12793 this.next();
12794 if (this.isLineTerminator()) {
12795 node.label = null;
12796 } else {
12797 node.label = this.parseIdentifier();
12798 this.semicolon();
12799 }
12800 this.verifyBreakContinue(node, isBreak);
12801 return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
12802 }
12803 verifyBreakContinue(node, isBreak) {
12804 let i;
12805 for (i = 0; i < this.state.labels.length; ++i) {
12806 const lab = this.state.labels[i];
12807 if (node.label == null || lab.name === node.label.name) {
12808 if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
12809 if (node.label && isBreak) break;
12810 }
12811 }
12812 if (i === this.state.labels.length) {
12813 const type = isBreak ? "BreakStatement" : "ContinueStatement";
12814 this.raise(Errors.IllegalBreakContinue, {
12815 at: node,
12816 type
12817 });
12818 }
12819 }
12820 parseDebuggerStatement(node) {
12821 this.next();
12822 this.semicolon();
12823 return this.finishNode(node, "DebuggerStatement");
12824 }
12825 parseHeaderExpression() {
12826 this.expect(10);
12827 const val = this.parseExpression();
12828 this.expect(11);
12829 return val;
12830 }
12831 parseDoWhileStatement(node) {
12832 this.next();
12833 this.state.labels.push(loopLabel);
12834 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
12835 this.state.labels.pop();
12836 this.expect(92);
12837 node.test = this.parseHeaderExpression();
12838 this.eat(13);
12839 return this.finishNode(node, "DoWhileStatement");
12840 }
12841 parseForStatement(node) {
12842 this.next();
12843 this.state.labels.push(loopLabel);
12844 let awaitAt = null;
12845 if (this.isAwaitAllowed() && this.eatContextual(96)) {
12846 awaitAt = this.state.lastTokStartLoc;
12847 }
12848 this.scope.enter(0);
12849 this.expect(10);
12850 if (this.match(13)) {
12851 if (awaitAt !== null) {
12852 this.unexpected(awaitAt);
12853 }
12854 return this.parseFor(node, null);
12855 }
12856 const startsWithLet = this.isContextual(99);
12857 {
12858 const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
12859 const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(105) && this.startsUsingForOf();
12860 const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
12861 if (this.match(74) || this.match(75) || isLetOrUsing) {
12862 const initNode = this.startNode();
12863 let kind;
12864 if (startsWithAwaitUsing) {
12865 kind = "await using";
12866 if (!this.isAwaitAllowed()) {
12867 this.raise(Errors.AwaitUsingNotInAsyncContext, {
12868 at: this.state.startLoc
12869 });
12870 }
12871 this.next();
12872 } else {
12873 kind = this.state.value;
12874 }
12875 this.next();
12876 this.parseVar(initNode, true, kind);
12877 const init = this.finishNode(initNode, "VariableDeclaration");
12878 const isForIn = this.match(58);
12879 if (isForIn && starsWithUsingDeclaration) {
12880 this.raise(Errors.ForInUsing, {
12881 at: init
12882 });
12883 }
12884 if ((isForIn || this.isContextual(101)) && init.declarations.length === 1) {
12885 return this.parseForIn(node, init, awaitAt);
12886 }
12887 if (awaitAt !== null) {
12888 this.unexpected(awaitAt);
12889 }
12890 return this.parseFor(node, init);
12891 }
12892 }
12893 const startsWithAsync = this.isContextual(95);
12894 const refExpressionErrors = new ExpressionErrors();
12895 const init = this.parseExpression(true, refExpressionErrors);
12896 const isForOf = this.isContextual(101);
12897 if (isForOf) {
12898 if (startsWithLet) {
12899 this.raise(Errors.ForOfLet, {
12900 at: init
12901 });
12902 }
12903 if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
12904 this.raise(Errors.ForOfAsync, {
12905 at: init
12906 });
12907 }
12908 }
12909 if (isForOf || this.match(58)) {
12910 this.checkDestructuringPrivate(refExpressionErrors);
12911 this.toAssignable(init, true);
12912 const type = isForOf ? "ForOfStatement" : "ForInStatement";
12913 this.checkLVal(init, {
12914 in: {
12915 type
12916 }
12917 });
12918 return this.parseForIn(node, init, awaitAt);
12919 } else {
12920 this.checkExpressionErrors(refExpressionErrors, true);
12921 }
12922 if (awaitAt !== null) {
12923 this.unexpected(awaitAt);
12924 }
12925 return this.parseFor(node, init);
12926 }
12927 parseFunctionStatement(node, isAsync, isHangingDeclaration) {
12928 this.next();
12929 return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
12930 }
12931 parseIfStatement(node) {
12932 this.next();
12933 node.test = this.parseHeaderExpression();
12934 node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
12935 node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
12936 return this.finishNode(node, "IfStatement");
12937 }
12938 parseReturnStatement(node) {
12939 if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
12940 this.raise(Errors.IllegalReturn, {
12941 at: this.state.startLoc
12942 });
12943 }
12944 this.next();
12945 if (this.isLineTerminator()) {
12946 node.argument = null;
12947 } else {
12948 node.argument = this.parseExpression();
12949 this.semicolon();
12950 }
12951 return this.finishNode(node, "ReturnStatement");
12952 }
12953 parseSwitchStatement(node) {
12954 this.next();
12955 node.discriminant = this.parseHeaderExpression();
12956 const cases = node.cases = [];
12957 this.expect(5);
12958 this.state.labels.push(switchLabel);
12959 this.scope.enter(0);
12960 let cur;
12961 for (let sawDefault; !this.match(8);) {
12962 if (this.match(61) || this.match(65)) {
12963 const isCase = this.match(61);
12964 if (cur) this.finishNode(cur, "SwitchCase");
12965 cases.push(cur = this.startNode());
12966 cur.consequent = [];
12967 this.next();
12968 if (isCase) {
12969 cur.test = this.parseExpression();
12970 } else {
12971 if (sawDefault) {
12972 this.raise(Errors.MultipleDefaultsInSwitch, {
12973 at: this.state.lastTokStartLoc
12974 });
12975 }
12976 sawDefault = true;
12977 cur.test = null;
12978 }
12979 this.expect(14);
12980 } else {
12981 if (cur) {
12982 cur.consequent.push(this.parseStatementListItem());
12983 } else {
12984 this.unexpected();
12985 }
12986 }
12987 }
12988 this.scope.exit();
12989 if (cur) this.finishNode(cur, "SwitchCase");
12990 this.next();
12991 this.state.labels.pop();
12992 return this.finishNode(node, "SwitchStatement");
12993 }
12994 parseThrowStatement(node) {
12995 this.next();
12996 if (this.hasPrecedingLineBreak()) {
12997 this.raise(Errors.NewlineAfterThrow, {
12998 at: this.state.lastTokEndLoc
12999 });
13000 }
13001 node.argument = this.parseExpression();
13002 this.semicolon();
13003 return this.finishNode(node, "ThrowStatement");
13004 }
13005 parseCatchClauseParam() {
13006 const param = this.parseBindingAtom();
13007 this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
13008 this.checkLVal(param, {
13009 in: {
13010 type: "CatchClause"
13011 },
13012 binding: 9
13013 });
13014 return param;
13015 }
13016 parseTryStatement(node) {
13017 this.next();
13018 node.block = this.parseBlock();
13019 node.handler = null;
13020 if (this.match(62)) {
13021 const clause = this.startNode();
13022 this.next();
13023 if (this.match(10)) {
13024 this.expect(10);
13025 clause.param = this.parseCatchClauseParam();
13026 this.expect(11);
13027 } else {
13028 clause.param = null;
13029 this.scope.enter(0);
13030 }
13031 clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
13032 this.scope.exit();
13033 node.handler = this.finishNode(clause, "CatchClause");
13034 }
13035 node.finalizer = this.eat(67) ? this.parseBlock() : null;
13036 if (!node.handler && !node.finalizer) {
13037 this.raise(Errors.NoCatchOrFinally, {
13038 at: node
13039 });
13040 }
13041 return this.finishNode(node, "TryStatement");
13042 }
13043 parseVarStatement(node, kind, allowMissingInitializer = false) {
13044 this.next();
13045 this.parseVar(node, false, kind, allowMissingInitializer);
13046 this.semicolon();
13047 return this.finishNode(node, "VariableDeclaration");
13048 }
13049 parseWhileStatement(node) {
13050 this.next();
13051 node.test = this.parseHeaderExpression();
13052 this.state.labels.push(loopLabel);
13053 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13054 this.state.labels.pop();
13055 return this.finishNode(node, "WhileStatement");
13056 }
13057 parseWithStatement(node) {
13058 if (this.state.strict) {
13059 this.raise(Errors.StrictWith, {
13060 at: this.state.startLoc
13061 });
13062 }
13063 this.next();
13064 node.object = this.parseHeaderExpression();
13065 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13066 return this.finishNode(node, "WithStatement");
13067 }
13068 parseEmptyStatement(node) {
13069 this.next();
13070 return this.finishNode(node, "EmptyStatement");
13071 }
13072 parseLabeledStatement(node, maybeName, expr, flags) {
13073 for (const label of this.state.labels) {
13074 if (label.name === maybeName) {
13075 this.raise(Errors.LabelRedeclaration, {
13076 at: expr,
13077 labelName: maybeName
13078 });
13079 }
13080 }
13081 const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
13082 for (let i = this.state.labels.length - 1; i >= 0; i--) {
13083 const label = this.state.labels[i];
13084 if (label.statementStart === node.start) {
13085 label.statementStart = this.state.start;
13086 label.kind = kind;
13087 } else {
13088 break;
13089 }
13090 }
13091 this.state.labels.push({
13092 name: maybeName,
13093 kind: kind,
13094 statementStart: this.state.start
13095 });
13096 node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
13097 this.state.labels.pop();
13098 node.label = expr;
13099 return this.finishNode(node, "LabeledStatement");
13100 }
13101 parseExpressionStatement(node, expr, decorators) {
13102 node.expression = expr;
13103 this.semicolon();
13104 return this.finishNode(node, "ExpressionStatement");
13105 }
13106 parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
13107 const node = this.startNode();
13108 if (allowDirectives) {
13109 this.state.strictErrors.clear();
13110 }
13111 this.expect(5);
13112 if (createNewLexicalScope) {
13113 this.scope.enter(0);
13114 }
13115 this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
13116 if (createNewLexicalScope) {
13117 this.scope.exit();
13118 }
13119 return this.finishNode(node, "BlockStatement");
13120 }
13121 isValidDirective(stmt) {
13122 return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
13123 }
13124 parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
13125 const body = node.body = [];
13126 const directives = node.directives = [];
13127 this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
13128 }
13129 parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
13130 const oldStrict = this.state.strict;
13131 let hasStrictModeDirective = false;
13132 let parsedNonDirective = false;
13133 while (!this.match(end)) {
13134 const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
13135 if (directives && !parsedNonDirective) {
13136 if (this.isValidDirective(stmt)) {
13137 const directive = this.stmtToDirective(stmt);
13138 directives.push(directive);
13139 if (!hasStrictModeDirective && directive.value.value === "use strict") {
13140 hasStrictModeDirective = true;
13141 this.setStrict(true);
13142 }
13143 continue;
13144 }
13145 parsedNonDirective = true;
13146 this.state.strictErrors.clear();
13147 }
13148 body.push(stmt);
13149 }
13150 afterBlockParse == null ? void 0 : afterBlockParse.call(this, hasStrictModeDirective);
13151 if (!oldStrict) {
13152 this.setStrict(false);
13153 }
13154 this.next();
13155 }
13156 parseFor(node, init) {
13157 node.init = init;
13158 this.semicolon(false);
13159 node.test = this.match(13) ? null : this.parseExpression();
13160 this.semicolon(false);
13161 node.update = this.match(11) ? null : this.parseExpression();
13162 this.expect(11);
13163 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13164 this.scope.exit();
13165 this.state.labels.pop();
13166 return this.finishNode(node, "ForStatement");
13167 }
13168 parseForIn(node, init, awaitAt) {
13169 const isForIn = this.match(58);
13170 this.next();
13171 if (isForIn) {
13172 if (awaitAt !== null) this.unexpected(awaitAt);
13173 } else {
13174 node.await = awaitAt !== null;
13175 }
13176 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")) {
13177 this.raise(Errors.ForInOfLoopInitializer, {
13178 at: init,
13179 type: isForIn ? "ForInStatement" : "ForOfStatement"
13180 });
13181 }
13182 if (init.type === "AssignmentPattern") {
13183 this.raise(Errors.InvalidLhs, {
13184 at: init,
13185 ancestor: {
13186 type: "ForStatement"
13187 }
13188 });
13189 }
13190 node.left = init;
13191 node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
13192 this.expect(11);
13193 node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
13194 this.scope.exit();
13195 this.state.labels.pop();
13196 return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
13197 }
13198 parseVar(node, isFor, kind, allowMissingInitializer = false) {
13199 const declarations = node.declarations = [];
13200 node.kind = kind;
13201 for (;;) {
13202 const decl = this.startNode();
13203 this.parseVarId(decl, kind);
13204 decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
13205 if (decl.init === null && !allowMissingInitializer) {
13206 if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(101)))) {
13207 this.raise(Errors.DeclarationMissingInitializer, {
13208 at: this.state.lastTokEndLoc,
13209 kind: "destructuring"
13210 });
13211 } else if (kind === "const" && !(this.match(58) || this.isContextual(101))) {
13212 this.raise(Errors.DeclarationMissingInitializer, {
13213 at: this.state.lastTokEndLoc,
13214 kind: "const"
13215 });
13216 }
13217 }
13218 declarations.push(this.finishNode(decl, "VariableDeclarator"));
13219 if (!this.eat(12)) break;
13220 }
13221 return node;
13222 }
13223 parseVarId(decl, kind) {
13224 const id = this.parseBindingAtom();
13225 this.checkLVal(id, {
13226 in: {
13227 type: "VariableDeclarator"
13228 },
13229 binding: kind === "var" ? 5 : 8201
13230 });
13231 decl.id = id;
13232 }
13233 parseAsyncFunctionExpression(node) {
13234 return this.parseFunction(node, 8);
13235 }
13236 parseFunction(node, flags = 0) {
13237 const hangingDeclaration = flags & 2;
13238 const isDeclaration = !!(flags & 1);
13239 const requireId = isDeclaration && !(flags & 4);
13240 const isAsync = !!(flags & 8);
13241 this.initFunction(node, isAsync);
13242 if (this.match(55)) {
13243 if (hangingDeclaration) {
13244 this.raise(Errors.GeneratorInSingleStatementContext, {
13245 at: this.state.startLoc
13246 });
13247 }
13248 this.next();
13249 node.generator = true;
13250 }
13251 if (isDeclaration) {
13252 node.id = this.parseFunctionId(requireId);
13253 }
13254 const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
13255 this.state.maybeInArrowParameters = false;
13256 this.scope.enter(2);
13257 this.prodParam.enter(functionFlags(isAsync, node.generator));
13258 if (!isDeclaration) {
13259 node.id = this.parseFunctionId();
13260 }
13261 this.parseFunctionParams(node, false);
13262 this.withSmartMixTopicForbiddingContext(() => {
13263 this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
13264 });
13265 this.prodParam.exit();
13266 this.scope.exit();
13267 if (isDeclaration && !hangingDeclaration) {
13268 this.registerFunctionStatementId(node);
13269 }
13270 this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
13271 return node;
13272 }
13273 parseFunctionId(requireId) {
13274 return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
13275 }
13276 parseFunctionParams(node, isConstructor) {
13277 this.expect(10);
13278 this.expressionScope.enter(newParameterDeclarationScope());
13279 node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
13280 this.expressionScope.exit();
13281 }
13282 registerFunctionStatementId(node) {
13283 if (!node.id) return;
13284 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);
13285 }
13286 parseClass(node, isStatement, optionalId) {
13287 this.next();
13288 const oldStrict = this.state.strict;
13289 this.state.strict = true;
13290 this.parseClassId(node, isStatement, optionalId);
13291 this.parseClassSuper(node);
13292 node.body = this.parseClassBody(!!node.superClass, oldStrict);
13293 return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
13294 }
13295 isClassProperty() {
13296 return this.match(29) || this.match(13) || this.match(8);
13297 }
13298 isClassMethod() {
13299 return this.match(10);
13300 }
13301 isNonstaticConstructor(method) {
13302 return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
13303 }
13304 parseClassBody(hadSuperClass, oldStrict) {
13305 this.classScope.enter();
13306 const state = {
13307 hadConstructor: false,
13308 hadSuperClass
13309 };
13310 let decorators = [];
13311 const classBody = this.startNode();
13312 classBody.body = [];
13313 this.expect(5);
13314 this.withSmartMixTopicForbiddingContext(() => {
13315 while (!this.match(8)) {
13316 if (this.eat(13)) {
13317 if (decorators.length > 0) {
13318 throw this.raise(Errors.DecoratorSemicolon, {
13319 at: this.state.lastTokEndLoc
13320 });
13321 }
13322 continue;
13323 }
13324 if (this.match(26)) {
13325 decorators.push(this.parseDecorator());
13326 continue;
13327 }
13328 const member = this.startNode();
13329 if (decorators.length) {
13330 member.decorators = decorators;
13331 this.resetStartLocationFromNode(member, decorators[0]);
13332 decorators = [];
13333 }
13334 this.parseClassMember(classBody, member, state);
13335 if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
13336 this.raise(Errors.DecoratorConstructor, {
13337 at: member
13338 });
13339 }
13340 }
13341 });
13342 this.state.strict = oldStrict;
13343 this.next();
13344 if (decorators.length) {
13345 throw this.raise(Errors.TrailingDecorator, {
13346 at: this.state.startLoc
13347 });
13348 }
13349 this.classScope.exit();
13350 return this.finishNode(classBody, "ClassBody");
13351 }
13352 parseClassMemberFromModifier(classBody, member) {
13353 const key = this.parseIdentifier(true);
13354 if (this.isClassMethod()) {
13355 const method = member;
13356 method.kind = "method";
13357 method.computed = false;
13358 method.key = key;
13359 method.static = false;
13360 this.pushClassMethod(classBody, method, false, false, false, false);
13361 return true;
13362 } else if (this.isClassProperty()) {
13363 const prop = member;
13364 prop.computed = false;
13365 prop.key = key;
13366 prop.static = false;
13367 classBody.body.push(this.parseClassProperty(prop));
13368 return true;
13369 }
13370 this.resetPreviousNodeTrailingComments(key);
13371 return false;
13372 }
13373 parseClassMember(classBody, member, state) {
13374 const isStatic = this.isContextual(104);
13375 if (isStatic) {
13376 if (this.parseClassMemberFromModifier(classBody, member)) {
13377 return;
13378 }
13379 if (this.eat(5)) {
13380 this.parseClassStaticBlock(classBody, member);
13381 return;
13382 }
13383 }
13384 this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
13385 }
13386 parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
13387 const publicMethod = member;
13388 const privateMethod = member;
13389 const publicProp = member;
13390 const privateProp = member;
13391 const accessorProp = member;
13392 const method = publicMethod;
13393 const publicMember = publicMethod;
13394 member.static = isStatic;
13395 this.parsePropertyNamePrefixOperator(member);
13396 if (this.eat(55)) {
13397 method.kind = "method";
13398 const isPrivateName = this.match(136);
13399 this.parseClassElementName(method);
13400 if (isPrivateName) {
13401 this.pushClassPrivateMethod(classBody, privateMethod, true, false);
13402 return;
13403 }
13404 if (this.isNonstaticConstructor(publicMethod)) {
13405 this.raise(Errors.ConstructorIsGenerator, {
13406 at: publicMethod.key
13407 });
13408 }
13409 this.pushClassMethod(classBody, publicMethod, true, false, false, false);
13410 return;
13411 }
13412 const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
13413 const isPrivate = this.match(136);
13414 const key = this.parseClassElementName(member);
13415 const maybeQuestionTokenStartLoc = this.state.startLoc;
13416 this.parsePostMemberNameModifiers(publicMember);
13417 if (this.isClassMethod()) {
13418 method.kind = "method";
13419 if (isPrivate) {
13420 this.pushClassPrivateMethod(classBody, privateMethod, false, false);
13421 return;
13422 }
13423 const isConstructor = this.isNonstaticConstructor(publicMethod);
13424 let allowsDirectSuper = false;
13425 if (isConstructor) {
13426 publicMethod.kind = "constructor";
13427 if (state.hadConstructor && !this.hasPlugin("typescript")) {
13428 this.raise(Errors.DuplicateConstructor, {
13429 at: key
13430 });
13431 }
13432 if (isConstructor && this.hasPlugin("typescript") && member.override) {
13433 this.raise(Errors.OverrideOnConstructor, {
13434 at: key
13435 });
13436 }
13437 state.hadConstructor = true;
13438 allowsDirectSuper = state.hadSuperClass;
13439 }
13440 this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
13441 } else if (this.isClassProperty()) {
13442 if (isPrivate) {
13443 this.pushClassPrivateProperty(classBody, privateProp);
13444 } else {
13445 this.pushClassProperty(classBody, publicProp);
13446 }
13447 } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
13448 this.resetPreviousNodeTrailingComments(key);
13449 const isGenerator = this.eat(55);
13450 if (publicMember.optional) {
13451 this.unexpected(maybeQuestionTokenStartLoc);
13452 }
13453 method.kind = "method";
13454 const isPrivate = this.match(136);
13455 this.parseClassElementName(method);
13456 this.parsePostMemberNameModifiers(publicMember);
13457 if (isPrivate) {
13458 this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
13459 } else {
13460 if (this.isNonstaticConstructor(publicMethod)) {
13461 this.raise(Errors.ConstructorIsAsync, {
13462 at: publicMethod.key
13463 });
13464 }
13465 this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
13466 }
13467 } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
13468 this.resetPreviousNodeTrailingComments(key);
13469 method.kind = key.name;
13470 const isPrivate = this.match(136);
13471 this.parseClassElementName(publicMethod);
13472 if (isPrivate) {
13473 this.pushClassPrivateMethod(classBody, privateMethod, false, false);
13474 } else {
13475 if (this.isNonstaticConstructor(publicMethod)) {
13476 this.raise(Errors.ConstructorIsAccessor, {
13477 at: publicMethod.key
13478 });
13479 }
13480 this.pushClassMethod(classBody, publicMethod, false, false, false, false);
13481 }
13482 this.checkGetterSetterParams(publicMethod);
13483 } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
13484 this.expectPlugin("decoratorAutoAccessors");
13485 this.resetPreviousNodeTrailingComments(key);
13486 const isPrivate = this.match(136);
13487 this.parseClassElementName(publicProp);
13488 this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
13489 } else if (this.isLineTerminator()) {
13490 if (isPrivate) {
13491 this.pushClassPrivateProperty(classBody, privateProp);
13492 } else {
13493 this.pushClassProperty(classBody, publicProp);
13494 }
13495 } else {
13496 this.unexpected();
13497 }
13498 }
13499 parseClassElementName(member) {
13500 const {
13501 type,
13502 value
13503 } = this.state;
13504 if ((type === 130 || type === 131) && member.static && value === "prototype") {
13505 this.raise(Errors.StaticPrototype, {
13506 at: this.state.startLoc
13507 });
13508 }
13509 if (type === 136) {
13510 if (value === "constructor") {
13511 this.raise(Errors.ConstructorClassPrivateField, {
13512 at: this.state.startLoc
13513 });
13514 }
13515 const key = this.parsePrivateName();
13516 member.key = key;
13517 return key;
13518 }
13519 return this.parsePropertyName(member);
13520 }
13521 parseClassStaticBlock(classBody, member) {
13522 var _member$decorators;
13523 this.scope.enter(64 | 128 | 16);
13524 const oldLabels = this.state.labels;
13525 this.state.labels = [];
13526 this.prodParam.enter(PARAM);
13527 const body = member.body = [];
13528 this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
13529 this.prodParam.exit();
13530 this.scope.exit();
13531 this.state.labels = oldLabels;
13532 classBody.body.push(this.finishNode(member, "StaticBlock"));
13533 if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
13534 this.raise(Errors.DecoratorStaticBlock, {
13535 at: member
13536 });
13537 }
13538 }
13539 pushClassProperty(classBody, prop) {
13540 if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
13541 this.raise(Errors.ConstructorClassField, {
13542 at: prop.key
13543 });
13544 }
13545 classBody.body.push(this.parseClassProperty(prop));
13546 }
13547 pushClassPrivateProperty(classBody, prop) {
13548 const node = this.parseClassPrivateProperty(prop);
13549 classBody.body.push(node);
13550 this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
13551 }
13552 pushClassAccessorProperty(classBody, prop, isPrivate) {
13553 if (!isPrivate && !prop.computed) {
13554 const key = prop.key;
13555 if (key.name === "constructor" || key.value === "constructor") {
13556 this.raise(Errors.ConstructorClassField, {
13557 at: key
13558 });
13559 }
13560 }
13561 const node = this.parseClassAccessorProperty(prop);
13562 classBody.body.push(node);
13563 if (isPrivate) {
13564 this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
13565 }
13566 }
13567 pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
13568 classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
13569 }
13570 pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
13571 const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
13572 classBody.body.push(node);
13573 const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
13574 this.declareClassPrivateMethodInScope(node, kind);
13575 }
13576 declareClassPrivateMethodInScope(node, kind) {
13577 this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
13578 }
13579 parsePostMemberNameModifiers(methodOrProp) {}
13580 parseClassPrivateProperty(node) {
13581 this.parseInitializer(node);
13582 this.semicolon();
13583 return this.finishNode(node, "ClassPrivateProperty");
13584 }
13585 parseClassProperty(node) {
13586 this.parseInitializer(node);
13587 this.semicolon();
13588 return this.finishNode(node, "ClassProperty");
13589 }
13590 parseClassAccessorProperty(node) {
13591 this.parseInitializer(node);
13592 this.semicolon();
13593 return this.finishNode(node, "ClassAccessorProperty");
13594 }
13595 parseInitializer(node) {
13596 this.scope.enter(64 | 16);
13597 this.expressionScope.enter(newExpressionScope());
13598 this.prodParam.enter(PARAM);
13599 node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
13600 this.expressionScope.exit();
13601 this.prodParam.exit();
13602 this.scope.exit();
13603 }
13604 parseClassId(node, isStatement, optionalId, bindingType = 8331) {
13605 if (tokenIsIdentifier(this.state.type)) {
13606 node.id = this.parseIdentifier();
13607 if (isStatement) {
13608 this.declareNameFromIdentifier(node.id, bindingType);
13609 }
13610 } else {
13611 if (optionalId || !isStatement) {
13612 node.id = null;
13613 } else {
13614 throw this.raise(Errors.MissingClassName, {
13615 at: this.state.startLoc
13616 });
13617 }
13618 }
13619 }
13620 parseClassSuper(node) {
13621 node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
13622 }
13623 parseExport(node, decorators) {
13624 const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
13625 const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
13626 const parseAfterDefault = !hasDefault || this.eat(12);
13627 const hasStar = parseAfterDefault && this.eatExportStar(node);
13628 const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
13629 const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
13630 const isFromRequired = hasDefault || hasStar;
13631 if (hasStar && !hasNamespace) {
13632 if (hasDefault) this.unexpected();
13633 if (decorators) {
13634 throw this.raise(Errors.UnsupportedDecoratorExport, {
13635 at: node
13636 });
13637 }
13638 this.parseExportFrom(node, true);
13639 return this.finishNode(node, "ExportAllDeclaration");
13640 }
13641 const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
13642 if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
13643 this.unexpected(null, 5);
13644 }
13645 if (hasNamespace && parseAfterNamespace) {
13646 this.unexpected(null, 97);
13647 }
13648 let hasDeclaration;
13649 if (isFromRequired || hasSpecifiers) {
13650 hasDeclaration = false;
13651 if (decorators) {
13652 throw this.raise(Errors.UnsupportedDecoratorExport, {
13653 at: node
13654 });
13655 }
13656 this.parseExportFrom(node, isFromRequired);
13657 } else {
13658 hasDeclaration = this.maybeParseExportDeclaration(node);
13659 }
13660 if (isFromRequired || hasSpecifiers || hasDeclaration) {
13661 var _node2$declaration;
13662 const node2 = node;
13663 this.checkExport(node2, true, false, !!node2.source);
13664 if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
13665 this.maybeTakeDecorators(decorators, node2.declaration, node2);
13666 } else if (decorators) {
13667 throw this.raise(Errors.UnsupportedDecoratorExport, {
13668 at: node
13669 });
13670 }
13671 return this.finishNode(node2, "ExportNamedDeclaration");
13672 }
13673 if (this.eat(65)) {
13674 const node2 = node;
13675 const decl = this.parseExportDefaultExpression();
13676 node2.declaration = decl;
13677 if (decl.type === "ClassDeclaration") {
13678 this.maybeTakeDecorators(decorators, decl, node2);
13679 } else if (decorators) {
13680 throw this.raise(Errors.UnsupportedDecoratorExport, {
13681 at: node
13682 });
13683 }
13684 this.checkExport(node2, true, true);
13685 return this.finishNode(node2, "ExportDefaultDeclaration");
13686 }
13687 this.unexpected(null, 5);
13688 }
13689 eatExportStar(node) {
13690 return this.eat(55);
13691 }
13692 maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
13693 if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
13694 this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
13695 const id = maybeDefaultIdentifier || this.parseIdentifier(true);
13696 const specifier = this.startNodeAtNode(id);
13697 specifier.exported = id;
13698 node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
13699 return true;
13700 }
13701 return false;
13702 }
13703 maybeParseExportNamespaceSpecifier(node) {
13704 if (this.isContextual(93)) {
13705 if (!node.specifiers) node.specifiers = [];
13706 const specifier = this.startNodeAt(this.state.lastTokStartLoc);
13707 this.next();
13708 specifier.exported = this.parseModuleExportName();
13709 node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
13710 return true;
13711 }
13712 return false;
13713 }
13714 maybeParseExportNamedSpecifiers(node) {
13715 if (this.match(5)) {
13716 if (!node.specifiers) node.specifiers = [];
13717 const isTypeExport = node.exportKind === "type";
13718 node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
13719 node.source = null;
13720 node.declaration = null;
13721 if (this.hasPlugin("importAssertions")) {
13722 node.assertions = [];
13723 }
13724 return true;
13725 }
13726 return false;
13727 }
13728 maybeParseExportDeclaration(node) {
13729 if (this.shouldParseExportDeclaration()) {
13730 node.specifiers = [];
13731 node.source = null;
13732 if (this.hasPlugin("importAssertions")) {
13733 node.assertions = [];
13734 }
13735 node.declaration = this.parseExportDeclaration(node);
13736 return true;
13737 }
13738 return false;
13739 }
13740 isAsyncFunction() {
13741 if (!this.isContextual(95)) return false;
13742 const next = this.nextTokenInLineStart();
13743 return this.isUnparsedContextual(next, "function");
13744 }
13745 parseExportDefaultExpression() {
13746 const expr = this.startNode();
13747 if (this.match(68)) {
13748 this.next();
13749 return this.parseFunction(expr, 1 | 4);
13750 } else if (this.isAsyncFunction()) {
13751 this.next();
13752 this.next();
13753 return this.parseFunction(expr, 1 | 4 | 8);
13754 }
13755 if (this.match(80)) {
13756 return this.parseClass(expr, true, true);
13757 }
13758 if (this.match(26)) {
13759 if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
13760 this.raise(Errors.DecoratorBeforeExport, {
13761 at: this.state.startLoc
13762 });
13763 }
13764 return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
13765 }
13766 if (this.match(75) || this.match(74) || this.isLet()) {
13767 throw this.raise(Errors.UnsupportedDefaultExport, {
13768 at: this.state.startLoc
13769 });
13770 }
13771 const res = this.parseMaybeAssignAllowIn();
13772 this.semicolon();
13773 return res;
13774 }
13775 parseExportDeclaration(node) {
13776 if (this.match(80)) {
13777 const node = this.parseClass(this.startNode(), true, false);
13778 return node;
13779 }
13780 return this.parseStatementListItem();
13781 }
13782 isExportDefaultSpecifier() {
13783 const {
13784 type
13785 } = this.state;
13786 if (tokenIsIdentifier(type)) {
13787 if (type === 95 && !this.state.containsEsc || type === 99) {
13788 return false;
13789 }
13790 if ((type === 128 || type === 127) && !this.state.containsEsc) {
13791 const {
13792 type: nextType
13793 } = this.lookahead();
13794 if (tokenIsIdentifier(nextType) && nextType !== 97 || nextType === 5) {
13795 this.expectOnePlugin(["flow", "typescript"]);
13796 return false;
13797 }
13798 }
13799 } else if (!this.match(65)) {
13800 return false;
13801 }
13802 const next = this.nextTokenStart();
13803 const hasFrom = this.isUnparsedContextual(next, "from");
13804 if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
13805 return true;
13806 }
13807 if (this.match(65) && hasFrom) {
13808 const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
13809 return nextAfterFrom === 34 || nextAfterFrom === 39;
13810 }
13811 return false;
13812 }
13813 parseExportFrom(node, expect) {
13814 if (this.eatContextual(97)) {
13815 node.source = this.parseImportSource();
13816 this.checkExport(node);
13817 this.maybeParseImportAttributes(node);
13818 this.checkJSONModuleImport(node);
13819 } else if (expect) {
13820 this.unexpected();
13821 }
13822 this.semicolon();
13823 }
13824 shouldParseExportDeclaration() {
13825 const {
13826 type
13827 } = this.state;
13828 if (type === 26) {
13829 this.expectOnePlugin(["decorators", "decorators-legacy"]);
13830 if (this.hasPlugin("decorators")) {
13831 if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
13832 this.raise(Errors.DecoratorBeforeExport, {
13833 at: this.state.startLoc
13834 });
13835 }
13836 return true;
13837 }
13838 }
13839 return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
13840 }
13841 checkExport(node, checkNames, isDefault, isFrom) {
13842 if (checkNames) {
13843 var _node$specifiers;
13844 if (isDefault) {
13845 this.checkDuplicateExports(node, "default");
13846 if (this.hasPlugin("exportDefaultFrom")) {
13847 var _declaration$extra;
13848 const declaration = node.declaration;
13849 if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
13850 this.raise(Errors.ExportDefaultFromAsIdentifier, {
13851 at: declaration
13852 });
13853 }
13854 }
13855 } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
13856 for (const specifier of node.specifiers) {
13857 const {
13858 exported
13859 } = specifier;
13860 const exportName = exported.type === "Identifier" ? exported.name : exported.value;
13861 this.checkDuplicateExports(specifier, exportName);
13862 if (!isFrom && specifier.local) {
13863 const {
13864 local
13865 } = specifier;
13866 if (local.type !== "Identifier") {
13867 this.raise(Errors.ExportBindingIsString, {
13868 at: specifier,
13869 localName: local.value,
13870 exportName
13871 });
13872 } else {
13873 this.checkReservedWord(local.name, local.loc.start, true, false);
13874 this.scope.checkLocalExport(local);
13875 }
13876 }
13877 }
13878 } else if (node.declaration) {
13879 if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
13880 const id = node.declaration.id;
13881 if (!id) throw new Error("Assertion failure");
13882 this.checkDuplicateExports(node, id.name);
13883 } else if (node.declaration.type === "VariableDeclaration") {
13884 for (const declaration of node.declaration.declarations) {
13885 this.checkDeclaration(declaration.id);
13886 }
13887 }
13888 }
13889 }
13890 }
13891 checkDeclaration(node) {
13892 if (node.type === "Identifier") {
13893 this.checkDuplicateExports(node, node.name);
13894 } else if (node.type === "ObjectPattern") {
13895 for (const prop of node.properties) {
13896 this.checkDeclaration(prop);
13897 }
13898 } else if (node.type === "ArrayPattern") {
13899 for (const elem of node.elements) {
13900 if (elem) {
13901 this.checkDeclaration(elem);
13902 }
13903 }
13904 } else if (node.type === "ObjectProperty") {
13905 this.checkDeclaration(node.value);
13906 } else if (node.type === "RestElement") {
13907 this.checkDeclaration(node.argument);
13908 } else if (node.type === "AssignmentPattern") {
13909 this.checkDeclaration(node.left);
13910 }
13911 }
13912 checkDuplicateExports(node, exportName) {
13913 if (this.exportedIdentifiers.has(exportName)) {
13914 if (exportName === "default") {
13915 this.raise(Errors.DuplicateDefaultExport, {
13916 at: node
13917 });
13918 } else {
13919 this.raise(Errors.DuplicateExport, {
13920 at: node,
13921 exportName
13922 });
13923 }
13924 }
13925 this.exportedIdentifiers.add(exportName);
13926 }
13927 parseExportSpecifiers(isInTypeExport) {
13928 const nodes = [];
13929 let first = true;
13930 this.expect(5);
13931 while (!this.eat(8)) {
13932 if (first) {
13933 first = false;
13934 } else {
13935 this.expect(12);
13936 if (this.eat(8)) break;
13937 }
13938 const isMaybeTypeOnly = this.isContextual(128);
13939 const isString = this.match(131);
13940 const node = this.startNode();
13941 node.local = this.parseModuleExportName();
13942 nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
13943 }
13944 return nodes;
13945 }
13946 parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
13947 if (this.eatContextual(93)) {
13948 node.exported = this.parseModuleExportName();
13949 } else if (isString) {
13950 node.exported = cloneStringLiteral(node.local);
13951 } else if (!node.exported) {
13952 node.exported = cloneIdentifier(node.local);
13953 }
13954 return this.finishNode(node, "ExportSpecifier");
13955 }
13956 parseModuleExportName() {
13957 if (this.match(131)) {
13958 const result = this.parseStringLiteral(this.state.value);
13959 const surrogate = result.value.match(loneSurrogate);
13960 if (surrogate) {
13961 this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
13962 at: result,
13963 surrogateCharCode: surrogate[0].charCodeAt(0)
13964 });
13965 }
13966 return result;
13967 }
13968 return this.parseIdentifier(true);
13969 }
13970 isJSONModuleImport(node) {
13971 if (node.assertions != null) {
13972 return node.assertions.some(({
13973 key,
13974 value
13975 }) => {
13976 return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
13977 });
13978 }
13979 return false;
13980 }
13981 checkImportReflection(node) {
13982 if (node.module) {
13983 var _node$assertions;
13984 if (node.specifiers.length !== 1 || node.specifiers[0].type !== "ImportDefaultSpecifier") {
13985 this.raise(Errors.ImportReflectionNotBinding, {
13986 at: node.specifiers[0].loc.start
13987 });
13988 }
13989 if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
13990 this.raise(Errors.ImportReflectionHasAssertion, {
13991 at: node.specifiers[0].loc.start
13992 });
13993 }
13994 }
13995 }
13996 checkJSONModuleImport(node) {
13997 if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
13998 const {
13999 specifiers
14000 } = node;
14001 if (specifiers != null) {
14002 const nonDefaultNamedSpecifier = specifiers.find(specifier => {
14003 let imported;
14004 if (specifier.type === "ExportSpecifier") {
14005 imported = specifier.local;
14006 } else if (specifier.type === "ImportSpecifier") {
14007 imported = specifier.imported;
14008 }
14009 if (imported !== undefined) {
14010 return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
14011 }
14012 });
14013 if (nonDefaultNamedSpecifier !== undefined) {
14014 this.raise(Errors.ImportJSONBindingNotDefault, {
14015 at: nonDefaultNamedSpecifier.loc.start
14016 });
14017 }
14018 }
14019 }
14020 }
14021 isPotentialImportPhase(isExport) {
14022 return !isExport && this.isContextual(125);
14023 }
14024 applyImportPhase(node, isExport, phase, loc) {
14025 if (isExport) {
14026 return;
14027 }
14028 if (phase === "module") {
14029 this.expectPlugin("importReflection", loc);
14030 node.module = true;
14031 } else if (this.hasPlugin("importReflection")) {
14032 node.module = false;
14033 }
14034 }
14035 parseMaybeImportPhase(node, isExport) {
14036 if (!this.isPotentialImportPhase(isExport)) {
14037 this.applyImportPhase(node, isExport, null);
14038 return null;
14039 }
14040 const phaseIdentifier = this.parseIdentifier(true);
14041 const {
14042 type
14043 } = this.state;
14044 const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 97 || this.lookaheadCharCode() === 102 : type !== 12;
14045 if (isImportPhase) {
14046 this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
14047 this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
14048 return null;
14049 } else {
14050 this.applyImportPhase(node, isExport, null);
14051 return phaseIdentifier;
14052 }
14053 }
14054 isPrecedingIdImportPhase(phase) {
14055 const {
14056 type
14057 } = this.state;
14058 return tokenIsIdentifier(type) ? type !== 97 || this.lookaheadCharCode() === 102 : type !== 12;
14059 }
14060 parseImport(node) {
14061 if (this.match(131)) {
14062 return this.parseImportSourceAndAttributes(node);
14063 }
14064 return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
14065 }
14066 parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
14067 node.specifiers = [];
14068 const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
14069 const parseNext = !hasDefault || this.eat(12);
14070 const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
14071 if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
14072 this.expectContextual(97);
14073 return this.parseImportSourceAndAttributes(node);
14074 }
14075 parseImportSourceAndAttributes(node) {
14076 var _node$specifiers2;
14077 (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
14078 node.source = this.parseImportSource();
14079 this.maybeParseImportAttributes(node);
14080 this.checkImportReflection(node);
14081 this.checkJSONModuleImport(node);
14082 this.semicolon();
14083 return this.finishNode(node, "ImportDeclaration");
14084 }
14085 parseImportSource() {
14086 if (!this.match(131)) this.unexpected();
14087 return this.parseExprAtom();
14088 }
14089 parseImportSpecifierLocal(node, specifier, type) {
14090 specifier.local = this.parseIdentifier();
14091 node.specifiers.push(this.finishImportSpecifier(specifier, type));
14092 }
14093 finishImportSpecifier(specifier, type, bindingType = 8201) {
14094 this.checkLVal(specifier.local, {
14095 in: {
14096 type
14097 },
14098 binding: bindingType
14099 });
14100 return this.finishNode(specifier, type);
14101 }
14102 parseImportAttributes() {
14103 this.expect(5);
14104 const attrs = [];
14105 const attrNames = new Set();
14106 do {
14107 if (this.match(8)) {
14108 break;
14109 }
14110 const node = this.startNode();
14111 const keyName = this.state.value;
14112 if (attrNames.has(keyName)) {
14113 this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
14114 at: this.state.startLoc,
14115 key: keyName
14116 });
14117 }
14118 attrNames.add(keyName);
14119 if (this.match(131)) {
14120 node.key = this.parseStringLiteral(keyName);
14121 } else {
14122 node.key = this.parseIdentifier(true);
14123 }
14124 this.expect(14);
14125 if (!this.match(131)) {
14126 throw this.raise(Errors.ModuleAttributeInvalidValue, {
14127 at: this.state.startLoc
14128 });
14129 }
14130 node.value = this.parseStringLiteral(this.state.value);
14131 attrs.push(this.finishNode(node, "ImportAttribute"));
14132 } while (this.eat(12));
14133 this.expect(8);
14134 return attrs;
14135 }
14136 parseModuleAttributes() {
14137 const attrs = [];
14138 const attributes = new Set();
14139 do {
14140 const node = this.startNode();
14141 node.key = this.parseIdentifier(true);
14142 if (node.key.name !== "type") {
14143 this.raise(Errors.ModuleAttributeDifferentFromType, {
14144 at: node.key
14145 });
14146 }
14147 if (attributes.has(node.key.name)) {
14148 this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
14149 at: node.key,
14150 key: node.key.name
14151 });
14152 }
14153 attributes.add(node.key.name);
14154 this.expect(14);
14155 if (!this.match(131)) {
14156 throw this.raise(Errors.ModuleAttributeInvalidValue, {
14157 at: this.state.startLoc
14158 });
14159 }
14160 node.value = this.parseStringLiteral(this.state.value);
14161 attrs.push(this.finishNode(node, "ImportAttribute"));
14162 } while (this.eat(12));
14163 return attrs;
14164 }
14165 maybeParseImportAttributes(node) {
14166 let attributes;
14167 let useWith = false;
14168 if (this.match(76)) {
14169 if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
14170 return;
14171 }
14172 this.next();
14173 {
14174 if (this.hasPlugin("moduleAttributes")) {
14175 attributes = this.parseModuleAttributes();
14176 } else {
14177 this.expectImportAttributesPlugin();
14178 attributes = this.parseImportAttributes();
14179 }
14180 }
14181 useWith = true;
14182 } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
14183 if (this.hasPlugin("importAttributes")) {
14184 if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) {
14185 this.raise(Errors.ImportAttributesUseAssert, {
14186 at: this.state.startLoc
14187 });
14188 }
14189 this.addExtra(node, "deprecatedAssertSyntax", true);
14190 } else {
14191 this.expectOnePlugin(["importAttributes", "importAssertions"]);
14192 }
14193 this.next();
14194 attributes = this.parseImportAttributes();
14195 } else if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
14196 attributes = [];
14197 } else {
14198 if (this.hasPlugin("moduleAttributes")) {
14199 attributes = [];
14200 } else return;
14201 }
14202 if (!useWith && this.hasPlugin("importAssertions")) {
14203 node.assertions = attributes;
14204 } else {
14205 node.attributes = attributes;
14206 }
14207 }
14208 maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
14209 if (maybeDefaultIdentifier) {
14210 const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
14211 specifier.local = maybeDefaultIdentifier;
14212 node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
14213 return true;
14214 } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
14215 this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
14216 return true;
14217 }
14218 return false;
14219 }
14220 maybeParseStarImportSpecifier(node) {
14221 if (this.match(55)) {
14222 const specifier = this.startNode();
14223 this.next();
14224 this.expectContextual(93);
14225 this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
14226 return true;
14227 }
14228 return false;
14229 }
14230 parseNamedImportSpecifiers(node) {
14231 let first = true;
14232 this.expect(5);
14233 while (!this.eat(8)) {
14234 if (first) {
14235 first = false;
14236 } else {
14237 if (this.eat(14)) {
14238 throw this.raise(Errors.DestructureNamedImport, {
14239 at: this.state.startLoc
14240 });
14241 }
14242 this.expect(12);
14243 if (this.eat(8)) break;
14244 }
14245 const specifier = this.startNode();
14246 const importedIsString = this.match(131);
14247 const isMaybeTypeOnly = this.isContextual(128);
14248 specifier.imported = this.parseModuleExportName();
14249 const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
14250 node.specifiers.push(importSpecifier);
14251 }
14252 }
14253 parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
14254 if (this.eatContextual(93)) {
14255 specifier.local = this.parseIdentifier();
14256 } else {
14257 const {
14258 imported
14259 } = specifier;
14260 if (importedIsString) {
14261 throw this.raise(Errors.ImportBindingIsString, {
14262 at: specifier,
14263 importName: imported.value
14264 });
14265 }
14266 this.checkReservedWord(imported.name, specifier.loc.start, true, true);
14267 if (!specifier.local) {
14268 specifier.local = cloneIdentifier(imported);
14269 }
14270 }
14271 return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
14272 }
14273 isThisParam(param) {
14274 return param.type === "Identifier" && param.name === "this";
14275 }
14276}
14277class Parser extends StatementParser {
14278 constructor(options, input) {
14279 options = getOptions(options);
14280 super(options, input);
14281 this.options = options;
14282 this.initializeScopes();
14283 this.plugins = pluginsMap(this.options.plugins);
14284 this.filename = options.sourceFilename;
14285 }
14286 getScopeHandler() {
14287 return ScopeHandler;
14288 }
14289 parse() {
14290 this.enterInitialScopes();
14291 const file = this.startNode();
14292 const program = this.startNode();
14293 this.nextToken();
14294 file.errors = null;
14295 this.parseTopLevel(file, program);
14296 file.errors = this.state.errors;
14297 return file;
14298 }
14299}
14300function pluginsMap(plugins) {
14301 const pluginMap = new Map();
14302 for (const plugin of plugins) {
14303 const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
14304 if (!pluginMap.has(name)) pluginMap.set(name, options || {});
14305 }
14306 return pluginMap;
14307}
14308function parse(input, options) {
14309 var _options;
14310 if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
14311 options = Object.assign({}, options);
14312 try {
14313 options.sourceType = "module";
14314 const parser = getParser(options, input);
14315 const ast = parser.parse();
14316 if (parser.sawUnambiguousESM) {
14317 return ast;
14318 }
14319 if (parser.ambiguousScriptDifferentAst) {
14320 try {
14321 options.sourceType = "script";
14322 return getParser(options, input).parse();
14323 } catch (_unused) {}
14324 } else {
14325 ast.program.sourceType = "script";
14326 }
14327 return ast;
14328 } catch (moduleError) {
14329 try {
14330 options.sourceType = "script";
14331 return getParser(options, input).parse();
14332 } catch (_unused2) {}
14333 throw moduleError;
14334 }
14335 } else {
14336 return getParser(options, input).parse();
14337 }
14338}
14339function parseExpression(input, options) {
14340 const parser = getParser(options, input);
14341 if (parser.options.strictMode) {
14342 parser.state.strict = true;
14343 }
14344 return parser.getExpression();
14345}
14346function generateExportedTokenTypes(internalTokenTypes) {
14347 const tokenTypes = {};
14348 for (const typeName of Object.keys(internalTokenTypes)) {
14349 tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
14350 }
14351 return tokenTypes;
14352}
14353const tokTypes = generateExportedTokenTypes(tt);
14354function getParser(options, input) {
14355 let cls = Parser;
14356 if (options != null && options.plugins) {
14357 validatePlugins(options.plugins);
14358 cls = getParserClass(options.plugins);
14359 }
14360 return new cls(options, input);
14361}
14362const parserClassCache = {};
14363function getParserClass(pluginsFromOptions) {
14364 const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
14365 const key = pluginList.join("/");
14366 let cls = parserClassCache[key];
14367 if (!cls) {
14368 cls = Parser;
14369 for (const plugin of pluginList) {
14370 cls = mixinPlugins[plugin](cls);
14371 }
14372 parserClassCache[key] = cls;
14373 }
14374 return cls;
14375}
14376exports.parse = parse;
14377exports.parseExpression = parseExpression;
14378exports.tokTypes = tokTypes;
14379//# sourceMappingURL=index.js.map