@tinacms/app 1.0.7 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/appFiles/node_modules/.package-lock.json +29 -28
  2. package/appFiles/node_modules/@babel/generator/lib/buffer.js +34 -10
  3. package/appFiles/node_modules/@babel/generator/lib/buffer.js.map +1 -1
  4. package/appFiles/node_modules/@babel/generator/lib/generators/classes.js +3 -4
  5. package/appFiles/node_modules/@babel/generator/lib/generators/classes.js.map +1 -1
  6. package/appFiles/node_modules/@babel/generator/lib/generators/expressions.js +7 -0
  7. package/appFiles/node_modules/@babel/generator/lib/generators/expressions.js.map +1 -1
  8. package/appFiles/node_modules/@babel/generator/lib/generators/methods.js +51 -8
  9. package/appFiles/node_modules/@babel/generator/lib/generators/methods.js.map +1 -1
  10. package/appFiles/node_modules/@babel/generator/lib/generators/modules.js +7 -10
  11. package/appFiles/node_modules/@babel/generator/lib/generators/modules.js.map +1 -1
  12. package/appFiles/node_modules/@babel/generator/lib/generators/types.js +2 -0
  13. package/appFiles/node_modules/@babel/generator/lib/generators/types.js.map +1 -1
  14. package/appFiles/node_modules/@babel/generator/lib/generators/typescript.js +2 -2
  15. package/appFiles/node_modules/@babel/generator/lib/generators/typescript.js.map +1 -1
  16. package/appFiles/node_modules/@babel/generator/lib/index.js +1 -1
  17. package/appFiles/node_modules/@babel/generator/lib/index.js.map +1 -1
  18. package/appFiles/node_modules/@babel/generator/lib/node/parentheses.js.map +1 -1
  19. package/appFiles/node_modules/@babel/generator/lib/printer.js +7 -0
  20. package/appFiles/node_modules/@babel/generator/lib/printer.js.map +1 -1
  21. package/appFiles/node_modules/@babel/generator/lib/source-map.js +40 -9
  22. package/appFiles/node_modules/@babel/generator/lib/source-map.js.map +1 -1
  23. package/appFiles/node_modules/@babel/generator/package.json +5 -5
  24. package/appFiles/node_modules/@babel/helper-function-name/lib/index.js +0 -31
  25. package/appFiles/node_modules/@babel/helper-function-name/lib/index.js.map +1 -1
  26. package/appFiles/node_modules/@babel/helper-function-name/package.json +3 -3
  27. package/appFiles/node_modules/@babel/parser/lib/index.js +1901 -1885
  28. package/appFiles/node_modules/@babel/parser/lib/index.js.map +1 -1
  29. package/appFiles/node_modules/@babel/parser/package.json +2 -2
  30. package/appFiles/node_modules/@babel/parser/typings/babel-parser.d.ts +12 -0
  31. package/appFiles/node_modules/@babel/runtime/helpers/applyDecs2203R.js +173 -170
  32. package/appFiles/node_modules/@babel/runtime/helpers/applyDecs2301.js +221 -0
  33. package/appFiles/node_modules/@babel/runtime/helpers/esm/applyDecs2203R.js +173 -170
  34. package/appFiles/node_modules/@babel/runtime/helpers/esm/applyDecs2301.js +220 -0
  35. package/appFiles/node_modules/@babel/runtime/package.json +10 -1
  36. package/appFiles/node_modules/@babel/traverse/lib/path/modification.js.map +1 -1
  37. package/appFiles/node_modules/@babel/traverse/lib/visitors.js +11 -5
  38. package/appFiles/node_modules/@babel/traverse/lib/visitors.js.map +1 -1
  39. package/appFiles/node_modules/@babel/traverse/package.json +5 -5
  40. package/appFiles/node_modules/@babel/types/lib/asserts/generated/index.js +12 -7
  41. package/appFiles/node_modules/@babel/types/lib/asserts/generated/index.js.map +1 -1
  42. package/appFiles/node_modules/@babel/types/lib/ast-types/generated/index.js.map +1 -1
  43. package/appFiles/node_modules/@babel/types/lib/builders/generated/index.js +5 -5
  44. package/appFiles/node_modules/@babel/types/lib/builders/generated/index.js.map +1 -1
  45. package/appFiles/node_modules/@babel/types/lib/clone/cloneNode.js +2 -6
  46. package/appFiles/node_modules/@babel/types/lib/clone/cloneNode.js.map +1 -1
  47. package/appFiles/node_modules/@babel/types/lib/constants/generated/index.js +5 -4
  48. package/appFiles/node_modules/@babel/types/lib/constants/generated/index.js.map +1 -1
  49. package/appFiles/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js +0 -3
  50. package/appFiles/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js.map +1 -1
  51. package/appFiles/node_modules/@babel/types/lib/converters/toComputedKey.js +1 -2
  52. package/appFiles/node_modules/@babel/types/lib/converters/toComputedKey.js.map +1 -1
  53. package/appFiles/node_modules/@babel/types/lib/converters/toExpression.js +0 -3
  54. package/appFiles/node_modules/@babel/types/lib/converters/toExpression.js.map +1 -1
  55. package/appFiles/node_modules/@babel/types/lib/converters/toIdentifier.js +0 -3
  56. package/appFiles/node_modules/@babel/types/lib/converters/toIdentifier.js.map +1 -1
  57. package/appFiles/node_modules/@babel/types/lib/converters/toKeyAlias.js +0 -3
  58. package/appFiles/node_modules/@babel/types/lib/converters/toKeyAlias.js.map +1 -1
  59. package/appFiles/node_modules/@babel/types/lib/converters/toSequenceExpression.js +0 -1
  60. package/appFiles/node_modules/@babel/types/lib/converters/toSequenceExpression.js.map +1 -1
  61. package/appFiles/node_modules/@babel/types/lib/converters/toStatement.js +0 -3
  62. package/appFiles/node_modules/@babel/types/lib/converters/toStatement.js.map +1 -1
  63. package/appFiles/node_modules/@babel/types/lib/converters/valueToNode.js +1 -9
  64. package/appFiles/node_modules/@babel/types/lib/converters/valueToNode.js.map +1 -1
  65. package/appFiles/node_modules/@babel/types/lib/definitions/core.js +21 -57
  66. package/appFiles/node_modules/@babel/types/lib/definitions/core.js.map +1 -1
  67. package/appFiles/node_modules/@babel/types/lib/definitions/deprecated-aliases.js +12 -0
  68. package/appFiles/node_modules/@babel/types/lib/definitions/deprecated-aliases.js.map +1 -0
  69. package/appFiles/node_modules/@babel/types/lib/definitions/experimental.js +0 -3
  70. package/appFiles/node_modules/@babel/types/lib/definitions/experimental.js.map +1 -1
  71. package/appFiles/node_modules/@babel/types/lib/definitions/flow.js +0 -1
  72. package/appFiles/node_modules/@babel/types/lib/definitions/flow.js.map +1 -1
  73. package/appFiles/node_modules/@babel/types/lib/definitions/index.js +10 -0
  74. package/appFiles/node_modules/@babel/types/lib/definitions/index.js.map +1 -1
  75. package/appFiles/node_modules/@babel/types/lib/definitions/typescript.js +6 -4
  76. package/appFiles/node_modules/@babel/types/lib/definitions/typescript.js.map +1 -1
  77. package/appFiles/node_modules/@babel/types/lib/definitions/utils.js +0 -2
  78. package/appFiles/node_modules/@babel/types/lib/definitions/utils.js.map +1 -1
  79. package/appFiles/node_modules/@babel/types/lib/index-legacy.d.ts +10 -3
  80. package/appFiles/node_modules/@babel/types/lib/index.d.ts +23 -6
  81. package/appFiles/node_modules/@babel/types/lib/index.js +9 -2
  82. package/appFiles/node_modules/@babel/types/lib/index.js.flow +8 -3
  83. package/appFiles/node_modules/@babel/types/lib/index.js.map +1 -1
  84. package/appFiles/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js +1 -9
  85. package/appFiles/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js.map +1 -1
  86. package/appFiles/node_modules/@babel/types/lib/modifications/inherits.js +0 -3
  87. package/appFiles/node_modules/@babel/types/lib/modifications/inherits.js.map +1 -1
  88. package/appFiles/node_modules/@babel/types/lib/modifications/removeProperties.js +1 -3
  89. package/appFiles/node_modules/@babel/types/lib/modifications/removeProperties.js.map +1 -1
  90. package/appFiles/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js +0 -8
  91. package/appFiles/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js.map +1 -1
  92. package/appFiles/node_modules/@babel/types/lib/retrievers/getBindingIdentifiers.js +2 -6
  93. package/appFiles/node_modules/@babel/types/lib/retrievers/getBindingIdentifiers.js.map +1 -1
  94. package/appFiles/node_modules/@babel/types/lib/traverse/traverseFast.js +1 -2
  95. package/appFiles/node_modules/@babel/types/lib/traverse/traverseFast.js.map +1 -1
  96. package/appFiles/node_modules/@babel/types/lib/utils/deprecationWarning.js +30 -0
  97. package/appFiles/node_modules/@babel/types/lib/utils/deprecationWarning.js.map +1 -0
  98. package/appFiles/node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js +0 -3
  99. package/appFiles/node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js.map +1 -1
  100. package/appFiles/node_modules/@babel/types/lib/utils/shallowEqual.js +1 -2
  101. package/appFiles/node_modules/@babel/types/lib/utils/shallowEqual.js.map +1 -1
  102. package/appFiles/node_modules/@babel/types/lib/validators/generated/index.js +11 -6
  103. package/appFiles/node_modules/@babel/types/lib/validators/generated/index.js.map +1 -1
  104. package/appFiles/node_modules/@babel/types/lib/validators/isBinding.js +2 -4
  105. package/appFiles/node_modules/@babel/types/lib/validators/isBinding.js.map +1 -1
  106. package/appFiles/node_modules/@babel/types/lib/validators/isLet.js +1 -2
  107. package/appFiles/node_modules/@babel/types/lib/validators/isLet.js.map +1 -1
  108. package/appFiles/node_modules/@babel/types/lib/validators/isNodesEquivalent.js +1 -2
  109. package/appFiles/node_modules/@babel/types/lib/validators/isNodesEquivalent.js.map +1 -1
  110. package/appFiles/node_modules/@babel/types/lib/validators/isReferenced.js +0 -21
  111. package/appFiles/node_modules/@babel/types/lib/validators/isReferenced.js.map +1 -1
  112. package/appFiles/node_modules/@babel/types/lib/validators/isScope.js +0 -1
  113. package/appFiles/node_modules/@babel/types/lib/validators/isScope.js.map +1 -1
  114. package/appFiles/node_modules/@babel/types/lib/validators/isSpecifierDefault.js +1 -2
  115. package/appFiles/node_modules/@babel/types/lib/validators/isSpecifierDefault.js.map +1 -1
  116. package/appFiles/node_modules/@babel/types/lib/validators/isType.js +0 -1
  117. package/appFiles/node_modules/@babel/types/lib/validators/isType.js.map +1 -1
  118. package/appFiles/node_modules/@babel/types/lib/validators/isValidES3Identifier.js +0 -1
  119. package/appFiles/node_modules/@babel/types/lib/validators/isValidES3Identifier.js.map +1 -1
  120. package/appFiles/node_modules/@babel/types/lib/validators/isVar.js +1 -2
  121. package/appFiles/node_modules/@babel/types/lib/validators/isVar.js.map +1 -1
  122. package/appFiles/node_modules/@babel/types/package.json +3 -3
  123. package/appFiles/node_modules/css-to-react-native/index.d.ts +17 -0
  124. package/appFiles/node_modules/css-to-react-native/index.js +15 -0
  125. package/appFiles/node_modules/css-to-react-native/package.json +2 -1
  126. package/appFiles/node_modules/css-to-react-native/src/__tests__/aspectRatio.js +23 -0
  127. package/appFiles/node_modules/css-to-react-native/src/transforms/aspectRatio.js +12 -0
  128. package/appFiles/node_modules/css-to-react-native/src/transforms/index.js +2 -0
  129. package/appFiles/src/App.tsx +3 -5
  130. package/appFiles/src/fields/rich-text/monaco/mdx.js +8573 -3668
  131. package/appFiles/src/lib/machines/query-machine.ts +0 -13
  132. package/appFiles/src/preview.tsx +22 -0
  133. package/dist/index.js +3 -1
  134. package/package.json +4 -4
@@ -128,9 +128,10 @@ var StandardErrors = {
128
128
  kind
129
129
  }) => `Missing initializer in ${kind} declaration.`,
130
130
  DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
131
- DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax.",
131
+ DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
132
+ DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
132
133
  DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
133
- DecoratorExportClass: "Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead.",
134
+ DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
134
135
  DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
135
136
  DecoratorStaticBlock: "Decorators can't be used with a static block.",
136
137
  DeletePrivateField: "Deleting a private field is not allowed.",
@@ -258,7 +259,8 @@ var StandardErrors = {
258
259
  RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
259
260
  RecordNoProto: "'__proto__' is not allowed in Record expressions.",
260
261
  RestTrailingComma: "Unexpected trailing comma after rest element.",
261
- SloppyFunction: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
262
+ SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
263
+ 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.",
262
264
  StaticPrototype: "Classes may not have static property named prototype.",
263
265
  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?",
264
266
  SuperPrivateField: "Private fields can't be accessed on super.",
@@ -735,9 +737,6 @@ var estree = (superClass => class ESTreeParserMixin extends superClass {
735
737
  }
736
738
  return super.hasPropertyAsPrivateName(node);
737
739
  }
738
- isOptionalChain(node) {
739
- return node.type === "ChainExpression";
740
- }
741
740
  isObjectProperty(node) {
742
741
  return node.type === "Property" && node.kind === "init" && !node.method;
743
742
  }
@@ -2475,7 +2474,7 @@ class Tokenizer extends CommentsParser {
2475
2474
  default:
2476
2475
  if (isWhitespace(ch)) {
2477
2476
  ++this.state.pos;
2478
- } else if (ch === 45 && !this.inModule) {
2477
+ } else if (ch === 45 && !this.inModule && this.options.annexB) {
2479
2478
  const pos = this.state.pos;
2480
2479
  if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
2481
2480
  const comment = this.skipLineComment(3);
@@ -2486,7 +2485,7 @@ class Tokenizer extends CommentsParser {
2486
2485
  } else {
2487
2486
  break loop;
2488
2487
  }
2489
- } else if (ch === 60 && !this.inModule) {
2488
+ } else if (ch === 60 && !this.inModule && this.options.annexB) {
2490
2489
  const pos = this.state.pos;
2491
2490
  if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
2492
2491
  const comment = this.skipLineComment(4);
@@ -3724,9 +3723,6 @@ class UtilParser extends Tokenizer {
3724
3723
  hasPropertyAsPrivateName(node) {
3725
3724
  return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
3726
3725
  }
3727
- isOptionalChain(node) {
3728
- return node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression";
3729
- }
3730
3726
  isObjectProperty(node) {
3731
3727
  return node.type === "ObjectProperty";
3732
3728
  }
@@ -5730,12 +5726,12 @@ var flow = (superClass => class FlowParserMixin extends superClass {
5730
5726
  return super.parseBindingAtom();
5731
5727
  }
5732
5728
  }
5733
- parseFunctionParams(node, allowModifiers) {
5729
+ parseFunctionParams(node, isConstructor) {
5734
5730
  const kind = node.kind;
5735
5731
  if (kind !== "get" && kind !== "set" && this.match(47)) {
5736
5732
  node.typeParameters = this.flowParseTypeParameterDeclaration();
5737
5733
  }
5738
- super.parseFunctionParams(node, allowModifiers);
5734
+ super.parseFunctionParams(node, isConstructor);
5739
5735
  }
5740
5736
  parseVarId(decl, kind) {
5741
5737
  super.parseVarId(decl, kind);
@@ -5932,7 +5928,7 @@ var flow = (superClass => class FlowParserMixin extends superClass {
5932
5928
  }
5933
5929
  parseAsyncArrowWithTypeParameters(startLoc) {
5934
5930
  const node = this.startNodeAt(startLoc);
5935
- this.parseFunctionParams(node);
5931
+ this.parseFunctionParams(node, false);
5936
5932
  if (!this.parseArrow(node)) return;
5937
5933
  return super.parseArrowExpression(node, undefined, true);
5938
5934
  }
@@ -7157,491 +7153,898 @@ class TypeScriptScopeHandler extends ScopeHandler {
7157
7153
  }
7158
7154
 
7159
7155
  const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
7160
- function nonNull(x) {
7161
- if (x == null) {
7162
- throw new Error(`Unexpected ${x} value.`);
7163
- }
7164
- return x;
7165
- }
7166
- function assert(x) {
7167
- if (!x) {
7168
- throw new Error("Assert fail");
7169
- }
7170
- }
7171
- const TSErrors = ParseErrorEnum`typescript`({
7172
- AbstractMethodHasImplementation: ({
7173
- methodName
7174
- }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
7175
- AbstractPropertyHasInitializer: ({
7176
- propertyName
7177
- }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
7178
- AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
7179
- AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
7180
- AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
7181
- ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
7182
- ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
7183
- ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
7184
- ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
7185
- DeclareAccessor: ({
7186
- kind
7187
- }) => `'declare' is not allowed in ${kind}ters.`,
7188
- DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
7189
- DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
7190
- DuplicateAccessibilityModifier: ({
7191
- modifier
7192
- }) => `Accessibility modifier already seen.`,
7193
- DuplicateModifier: ({
7194
- modifier
7195
- }) => `Duplicate modifier: '${modifier}'.`,
7196
- EmptyHeritageClauseType: ({
7197
- token
7198
- }) => `'${token}' list cannot be empty.`,
7199
- EmptyTypeArguments: "Type argument list cannot be empty.",
7200
- EmptyTypeParameters: "Type parameter list cannot be empty.",
7201
- ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
7202
- ImportAliasHasImportType: "An import alias can not use 'import type'.",
7203
- ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
7204
- IncompatibleModifiers: ({
7205
- modifiers
7206
- }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
7207
- IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
7208
- IndexSignatureHasAccessibility: ({
7209
- modifier
7210
- }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
7211
- IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
7212
- IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
7213
- IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
7214
- InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
7215
- InvalidModifierOnTypeMember: ({
7216
- modifier
7217
- }) => `'${modifier}' modifier cannot appear on a type member.`,
7218
- InvalidModifierOnTypeParameter: ({
7219
- modifier
7220
- }) => `'${modifier}' modifier cannot appear on a type parameter.`,
7221
- InvalidModifierOnTypeParameterPositions: ({
7222
- modifier
7223
- }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
7224
- InvalidModifiersOrder: ({
7225
- orderedModifiers
7226
- }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
7227
- InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
7228
- InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
7229
- MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
7230
- MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
7231
- NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
7232
- NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
7233
- OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
7234
- OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
7235
- PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
7236
- PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
7237
- PrivateElementHasAccessibility: ({
7238
- modifier
7239
- }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
7240
- ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
7241
- ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
7242
- ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
7243
- SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
7244
- SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
7245
- SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
7246
- SingleTypeParameterWithoutTrailingComma: ({
7247
- typeParameterName
7248
- }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
7249
- StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
7250
- TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
7251
- TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
7252
- TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
7253
- TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
7254
- UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
7255
- UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
7256
- UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
7257
- UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
7258
- UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
7259
- UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
7260
- UnsupportedSignatureParameterKind: ({
7261
- type
7262
- }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
7263
- });
7264
- function keywordTypeFromName(value) {
7265
- switch (value) {
7266
- case "any":
7267
- return "TSAnyKeyword";
7268
- case "boolean":
7269
- return "TSBooleanKeyword";
7270
- case "bigint":
7271
- return "TSBigIntKeyword";
7272
- case "never":
7273
- return "TSNeverKeyword";
7274
- case "number":
7275
- return "TSNumberKeyword";
7276
- case "object":
7277
- return "TSObjectKeyword";
7278
- case "string":
7279
- return "TSStringKeyword";
7280
- case "symbol":
7281
- return "TSSymbolKeyword";
7282
- case "undefined":
7283
- return "TSUndefinedKeyword";
7284
- case "unknown":
7285
- return "TSUnknownKeyword";
7286
- default:
7287
- return undefined;
7288
- }
7289
- }
7290
- function tsIsAccessModifier(modifier) {
7291
- return modifier === "private" || modifier === "public" || modifier === "protected";
7292
- }
7293
- function tsIsVarianceAnnotations(modifier) {
7294
- return modifier === "in" || modifier === "out";
7295
- }
7296
- var typescript = (superClass => class TypeScriptParserMixin extends superClass {
7297
- getScopeHandler() {
7298
- return TypeScriptScopeHandler;
7299
- }
7300
- tsIsIdentifier() {
7301
- return tokenIsIdentifier(this.state.type);
7302
- }
7303
- tsTokenCanFollowModifier() {
7304
- return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
7305
- }
7306
- tsNextTokenCanFollowModifier() {
7307
- this.next();
7308
- return this.tsTokenCanFollowModifier();
7309
- }
7310
- tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
7311
- if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58) {
7312
- return undefined;
7313
- }
7314
- const modifier = this.state.value;
7315
- if (allowedModifiers.indexOf(modifier) !== -1) {
7316
- if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
7317
- return undefined;
7318
- }
7319
- if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
7320
- return modifier;
7321
- }
7322
- }
7323
- return undefined;
7324
- }
7325
- tsParseModifiers({
7326
- modified,
7327
- allowedModifiers,
7328
- disallowedModifiers,
7329
- stopOnStartOfClassStaticBlock,
7330
- errorTemplate = TSErrors.InvalidModifierOnTypeMember
7331
- }) {
7332
- const enforceOrder = (loc, modifier, before, after) => {
7333
- if (modifier === before && modified[after]) {
7334
- this.raise(TSErrors.InvalidModifiersOrder, {
7335
- at: loc,
7336
- orderedModifiers: [before, after]
7337
- });
7338
- }
7339
- };
7340
- const incompatible = (loc, modifier, mod1, mod2) => {
7341
- if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
7342
- this.raise(TSErrors.IncompatibleModifiers, {
7343
- at: loc,
7344
- modifiers: [mod1, mod2]
7345
- });
7346
- }
7347
- };
7348
- for (;;) {
7349
- const {
7350
- startLoc
7351
- } = this.state;
7352
- const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
7353
- if (!modifier) break;
7354
- if (tsIsAccessModifier(modifier)) {
7355
- if (modified.accessibility) {
7356
- this.raise(TSErrors.DuplicateAccessibilityModifier, {
7357
- at: startLoc,
7358
- modifier
7156
+ const unwrapParenthesizedExpression = node => {
7157
+ return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
7158
+ };
7159
+ var ParseBindingListFlags = {
7160
+ ALLOW_EMPTY: 1,
7161
+ IS_FUNCTION_PARAMS: 2,
7162
+ IS_CONSTRUCTOR_PARAMS: 4
7163
+ };
7164
+ class LValParser extends NodeUtils {
7165
+ toAssignable(node, isLHS = false) {
7166
+ var _node$extra, _node$extra3;
7167
+ let parenthesized = undefined;
7168
+ if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
7169
+ parenthesized = unwrapParenthesizedExpression(node);
7170
+ if (isLHS) {
7171
+ if (parenthesized.type === "Identifier") {
7172
+ this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
7173
+ at: node
7359
7174
  });
7360
- } else {
7361
- enforceOrder(startLoc, modifier, modifier, "override");
7362
- enforceOrder(startLoc, modifier, modifier, "static");
7363
- enforceOrder(startLoc, modifier, modifier, "readonly");
7364
- modified.accessibility = modifier;
7365
- }
7366
- } else if (tsIsVarianceAnnotations(modifier)) {
7367
- if (modified[modifier]) {
7368
- this.raise(TSErrors.DuplicateModifier, {
7369
- at: startLoc,
7370
- modifier
7175
+ } else if (parenthesized.type !== "MemberExpression") {
7176
+ this.raise(Errors.InvalidParenthesizedAssignment, {
7177
+ at: node
7371
7178
  });
7372
7179
  }
7373
- modified[modifier] = true;
7374
- enforceOrder(startLoc, modifier, "in", "out");
7375
7180
  } else {
7376
- if (Object.hasOwnProperty.call(modified, modifier)) {
7377
- this.raise(TSErrors.DuplicateModifier, {
7378
- at: startLoc,
7379
- modifier
7380
- });
7381
- } else {
7382
- enforceOrder(startLoc, modifier, "static", "readonly");
7383
- enforceOrder(startLoc, modifier, "static", "override");
7384
- enforceOrder(startLoc, modifier, "override", "readonly");
7385
- enforceOrder(startLoc, modifier, "abstract", "override");
7386
- incompatible(startLoc, modifier, "declare", "override");
7387
- incompatible(startLoc, modifier, "static", "abstract");
7388
- }
7389
- modified[modifier] = true;
7390
- }
7391
- if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
7392
- this.raise(errorTemplate, {
7393
- at: startLoc,
7394
- modifier
7181
+ this.raise(Errors.InvalidParenthesizedAssignment, {
7182
+ at: node
7395
7183
  });
7396
7184
  }
7397
7185
  }
7398
- }
7399
- tsIsListTerminator(kind) {
7400
- switch (kind) {
7401
- case "EnumMembers":
7402
- case "TypeMembers":
7403
- return this.match(8);
7404
- case "HeritageClauseElement":
7405
- return this.match(5);
7406
- case "TupleElementTypes":
7407
- return this.match(3);
7408
- case "TypeParametersOrArguments":
7409
- return this.match(48);
7410
- }
7411
- throw new Error("Unreachable");
7412
- }
7413
- tsParseList(kind, parseElement) {
7414
- const result = [];
7415
- while (!this.tsIsListTerminator(kind)) {
7416
- result.push(parseElement());
7417
- }
7418
- return result;
7419
- }
7420
- tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
7421
- return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
7422
- }
7423
- tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
7424
- const result = [];
7425
- let trailingCommaPos = -1;
7426
- for (;;) {
7427
- if (this.tsIsListTerminator(kind)) {
7186
+ switch (node.type) {
7187
+ case "Identifier":
7188
+ case "ObjectPattern":
7189
+ case "ArrayPattern":
7190
+ case "AssignmentPattern":
7191
+ case "RestElement":
7428
7192
  break;
7429
- }
7430
- trailingCommaPos = -1;
7431
- const element = parseElement();
7432
- if (element == null) {
7433
- return undefined;
7434
- }
7435
- result.push(element);
7436
- if (this.eat(12)) {
7437
- trailingCommaPos = this.state.lastTokStart;
7438
- continue;
7439
- }
7440
- if (this.tsIsListTerminator(kind)) {
7193
+ case "ObjectExpression":
7194
+ node.type = "ObjectPattern";
7195
+ for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
7196
+ var _node$extra2;
7197
+ const prop = node.properties[i];
7198
+ const isLast = i === last;
7199
+ this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
7200
+ if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
7201
+ this.raise(Errors.RestTrailingComma, {
7202
+ at: node.extra.trailingCommaLoc
7203
+ });
7204
+ }
7205
+ }
7206
+ break;
7207
+ case "ObjectProperty":
7208
+ {
7209
+ const {
7210
+ key,
7211
+ value
7212
+ } = node;
7213
+ if (this.isPrivateName(key)) {
7214
+ this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
7215
+ }
7216
+ this.toAssignable(value, isLHS);
7217
+ break;
7218
+ }
7219
+ case "SpreadElement":
7220
+ {
7221
+ throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
7222
+ }
7223
+ case "ArrayExpression":
7224
+ node.type = "ArrayPattern";
7225
+ this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
7226
+ break;
7227
+ case "AssignmentExpression":
7228
+ if (node.operator !== "=") {
7229
+ this.raise(Errors.MissingEqInAssignment, {
7230
+ at: node.left.loc.end
7231
+ });
7232
+ }
7233
+ node.type = "AssignmentPattern";
7234
+ delete node.operator;
7235
+ this.toAssignable(node.left, isLHS);
7236
+ break;
7237
+ case "ParenthesizedExpression":
7238
+ this.toAssignable(parenthesized, isLHS);
7441
7239
  break;
7442
- }
7443
- if (expectSuccess) {
7444
- this.expect(12);
7445
- }
7446
- return undefined;
7447
- }
7448
- if (refTrailingCommaPos) {
7449
- refTrailingCommaPos.value = trailingCommaPos;
7450
7240
  }
7451
- return result;
7452
7241
  }
7453
- tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
7454
- if (!skipFirstToken) {
7455
- if (bracket) {
7456
- this.expect(0);
7457
- } else {
7458
- this.expect(47);
7242
+ toAssignableObjectExpressionProp(prop, isLast, isLHS) {
7243
+ if (prop.type === "ObjectMethod") {
7244
+ this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
7245
+ at: prop.key
7246
+ });
7247
+ } else if (prop.type === "SpreadElement") {
7248
+ prop.type = "RestElement";
7249
+ const arg = prop.argument;
7250
+ this.checkToRestConversion(arg, false);
7251
+ this.toAssignable(arg, isLHS);
7252
+ if (!isLast) {
7253
+ this.raise(Errors.RestTrailingComma, {
7254
+ at: prop
7255
+ });
7459
7256
  }
7460
- }
7461
- const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
7462
- if (bracket) {
7463
- this.expect(3);
7464
7257
  } else {
7465
- this.expect(48);
7258
+ this.toAssignable(prop, isLHS);
7466
7259
  }
7467
- return result;
7468
7260
  }
7469
- tsParseImportType() {
7470
- const node = this.startNode();
7471
- this.expect(83);
7472
- this.expect(10);
7473
- if (!this.match(131)) {
7474
- this.raise(TSErrors.UnsupportedImportTypeArgument, {
7475
- at: this.state.startLoc
7476
- });
7477
- }
7478
- node.argument = super.parseExprAtom();
7479
- this.expect(11);
7480
- if (this.eat(16)) {
7481
- node.qualifier = this.tsParseEntityName();
7482
- }
7483
- if (this.match(47)) {
7484
- node.typeParameters = this.tsParseTypeArguments();
7261
+ toAssignableList(exprList, trailingCommaLoc, isLHS) {
7262
+ const end = exprList.length - 1;
7263
+ for (let i = 0; i <= end; i++) {
7264
+ const elt = exprList[i];
7265
+ if (!elt) continue;
7266
+ if (elt.type === "SpreadElement") {
7267
+ elt.type = "RestElement";
7268
+ const arg = elt.argument;
7269
+ this.checkToRestConversion(arg, true);
7270
+ this.toAssignable(arg, isLHS);
7271
+ } else {
7272
+ this.toAssignable(elt, isLHS);
7273
+ }
7274
+ if (elt.type === "RestElement") {
7275
+ if (i < end) {
7276
+ this.raise(Errors.RestTrailingComma, {
7277
+ at: elt
7278
+ });
7279
+ } else if (trailingCommaLoc) {
7280
+ this.raise(Errors.RestTrailingComma, {
7281
+ at: trailingCommaLoc
7282
+ });
7283
+ }
7284
+ }
7485
7285
  }
7486
- return this.finishNode(node, "TSImportType");
7487
7286
  }
7488
- tsParseEntityName(allowReservedWords = true) {
7489
- let entity = this.parseIdentifier(allowReservedWords);
7490
- while (this.eat(16)) {
7491
- const node = this.startNodeAtNode(entity);
7492
- node.left = entity;
7493
- node.right = this.parseIdentifier(allowReservedWords);
7494
- entity = this.finishNode(node, "TSQualifiedName");
7287
+ isAssignable(node, isBinding) {
7288
+ switch (node.type) {
7289
+ case "Identifier":
7290
+ case "ObjectPattern":
7291
+ case "ArrayPattern":
7292
+ case "AssignmentPattern":
7293
+ case "RestElement":
7294
+ return true;
7295
+ case "ObjectExpression":
7296
+ {
7297
+ const last = node.properties.length - 1;
7298
+ return node.properties.every((prop, i) => {
7299
+ return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
7300
+ });
7301
+ }
7302
+ case "ObjectProperty":
7303
+ return this.isAssignable(node.value);
7304
+ case "SpreadElement":
7305
+ return this.isAssignable(node.argument);
7306
+ case "ArrayExpression":
7307
+ return node.elements.every(element => element === null || this.isAssignable(element));
7308
+ case "AssignmentExpression":
7309
+ return node.operator === "=";
7310
+ case "ParenthesizedExpression":
7311
+ return this.isAssignable(node.expression);
7312
+ case "MemberExpression":
7313
+ case "OptionalMemberExpression":
7314
+ return !isBinding;
7315
+ default:
7316
+ return false;
7495
7317
  }
7496
- return entity;
7497
7318
  }
7498
- tsParseTypeReference() {
7499
- const node = this.startNode();
7500
- node.typeName = this.tsParseEntityName();
7501
- if (!this.hasPrecedingLineBreak() && this.match(47)) {
7502
- node.typeParameters = this.tsParseTypeArguments();
7319
+ toReferencedList(exprList, isParenthesizedExpr) {
7320
+ return exprList;
7321
+ }
7322
+ toReferencedListDeep(exprList, isParenthesizedExpr) {
7323
+ this.toReferencedList(exprList, isParenthesizedExpr);
7324
+ for (const expr of exprList) {
7325
+ if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
7326
+ this.toReferencedListDeep(expr.elements);
7327
+ }
7503
7328
  }
7504
- return this.finishNode(node, "TSTypeReference");
7505
7329
  }
7506
- tsParseThisTypePredicate(lhs) {
7330
+ parseSpread(refExpressionErrors) {
7331
+ const node = this.startNode();
7507
7332
  this.next();
7508
- const node = this.startNodeAtNode(lhs);
7509
- node.parameterName = lhs;
7510
- node.typeAnnotation = this.tsParseTypeAnnotation(false);
7511
- node.asserts = false;
7512
- return this.finishNode(node, "TSTypePredicate");
7333
+ node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
7334
+ return this.finishNode(node, "SpreadElement");
7513
7335
  }
7514
- tsParseThisTypeNode() {
7336
+ parseRestBinding() {
7515
7337
  const node = this.startNode();
7516
7338
  this.next();
7517
- return this.finishNode(node, "TSThisType");
7339
+ node.argument = this.parseBindingAtom();
7340
+ return this.finishNode(node, "RestElement");
7518
7341
  }
7519
- tsParseTypeQuery() {
7520
- const node = this.startNode();
7521
- this.expect(87);
7522
- if (this.match(83)) {
7523
- node.exprName = this.tsParseImportType();
7524
- } else {
7525
- node.exprName = this.tsParseEntityName();
7526
- }
7527
- if (!this.hasPrecedingLineBreak() && this.match(47)) {
7528
- node.typeParameters = this.tsParseTypeArguments();
7342
+ parseBindingAtom() {
7343
+ switch (this.state.type) {
7344
+ case 0:
7345
+ {
7346
+ const node = this.startNode();
7347
+ this.next();
7348
+ node.elements = this.parseBindingList(3, 93, ParseBindingListFlags.ALLOW_EMPTY);
7349
+ return this.finishNode(node, "ArrayPattern");
7350
+ }
7351
+ case 5:
7352
+ return this.parseObjectLike(8, true);
7529
7353
  }
7530
- return this.finishNode(node, "TSTypeQuery");
7354
+ return this.parseIdentifier();
7531
7355
  }
7532
- tsParseInOutModifiers(node) {
7533
- this.tsParseModifiers({
7534
- modified: node,
7535
- allowedModifiers: ["in", "out"],
7536
- disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
7537
- errorTemplate: TSErrors.InvalidModifierOnTypeParameter
7538
- });
7356
+ parseBindingList(close, closeCharCode, flags) {
7357
+ const allowEmpty = flags & ParseBindingListFlags.ALLOW_EMPTY;
7358
+ const elts = [];
7359
+ let first = true;
7360
+ while (!this.eat(close)) {
7361
+ if (first) {
7362
+ first = false;
7363
+ } else {
7364
+ this.expect(12);
7365
+ }
7366
+ if (allowEmpty && this.match(12)) {
7367
+ elts.push(null);
7368
+ } else if (this.eat(close)) {
7369
+ break;
7370
+ } else if (this.match(21)) {
7371
+ elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
7372
+ if (!this.checkCommaAfterRest(closeCharCode)) {
7373
+ this.expect(close);
7374
+ break;
7375
+ }
7376
+ } else {
7377
+ const decorators = [];
7378
+ if (this.match(26) && this.hasPlugin("decorators")) {
7379
+ this.raise(Errors.UnsupportedParameterDecorator, {
7380
+ at: this.state.startLoc
7381
+ });
7382
+ }
7383
+ while (this.match(26)) {
7384
+ decorators.push(this.parseDecorator());
7385
+ }
7386
+ elts.push(this.parseAssignableListItem(flags, decorators));
7387
+ }
7388
+ }
7389
+ return elts;
7539
7390
  }
7540
- tsParseNoneModifiers(node) {
7541
- this.tsParseModifiers({
7542
- modified: node,
7543
- allowedModifiers: [],
7544
- disallowedModifiers: ["in", "out"],
7545
- errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
7546
- });
7391
+ parseBindingRestProperty(prop) {
7392
+ this.next();
7393
+ prop.argument = this.parseIdentifier();
7394
+ this.checkCommaAfterRest(125);
7395
+ return this.finishNode(prop, "RestElement");
7547
7396
  }
7548
- tsParseTypeParameter(parseModifiers = this.tsParseNoneModifiers.bind(this)) {
7549
- const node = this.startNode();
7550
- parseModifiers(node);
7551
- node.name = this.tsParseTypeParameterName();
7552
- node.constraint = this.tsEatThenParseType(81);
7553
- node.default = this.tsEatThenParseType(29);
7554
- return this.finishNode(node, "TSTypeParameter");
7397
+ parseBindingProperty() {
7398
+ const prop = this.startNode();
7399
+ const {
7400
+ type,
7401
+ startLoc
7402
+ } = this.state;
7403
+ if (type === 21) {
7404
+ return this.parseBindingRestProperty(prop);
7405
+ } else if (type === 136) {
7406
+ this.expectPlugin("destructuringPrivate", startLoc);
7407
+ this.classScope.usePrivateName(this.state.value, startLoc);
7408
+ prop.key = this.parsePrivateName();
7409
+ } else {
7410
+ this.parsePropertyName(prop);
7411
+ }
7412
+ prop.method = false;
7413
+ return this.parseObjPropValue(prop, startLoc, false, false, true, false);
7555
7414
  }
7556
- tsTryParseTypeParameters(parseModifiers) {
7557
- if (this.match(47)) {
7558
- return this.tsParseTypeParameters(parseModifiers);
7415
+ parseAssignableListItem(flags, decorators) {
7416
+ const left = this.parseMaybeDefault();
7417
+ this.parseAssignableListItemTypes(left, flags);
7418
+ const elt = this.parseMaybeDefault(left.loc.start, left);
7419
+ if (decorators.length) {
7420
+ left.decorators = decorators;
7559
7421
  }
7422
+ return elt;
7560
7423
  }
7561
- tsParseTypeParameters(parseModifiers) {
7562
- const node = this.startNode();
7563
- if (this.match(47) || this.match(140)) {
7564
- this.next();
7565
- } else {
7566
- this.unexpected();
7424
+ parseAssignableListItemTypes(param, flags) {
7425
+ return param;
7426
+ }
7427
+ parseMaybeDefault(startLoc, left) {
7428
+ var _startLoc, _left;
7429
+ (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
7430
+ left = (_left = left) != null ? _left : this.parseBindingAtom();
7431
+ if (!this.eat(29)) return left;
7432
+ const node = this.startNodeAt(startLoc);
7433
+ node.left = left;
7434
+ node.right = this.parseMaybeAssignAllowIn();
7435
+ return this.finishNode(node, "AssignmentPattern");
7436
+ }
7437
+ isValidLVal(type, isUnparenthesizedInAssign, binding) {
7438
+ return getOwn$1({
7439
+ AssignmentPattern: "left",
7440
+ RestElement: "argument",
7441
+ ObjectProperty: "value",
7442
+ ParenthesizedExpression: "expression",
7443
+ ArrayPattern: "elements",
7444
+ ObjectPattern: "properties"
7445
+ }, type);
7446
+ }
7447
+ checkLVal(expression, {
7448
+ in: ancestor,
7449
+ binding = BIND_NONE,
7450
+ checkClashes = false,
7451
+ strictModeChanged = false,
7452
+ hasParenthesizedAncestor = false
7453
+ }) {
7454
+ var _expression$extra;
7455
+ const type = expression.type;
7456
+ if (this.isObjectMethod(expression)) return;
7457
+ if (type === "MemberExpression") {
7458
+ if (binding !== BIND_NONE) {
7459
+ this.raise(Errors.InvalidPropertyBindingPattern, {
7460
+ at: expression
7461
+ });
7462
+ }
7463
+ return;
7567
7464
  }
7568
- const refTrailingCommaPos = {
7569
- value: -1
7570
- };
7571
- node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
7572
- if (node.params.length === 0) {
7573
- this.raise(TSErrors.EmptyTypeParameters, {
7574
- at: node
7575
- });
7465
+ if (type === "Identifier") {
7466
+ this.checkIdentifier(expression, binding, strictModeChanged);
7467
+ const {
7468
+ name
7469
+ } = expression;
7470
+ if (checkClashes) {
7471
+ if (checkClashes.has(name)) {
7472
+ this.raise(Errors.ParamDupe, {
7473
+ at: expression
7474
+ });
7475
+ } else {
7476
+ checkClashes.add(name);
7477
+ }
7478
+ }
7479
+ return;
7576
7480
  }
7577
- if (refTrailingCommaPos.value !== -1) {
7578
- this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
7481
+ const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
7482
+ if (validity === true) return;
7483
+ if (validity === false) {
7484
+ const ParseErrorClass = binding === BIND_NONE ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
7485
+ this.raise(ParseErrorClass, {
7486
+ at: expression,
7487
+ ancestor
7488
+ });
7489
+ return;
7579
7490
  }
7580
- return this.finishNode(node, "TSTypeParameterDeclaration");
7581
- }
7582
- tsFillSignature(returnToken, signature) {
7583
- const returnTokenRequired = returnToken === 19;
7584
- const paramsKey = "parameters";
7585
- const returnTypeKey = "typeAnnotation";
7586
- signature.typeParameters = this.tsTryParseTypeParameters();
7587
- this.expect(10);
7588
- signature[paramsKey] = this.tsParseBindingListForSignature();
7589
- if (returnTokenRequired) {
7590
- signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
7591
- } else if (this.match(returnToken)) {
7592
- signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
7491
+ const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
7492
+ const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? {
7493
+ type
7494
+ } : ancestor;
7495
+ for (const child of [].concat(expression[key])) {
7496
+ if (child) {
7497
+ this.checkLVal(child, {
7498
+ in: nextAncestor,
7499
+ binding,
7500
+ checkClashes,
7501
+ strictModeChanged,
7502
+ hasParenthesizedAncestor: isParenthesizedExpression
7503
+ });
7504
+ }
7593
7505
  }
7594
7506
  }
7595
- tsParseBindingListForSignature() {
7596
- return super.parseBindingList(11, 41).map(pattern => {
7597
- if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
7598
- this.raise(TSErrors.UnsupportedSignatureParameterKind, {
7599
- at: pattern,
7600
- type: pattern.type
7507
+ checkIdentifier(at, bindingType, strictModeChanged = false) {
7508
+ if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
7509
+ if (bindingType === BIND_NONE) {
7510
+ this.raise(Errors.StrictEvalArguments, {
7511
+ at,
7512
+ referenceName: at.name
7513
+ });
7514
+ } else {
7515
+ this.raise(Errors.StrictEvalArgumentsBinding, {
7516
+ at,
7517
+ bindingName: at.name
7601
7518
  });
7602
7519
  }
7603
- return pattern;
7604
- });
7605
- }
7606
- tsParseTypeMemberSemicolon() {
7607
- if (!this.eat(12) && !this.isLineTerminator()) {
7608
- this.expect(13);
7609
7520
  }
7610
- }
7611
- tsParseSignatureMember(kind, node) {
7612
- this.tsFillSignature(14, node);
7613
- this.tsParseTypeMemberSemicolon();
7614
- return this.finishNode(node, kind);
7615
- }
7616
- tsIsUnambiguouslyIndexSignature() {
7617
- this.next();
7618
- if (tokenIsIdentifier(this.state.type)) {
7619
- this.next();
7620
- return this.match(14);
7521
+ if (bindingType & BIND_FLAGS_NO_LET_IN_LEXICAL && at.name === "let") {
7522
+ this.raise(Errors.LetInLexicalBinding, {
7523
+ at
7524
+ });
7621
7525
  }
7622
- return false;
7623
- }
7624
- tsTryParseIndexSignature(node) {
7625
- if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
7626
- return undefined;
7526
+ if (!(bindingType & BIND_NONE)) {
7527
+ this.declareNameFromIdentifier(at, bindingType);
7627
7528
  }
7628
- this.expect(0);
7629
- const id = this.parseIdentifier();
7630
- id.typeAnnotation = this.tsParseTypeAnnotation();
7631
- this.resetEndLocation(id);
7632
- this.expect(3);
7633
- node.parameters = [id];
7634
- const type = this.tsTryParseTypeAnnotation();
7635
- if (type) node.typeAnnotation = type;
7636
- this.tsParseTypeMemberSemicolon();
7637
- return this.finishNode(node, "TSIndexSignature");
7638
7529
  }
7639
- tsParsePropertyOrMethodSignature(node, readonly) {
7640
- if (this.eat(17)) node.optional = true;
7641
- const nodeAny = node;
7642
- if (this.match(10) || this.match(47)) {
7643
- if (readonly) {
7644
- this.raise(TSErrors.ReadonlyForMethodSignature, {
7530
+ declareNameFromIdentifier(identifier, binding) {
7531
+ this.scope.declareName(identifier.name, binding, identifier.loc.start);
7532
+ }
7533
+ checkToRestConversion(node, allowPattern) {
7534
+ switch (node.type) {
7535
+ case "ParenthesizedExpression":
7536
+ this.checkToRestConversion(node.expression, allowPattern);
7537
+ break;
7538
+ case "Identifier":
7539
+ case "MemberExpression":
7540
+ break;
7541
+ case "ArrayExpression":
7542
+ case "ObjectExpression":
7543
+ if (allowPattern) break;
7544
+ default:
7545
+ this.raise(Errors.InvalidRestAssignmentPattern, {
7546
+ at: node
7547
+ });
7548
+ }
7549
+ }
7550
+ checkCommaAfterRest(close) {
7551
+ if (!this.match(12)) {
7552
+ return false;
7553
+ }
7554
+ this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
7555
+ at: this.state.startLoc
7556
+ });
7557
+ return true;
7558
+ }
7559
+ }
7560
+
7561
+ const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
7562
+ function nonNull(x) {
7563
+ if (x == null) {
7564
+ throw new Error(`Unexpected ${x} value.`);
7565
+ }
7566
+ return x;
7567
+ }
7568
+ function assert(x) {
7569
+ if (!x) {
7570
+ throw new Error("Assert fail");
7571
+ }
7572
+ }
7573
+ const TSErrors = ParseErrorEnum`typescript`({
7574
+ AbstractMethodHasImplementation: ({
7575
+ methodName
7576
+ }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
7577
+ AbstractPropertyHasInitializer: ({
7578
+ propertyName
7579
+ }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
7580
+ AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
7581
+ AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
7582
+ AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
7583
+ ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
7584
+ ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
7585
+ ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
7586
+ ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
7587
+ DeclareAccessor: ({
7588
+ kind
7589
+ }) => `'declare' is not allowed in ${kind}ters.`,
7590
+ DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
7591
+ DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
7592
+ DuplicateAccessibilityModifier: ({
7593
+ modifier
7594
+ }) => `Accessibility modifier already seen.`,
7595
+ DuplicateModifier: ({
7596
+ modifier
7597
+ }) => `Duplicate modifier: '${modifier}'.`,
7598
+ EmptyHeritageClauseType: ({
7599
+ token
7600
+ }) => `'${token}' list cannot be empty.`,
7601
+ EmptyTypeArguments: "Type argument list cannot be empty.",
7602
+ EmptyTypeParameters: "Type parameter list cannot be empty.",
7603
+ ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
7604
+ ImportAliasHasImportType: "An import alias can not use 'import type'.",
7605
+ ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
7606
+ IncompatibleModifiers: ({
7607
+ modifiers
7608
+ }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
7609
+ IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
7610
+ IndexSignatureHasAccessibility: ({
7611
+ modifier
7612
+ }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
7613
+ IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
7614
+ IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
7615
+ IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
7616
+ InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
7617
+ InvalidModifierOnTypeMember: ({
7618
+ modifier
7619
+ }) => `'${modifier}' modifier cannot appear on a type member.`,
7620
+ InvalidModifierOnTypeParameter: ({
7621
+ modifier
7622
+ }) => `'${modifier}' modifier cannot appear on a type parameter.`,
7623
+ InvalidModifierOnTypeParameterPositions: ({
7624
+ modifier
7625
+ }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
7626
+ InvalidModifiersOrder: ({
7627
+ orderedModifiers
7628
+ }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
7629
+ InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
7630
+ InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
7631
+ MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
7632
+ MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
7633
+ NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
7634
+ NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
7635
+ OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
7636
+ OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
7637
+ PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
7638
+ PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
7639
+ PrivateElementHasAccessibility: ({
7640
+ modifier
7641
+ }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
7642
+ ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
7643
+ ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
7644
+ ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
7645
+ SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
7646
+ SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
7647
+ SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
7648
+ SingleTypeParameterWithoutTrailingComma: ({
7649
+ typeParameterName
7650
+ }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
7651
+ StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
7652
+ TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
7653
+ TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
7654
+ TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
7655
+ TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
7656
+ UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
7657
+ UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
7658
+ UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
7659
+ UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
7660
+ UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
7661
+ UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
7662
+ UnsupportedSignatureParameterKind: ({
7663
+ type
7664
+ }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
7665
+ });
7666
+ function keywordTypeFromName(value) {
7667
+ switch (value) {
7668
+ case "any":
7669
+ return "TSAnyKeyword";
7670
+ case "boolean":
7671
+ return "TSBooleanKeyword";
7672
+ case "bigint":
7673
+ return "TSBigIntKeyword";
7674
+ case "never":
7675
+ return "TSNeverKeyword";
7676
+ case "number":
7677
+ return "TSNumberKeyword";
7678
+ case "object":
7679
+ return "TSObjectKeyword";
7680
+ case "string":
7681
+ return "TSStringKeyword";
7682
+ case "symbol":
7683
+ return "TSSymbolKeyword";
7684
+ case "undefined":
7685
+ return "TSUndefinedKeyword";
7686
+ case "unknown":
7687
+ return "TSUnknownKeyword";
7688
+ default:
7689
+ return undefined;
7690
+ }
7691
+ }
7692
+ function tsIsAccessModifier(modifier) {
7693
+ return modifier === "private" || modifier === "public" || modifier === "protected";
7694
+ }
7695
+ function tsIsVarianceAnnotations(modifier) {
7696
+ return modifier === "in" || modifier === "out";
7697
+ }
7698
+ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
7699
+ constructor(...args) {
7700
+ super(...args);
7701
+ this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
7702
+ allowedModifiers: ["in", "out"],
7703
+ disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
7704
+ errorTemplate: TSErrors.InvalidModifierOnTypeParameter
7705
+ });
7706
+ this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
7707
+ allowedModifiers: ["const"],
7708
+ disallowedModifiers: ["in", "out"],
7709
+ errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
7710
+ });
7711
+ this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
7712
+ allowedModifiers: ["in", "out", "const"],
7713
+ disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
7714
+ errorTemplate: TSErrors.InvalidModifierOnTypeParameter
7715
+ });
7716
+ }
7717
+ getScopeHandler() {
7718
+ return TypeScriptScopeHandler;
7719
+ }
7720
+ tsIsIdentifier() {
7721
+ return tokenIsIdentifier(this.state.type);
7722
+ }
7723
+ tsTokenCanFollowModifier() {
7724
+ return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
7725
+ }
7726
+ tsNextTokenCanFollowModifier() {
7727
+ this.next();
7728
+ return this.tsTokenCanFollowModifier();
7729
+ }
7730
+ tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
7731
+ if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
7732
+ return undefined;
7733
+ }
7734
+ const modifier = this.state.value;
7735
+ if (allowedModifiers.indexOf(modifier) !== -1) {
7736
+ if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
7737
+ return undefined;
7738
+ }
7739
+ if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
7740
+ return modifier;
7741
+ }
7742
+ }
7743
+ return undefined;
7744
+ }
7745
+ tsParseModifiers({
7746
+ allowedModifiers,
7747
+ disallowedModifiers,
7748
+ stopOnStartOfClassStaticBlock,
7749
+ errorTemplate = TSErrors.InvalidModifierOnTypeMember
7750
+ }, modified) {
7751
+ const enforceOrder = (loc, modifier, before, after) => {
7752
+ if (modifier === before && modified[after]) {
7753
+ this.raise(TSErrors.InvalidModifiersOrder, {
7754
+ at: loc,
7755
+ orderedModifiers: [before, after]
7756
+ });
7757
+ }
7758
+ };
7759
+ const incompatible = (loc, modifier, mod1, mod2) => {
7760
+ if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
7761
+ this.raise(TSErrors.IncompatibleModifiers, {
7762
+ at: loc,
7763
+ modifiers: [mod1, mod2]
7764
+ });
7765
+ }
7766
+ };
7767
+ for (;;) {
7768
+ const {
7769
+ startLoc
7770
+ } = this.state;
7771
+ const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
7772
+ if (!modifier) break;
7773
+ if (tsIsAccessModifier(modifier)) {
7774
+ if (modified.accessibility) {
7775
+ this.raise(TSErrors.DuplicateAccessibilityModifier, {
7776
+ at: startLoc,
7777
+ modifier
7778
+ });
7779
+ } else {
7780
+ enforceOrder(startLoc, modifier, modifier, "override");
7781
+ enforceOrder(startLoc, modifier, modifier, "static");
7782
+ enforceOrder(startLoc, modifier, modifier, "readonly");
7783
+ modified.accessibility = modifier;
7784
+ }
7785
+ } else if (tsIsVarianceAnnotations(modifier)) {
7786
+ if (modified[modifier]) {
7787
+ this.raise(TSErrors.DuplicateModifier, {
7788
+ at: startLoc,
7789
+ modifier
7790
+ });
7791
+ }
7792
+ modified[modifier] = true;
7793
+ enforceOrder(startLoc, modifier, "in", "out");
7794
+ } else {
7795
+ if (Object.hasOwnProperty.call(modified, modifier)) {
7796
+ this.raise(TSErrors.DuplicateModifier, {
7797
+ at: startLoc,
7798
+ modifier
7799
+ });
7800
+ } else {
7801
+ enforceOrder(startLoc, modifier, "static", "readonly");
7802
+ enforceOrder(startLoc, modifier, "static", "override");
7803
+ enforceOrder(startLoc, modifier, "override", "readonly");
7804
+ enforceOrder(startLoc, modifier, "abstract", "override");
7805
+ incompatible(startLoc, modifier, "declare", "override");
7806
+ incompatible(startLoc, modifier, "static", "abstract");
7807
+ }
7808
+ modified[modifier] = true;
7809
+ }
7810
+ if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
7811
+ this.raise(errorTemplate, {
7812
+ at: startLoc,
7813
+ modifier
7814
+ });
7815
+ }
7816
+ }
7817
+ }
7818
+ tsIsListTerminator(kind) {
7819
+ switch (kind) {
7820
+ case "EnumMembers":
7821
+ case "TypeMembers":
7822
+ return this.match(8);
7823
+ case "HeritageClauseElement":
7824
+ return this.match(5);
7825
+ case "TupleElementTypes":
7826
+ return this.match(3);
7827
+ case "TypeParametersOrArguments":
7828
+ return this.match(48);
7829
+ }
7830
+ throw new Error("Unreachable");
7831
+ }
7832
+ tsParseList(kind, parseElement) {
7833
+ const result = [];
7834
+ while (!this.tsIsListTerminator(kind)) {
7835
+ result.push(parseElement());
7836
+ }
7837
+ return result;
7838
+ }
7839
+ tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
7840
+ return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
7841
+ }
7842
+ tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
7843
+ const result = [];
7844
+ let trailingCommaPos = -1;
7845
+ for (;;) {
7846
+ if (this.tsIsListTerminator(kind)) {
7847
+ break;
7848
+ }
7849
+ trailingCommaPos = -1;
7850
+ const element = parseElement();
7851
+ if (element == null) {
7852
+ return undefined;
7853
+ }
7854
+ result.push(element);
7855
+ if (this.eat(12)) {
7856
+ trailingCommaPos = this.state.lastTokStart;
7857
+ continue;
7858
+ }
7859
+ if (this.tsIsListTerminator(kind)) {
7860
+ break;
7861
+ }
7862
+ if (expectSuccess) {
7863
+ this.expect(12);
7864
+ }
7865
+ return undefined;
7866
+ }
7867
+ if (refTrailingCommaPos) {
7868
+ refTrailingCommaPos.value = trailingCommaPos;
7869
+ }
7870
+ return result;
7871
+ }
7872
+ tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
7873
+ if (!skipFirstToken) {
7874
+ if (bracket) {
7875
+ this.expect(0);
7876
+ } else {
7877
+ this.expect(47);
7878
+ }
7879
+ }
7880
+ const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
7881
+ if (bracket) {
7882
+ this.expect(3);
7883
+ } else {
7884
+ this.expect(48);
7885
+ }
7886
+ return result;
7887
+ }
7888
+ tsParseImportType() {
7889
+ const node = this.startNode();
7890
+ this.expect(83);
7891
+ this.expect(10);
7892
+ if (!this.match(131)) {
7893
+ this.raise(TSErrors.UnsupportedImportTypeArgument, {
7894
+ at: this.state.startLoc
7895
+ });
7896
+ }
7897
+ node.argument = super.parseExprAtom();
7898
+ this.expect(11);
7899
+ if (this.eat(16)) {
7900
+ node.qualifier = this.tsParseEntityName();
7901
+ }
7902
+ if (this.match(47)) {
7903
+ node.typeParameters = this.tsParseTypeArguments();
7904
+ }
7905
+ return this.finishNode(node, "TSImportType");
7906
+ }
7907
+ tsParseEntityName(allowReservedWords = true) {
7908
+ let entity = this.parseIdentifier(allowReservedWords);
7909
+ while (this.eat(16)) {
7910
+ const node = this.startNodeAtNode(entity);
7911
+ node.left = entity;
7912
+ node.right = this.parseIdentifier(allowReservedWords);
7913
+ entity = this.finishNode(node, "TSQualifiedName");
7914
+ }
7915
+ return entity;
7916
+ }
7917
+ tsParseTypeReference() {
7918
+ const node = this.startNode();
7919
+ node.typeName = this.tsParseEntityName();
7920
+ if (!this.hasPrecedingLineBreak() && this.match(47)) {
7921
+ node.typeParameters = this.tsParseTypeArguments();
7922
+ }
7923
+ return this.finishNode(node, "TSTypeReference");
7924
+ }
7925
+ tsParseThisTypePredicate(lhs) {
7926
+ this.next();
7927
+ const node = this.startNodeAtNode(lhs);
7928
+ node.parameterName = lhs;
7929
+ node.typeAnnotation = this.tsParseTypeAnnotation(false);
7930
+ node.asserts = false;
7931
+ return this.finishNode(node, "TSTypePredicate");
7932
+ }
7933
+ tsParseThisTypeNode() {
7934
+ const node = this.startNode();
7935
+ this.next();
7936
+ return this.finishNode(node, "TSThisType");
7937
+ }
7938
+ tsParseTypeQuery() {
7939
+ const node = this.startNode();
7940
+ this.expect(87);
7941
+ if (this.match(83)) {
7942
+ node.exprName = this.tsParseImportType();
7943
+ } else {
7944
+ node.exprName = this.tsParseEntityName();
7945
+ }
7946
+ if (!this.hasPrecedingLineBreak() && this.match(47)) {
7947
+ node.typeParameters = this.tsParseTypeArguments();
7948
+ }
7949
+ return this.finishNode(node, "TSTypeQuery");
7950
+ }
7951
+ tsParseTypeParameter(parseModifiers) {
7952
+ const node = this.startNode();
7953
+ parseModifiers(node);
7954
+ node.name = this.tsParseTypeParameterName();
7955
+ node.constraint = this.tsEatThenParseType(81);
7956
+ node.default = this.tsEatThenParseType(29);
7957
+ return this.finishNode(node, "TSTypeParameter");
7958
+ }
7959
+ tsTryParseTypeParameters(parseModifiers) {
7960
+ if (this.match(47)) {
7961
+ return this.tsParseTypeParameters(parseModifiers);
7962
+ }
7963
+ }
7964
+ tsParseTypeParameters(parseModifiers) {
7965
+ const node = this.startNode();
7966
+ if (this.match(47) || this.match(140)) {
7967
+ this.next();
7968
+ } else {
7969
+ this.unexpected();
7970
+ }
7971
+ const refTrailingCommaPos = {
7972
+ value: -1
7973
+ };
7974
+ node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
7975
+ if (node.params.length === 0) {
7976
+ this.raise(TSErrors.EmptyTypeParameters, {
7977
+ at: node
7978
+ });
7979
+ }
7980
+ if (refTrailingCommaPos.value !== -1) {
7981
+ this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
7982
+ }
7983
+ return this.finishNode(node, "TSTypeParameterDeclaration");
7984
+ }
7985
+ tsFillSignature(returnToken, signature) {
7986
+ const returnTokenRequired = returnToken === 19;
7987
+ const paramsKey = "parameters";
7988
+ const returnTypeKey = "typeAnnotation";
7989
+ signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
7990
+ this.expect(10);
7991
+ signature[paramsKey] = this.tsParseBindingListForSignature();
7992
+ if (returnTokenRequired) {
7993
+ signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
7994
+ } else if (this.match(returnToken)) {
7995
+ signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
7996
+ }
7997
+ }
7998
+ tsParseBindingListForSignature() {
7999
+ return super.parseBindingList(11, 41, ParseBindingListFlags.IS_FUNCTION_PARAMS).map(pattern => {
8000
+ if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
8001
+ this.raise(TSErrors.UnsupportedSignatureParameterKind, {
8002
+ at: pattern,
8003
+ type: pattern.type
8004
+ });
8005
+ }
8006
+ return pattern;
8007
+ });
8008
+ }
8009
+ tsParseTypeMemberSemicolon() {
8010
+ if (!this.eat(12) && !this.isLineTerminator()) {
8011
+ this.expect(13);
8012
+ }
8013
+ }
8014
+ tsParseSignatureMember(kind, node) {
8015
+ this.tsFillSignature(14, node);
8016
+ this.tsParseTypeMemberSemicolon();
8017
+ return this.finishNode(node, kind);
8018
+ }
8019
+ tsIsUnambiguouslyIndexSignature() {
8020
+ this.next();
8021
+ if (tokenIsIdentifier(this.state.type)) {
8022
+ this.next();
8023
+ return this.match(14);
8024
+ }
8025
+ return false;
8026
+ }
8027
+ tsTryParseIndexSignature(node) {
8028
+ if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
8029
+ return undefined;
8030
+ }
8031
+ this.expect(0);
8032
+ const id = this.parseIdentifier();
8033
+ id.typeAnnotation = this.tsParseTypeAnnotation();
8034
+ this.resetEndLocation(id);
8035
+ this.expect(3);
8036
+ node.parameters = [id];
8037
+ const type = this.tsTryParseTypeAnnotation();
8038
+ if (type) node.typeAnnotation = type;
8039
+ this.tsParseTypeMemberSemicolon();
8040
+ return this.finishNode(node, "TSIndexSignature");
8041
+ }
8042
+ tsParsePropertyOrMethodSignature(node, readonly) {
8043
+ if (this.eat(17)) node.optional = true;
8044
+ const nodeAny = node;
8045
+ if (this.match(10) || this.match(47)) {
8046
+ if (readonly) {
8047
+ this.raise(TSErrors.ReadonlyForMethodSignature, {
7645
8048
  at: node
7646
8049
  });
7647
8050
  }
@@ -7723,10 +8126,9 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
7723
8126
  }
7724
8127
  }
7725
8128
  this.tsParseModifiers({
7726
- modified: node,
7727
8129
  allowedModifiers: ["readonly"],
7728
8130
  disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
7729
- });
8131
+ }, node);
7730
8132
  const idx = this.tsTryParseIndexSignature(node);
7731
8133
  if (idx) {
7732
8134
  return idx;
@@ -8075,7 +8477,7 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8075
8477
  } = this.state;
8076
8478
  const previousErrorCount = errors.length;
8077
8479
  try {
8078
- super.parseBindingList(3, 93, true);
8480
+ super.parseBindingList(3, 93, ParseBindingListFlags.ALLOW_EMPTY);
8079
8481
  return errors.length === previousErrorCount;
8080
8482
  } catch (_unused2) {
8081
8483
  return false;
@@ -8255,7 +8657,7 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8255
8657
  at: this.state.startLoc
8256
8658
  });
8257
8659
  }
8258
- node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
8660
+ node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
8259
8661
  if (this.eat(81)) {
8260
8662
  node.extends = this.tsParseHeritageClause("extends");
8261
8663
  }
@@ -8268,7 +8670,7 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8268
8670
  node.id = this.parseIdentifier();
8269
8671
  this.checkIdentifier(node.id, BIND_TS_TYPE);
8270
8672
  node.typeAnnotation = this.tsInType(() => {
8271
- node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
8673
+ node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
8272
8674
  this.expect(29);
8273
8675
  if (this.isContextual(112) && this.lookahead().type !== 16) {
8274
8676
  const node = this.startNode();
@@ -8574,7 +8976,7 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8574
8976
  this.state.maybeInArrowParameters = true;
8575
8977
  const res = this.tsTryParseAndCatch(() => {
8576
8978
  const node = this.startNodeAt(startLoc);
8577
- node.typeParameters = this.tsParseTypeParameters();
8979
+ node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
8578
8980
  super.parseFunctionParams(node);
8579
8981
  node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
8580
8982
  this.expect(19);
@@ -8613,28 +9015,22 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8613
9015
  if (this.tsIsDeclarationStart()) return false;
8614
9016
  return super.isExportDefaultSpecifier();
8615
9017
  }
8616
- parseAssignableListItem(allowModifiers, decorators) {
9018
+ parseAssignableListItem(flags, decorators) {
8617
9019
  const startLoc = this.state.startLoc;
8618
- let accessibility;
8619
- let readonly = false;
8620
- let override = false;
8621
- if (allowModifiers !== undefined) {
8622
- const modified = {};
8623
- this.tsParseModifiers({
8624
- modified,
8625
- allowedModifiers: ["public", "private", "protected", "override", "readonly"]
9020
+ const modified = {};
9021
+ this.tsParseModifiers({
9022
+ allowedModifiers: ["public", "private", "protected", "override", "readonly"]
9023
+ }, modified);
9024
+ const accessibility = modified.accessibility;
9025
+ const override = modified.override;
9026
+ const readonly = modified.readonly;
9027
+ if (!(flags & ParseBindingListFlags.IS_CONSTRUCTOR_PARAMS) && (accessibility || readonly || override)) {
9028
+ this.raise(TSErrors.UnexpectedParameterModifier, {
9029
+ at: startLoc
8626
9030
  });
8627
- accessibility = modified.accessibility;
8628
- override = modified.override;
8629
- readonly = modified.readonly;
8630
- if (allowModifiers === false && (accessibility || readonly || override)) {
8631
- this.raise(TSErrors.UnexpectedParameterModifier, {
8632
- at: startLoc
8633
- });
8634
- }
8635
9031
  }
8636
9032
  const left = this.parseMaybeDefault();
8637
- this.parseAssignableListItemTypes(left);
9033
+ this.parseAssignableListItemTypes(left, flags);
8638
9034
  const elt = this.parseMaybeDefault(left.loc.start, left);
8639
9035
  if (accessibility || readonly || override) {
8640
9036
  const pp = this.startNodeAt(startLoc);
@@ -8655,10 +9051,23 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8655
9051
  if (decorators.length) {
8656
9052
  left.decorators = decorators;
8657
9053
  }
8658
- return elt;
9054
+ return elt;
9055
+ }
9056
+ isSimpleParameter(node) {
9057
+ return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
9058
+ }
9059
+ tsDisallowOptionalPattern(node) {
9060
+ for (const param of node.params) {
9061
+ if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
9062
+ this.raise(TSErrors.PatternIsOptional, {
9063
+ at: param
9064
+ });
9065
+ }
9066
+ }
8659
9067
  }
8660
- isSimpleParameter(node) {
8661
- return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
9068
+ setArrowFunctionParameters(node, params, trailingCommaLoc) {
9069
+ super.setArrowFunctionParameters(node, params, trailingCommaLoc);
9070
+ this.tsDisallowOptionalPattern(node);
8662
9071
  }
8663
9072
  parseFunctionBodyAndFinish(node, type, isMethod = false) {
8664
9073
  if (this.match(14)) {
@@ -8676,6 +9085,7 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8676
9085
  return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
8677
9086
  }
8678
9087
  }
9088
+ this.tsDisallowOptionalPattern(node);
8679
9089
  return super.parseFunctionBodyAndFinish(node, type, isMethod);
8680
9090
  }
8681
9091
  registerFunctionStatementId(node) {
@@ -8868,11 +9278,13 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8868
9278
  this.semicolon();
8869
9279
  return this.finishNode(decl, "TSNamespaceExportDeclaration");
8870
9280
  } else {
8871
- if (this.isContextual(128) && this.lookahead().type === 5) {
8872
- this.next();
8873
- node.exportKind = "type";
8874
- } else {
8875
- node.exportKind = "value";
9281
+ node.exportKind = "value";
9282
+ if (this.isContextual(128)) {
9283
+ const ch = this.lookaheadCharCode();
9284
+ if (ch === 123 || ch === 42) {
9285
+ this.next();
9286
+ node.exportKind = "type";
9287
+ }
8876
9288
  }
8877
9289
  return super.parseExport(node, decorators);
8878
9290
  }
@@ -8950,1538 +9362,1138 @@ var typescript = (superClass => class TypeScriptParserMixin extends superClass {
8950
9362
  parseClassMember(classBody, member, state) {
8951
9363
  const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
8952
9364
  this.tsParseModifiers({
8953
- modified: member,
8954
9365
  allowedModifiers: modifiers,
8955
9366
  disallowedModifiers: ["in", "out"],
8956
9367
  stopOnStartOfClassStaticBlock: true,
8957
9368
  errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
8958
- });
9369
+ }, member);
8959
9370
  const callParseClassMemberWithIsStatic = () => {
8960
9371
  if (this.tsIsStartOfStaticBlocks()) {
8961
9372
  this.next();
8962
9373
  this.next();
8963
9374
  if (this.tsHasSomeModifiers(member, modifiers)) {
8964
9375
  this.raise(TSErrors.StaticBlockCannotHaveModifier, {
8965
- at: this.state.curPosition()
8966
- });
8967
- }
8968
- super.parseClassStaticBlock(classBody, member);
8969
- } else {
8970
- this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
8971
- }
8972
- };
8973
- if (member.declare) {
8974
- this.tsInAmbientContext(callParseClassMemberWithIsStatic);
8975
- } else {
8976
- callParseClassMemberWithIsStatic();
8977
- }
8978
- }
8979
- parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
8980
- const idx = this.tsTryParseIndexSignature(member);
8981
- if (idx) {
8982
- classBody.body.push(idx);
8983
- if (member.abstract) {
8984
- this.raise(TSErrors.IndexSignatureHasAbstract, {
8985
- at: member
8986
- });
8987
- }
8988
- if (member.accessibility) {
8989
- this.raise(TSErrors.IndexSignatureHasAccessibility, {
8990
- at: member,
8991
- modifier: member.accessibility
8992
- });
8993
- }
8994
- if (member.declare) {
8995
- this.raise(TSErrors.IndexSignatureHasDeclare, {
8996
- at: member
8997
- });
8998
- }
8999
- if (member.override) {
9000
- this.raise(TSErrors.IndexSignatureHasOverride, {
9001
- at: member
9002
- });
9003
- }
9004
- return;
9005
- }
9006
- if (!this.state.inAbstractClass && member.abstract) {
9007
- this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
9008
- at: member
9009
- });
9010
- }
9011
- if (member.override) {
9012
- if (!state.hadSuperClass) {
9013
- this.raise(TSErrors.OverrideNotInSubClass, {
9014
- at: member
9015
- });
9016
- }
9017
- }
9018
- super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
9019
- }
9020
- parsePostMemberNameModifiers(methodOrProp) {
9021
- const optional = this.eat(17);
9022
- if (optional) methodOrProp.optional = true;
9023
- if (methodOrProp.readonly && this.match(10)) {
9024
- this.raise(TSErrors.ClassMethodHasReadonly, {
9025
- at: methodOrProp
9026
- });
9027
- }
9028
- if (methodOrProp.declare && this.match(10)) {
9029
- this.raise(TSErrors.ClassMethodHasDeclare, {
9030
- at: methodOrProp
9031
- });
9032
- }
9033
- }
9034
- parseExpressionStatement(node, expr, decorators) {
9035
- const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
9036
- return decl || super.parseExpressionStatement(node, expr, decorators);
9037
- }
9038
- shouldParseExportDeclaration() {
9039
- if (this.tsIsDeclarationStart()) return true;
9040
- return super.shouldParseExportDeclaration();
9041
- }
9042
- parseConditional(expr, startLoc, refExpressionErrors) {
9043
- if (!this.state.maybeInArrowParameters || !this.match(17)) {
9044
- return super.parseConditional(expr, startLoc, refExpressionErrors);
9045
- }
9046
- const result = this.tryParse(() => super.parseConditional(expr, startLoc));
9047
- if (!result.node) {
9048
- if (result.error) {
9049
- super.setOptionalParametersError(refExpressionErrors, result.error);
9050
- }
9051
- return expr;
9052
- }
9053
- if (result.error) this.state = result.failState;
9054
- return result.node;
9055
- }
9056
- parseParenItem(node, startLoc) {
9057
- node = super.parseParenItem(node, startLoc);
9058
- if (this.eat(17)) {
9059
- node.optional = true;
9060
- this.resetEndLocation(node);
9061
- }
9062
- if (this.match(14)) {
9063
- const typeCastNode = this.startNodeAt(startLoc);
9064
- typeCastNode.expression = node;
9065
- typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
9066
- return this.finishNode(typeCastNode, "TSTypeCastExpression");
9067
- }
9068
- return node;
9069
- }
9070
- parseExportDeclaration(node) {
9071
- if (!this.state.isAmbientContext && this.isContextual(123)) {
9072
- return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
9073
- }
9074
- const startLoc = this.state.startLoc;
9075
- const isDeclare = this.eatContextual(123);
9076
- if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
9077
- throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
9078
- at: this.state.startLoc
9079
- });
9080
- }
9081
- const isIdentifier = tokenIsIdentifier(this.state.type);
9082
- const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
9083
- if (!declaration) return null;
9084
- if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
9085
- node.exportKind = "type";
9086
- }
9087
- if (isDeclare) {
9088
- this.resetStartLocation(declaration, startLoc);
9089
- declaration.declare = true;
9090
- }
9091
- return declaration;
9092
- }
9093
- parseClassId(node, isStatement, optionalId, bindingType) {
9094
- if ((!isStatement || optionalId) && this.isContextual(111)) {
9095
- return;
9096
- }
9097
- super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
9098
- const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers.bind(this));
9099
- if (typeParameters) node.typeParameters = typeParameters;
9100
- }
9101
- parseClassPropertyAnnotation(node) {
9102
- if (!node.optional) {
9103
- if (this.eat(35)) {
9104
- node.definite = true;
9105
- } else if (this.eat(17)) {
9106
- node.optional = true;
9107
- }
9108
- }
9109
- const type = this.tsTryParseTypeAnnotation();
9110
- if (type) node.typeAnnotation = type;
9111
- }
9112
- parseClassProperty(node) {
9113
- this.parseClassPropertyAnnotation(node);
9114
- if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
9115
- this.raise(TSErrors.DeclareClassFieldHasInitializer, {
9116
- at: this.state.startLoc
9117
- });
9118
- }
9119
- if (node.abstract && this.match(29)) {
9120
- const {
9121
- key
9122
- } = node;
9123
- this.raise(TSErrors.AbstractPropertyHasInitializer, {
9124
- at: this.state.startLoc,
9125
- propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
9126
- });
9127
- }
9128
- return super.parseClassProperty(node);
9129
- }
9130
- parseClassPrivateProperty(node) {
9131
- if (node.abstract) {
9132
- this.raise(TSErrors.PrivateElementHasAbstract, {
9133
- at: node
9134
- });
9135
- }
9136
- if (node.accessibility) {
9137
- this.raise(TSErrors.PrivateElementHasAccessibility, {
9138
- at: node,
9139
- modifier: node.accessibility
9140
- });
9141
- }
9142
- this.parseClassPropertyAnnotation(node);
9143
- return super.parseClassPrivateProperty(node);
9144
- }
9145
- parseClassAccessorProperty(node) {
9146
- this.parseClassPropertyAnnotation(node);
9147
- if (node.optional) {
9148
- this.raise(TSErrors.AccessorCannotBeOptional, {
9149
- at: node
9150
- });
9151
- }
9152
- return super.parseClassAccessorProperty(node);
9153
- }
9154
- pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
9155
- const typeParameters = this.tsTryParseTypeParameters();
9156
- if (typeParameters && isConstructor) {
9157
- this.raise(TSErrors.ConstructorHasTypeParameters, {
9158
- at: typeParameters
9159
- });
9160
- }
9161
- const {
9162
- declare = false,
9163
- kind
9164
- } = method;
9165
- if (declare && (kind === "get" || kind === "set")) {
9166
- this.raise(TSErrors.DeclareAccessor, {
9167
- at: method,
9168
- kind
9169
- });
9170
- }
9171
- if (typeParameters) method.typeParameters = typeParameters;
9172
- super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
9173
- }
9174
- pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
9175
- const typeParameters = this.tsTryParseTypeParameters();
9176
- if (typeParameters) method.typeParameters = typeParameters;
9177
- super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
9178
- }
9179
- declareClassPrivateMethodInScope(node, kind) {
9180
- if (node.type === "TSDeclareMethod") return;
9181
- if (node.type === "MethodDefinition" && !node.value.body) return;
9182
- super.declareClassPrivateMethodInScope(node, kind);
9183
- }
9184
- parseClassSuper(node) {
9185
- super.parseClassSuper(node);
9186
- if (node.superClass && (this.match(47) || this.match(51))) {
9187
- node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
9188
- }
9189
- if (this.eatContextual(111)) {
9190
- node.implements = this.tsParseHeritageClause("implements");
9191
- }
9192
- }
9193
- parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
9194
- const typeParameters = this.tsTryParseTypeParameters();
9195
- if (typeParameters) prop.typeParameters = typeParameters;
9196
- return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
9197
- }
9198
- parseFunctionParams(node, allowModifiers) {
9199
- const typeParameters = this.tsTryParseTypeParameters();
9200
- if (typeParameters) node.typeParameters = typeParameters;
9201
- super.parseFunctionParams(node, allowModifiers);
9202
- }
9203
- parseVarId(decl, kind) {
9204
- super.parseVarId(decl, kind);
9205
- if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
9206
- decl.definite = true;
9207
- }
9208
- const type = this.tsTryParseTypeAnnotation();
9209
- if (type) {
9210
- decl.id.typeAnnotation = type;
9211
- this.resetEndLocation(decl.id);
9212
- }
9213
- }
9214
- parseAsyncArrowFromCallExpression(node, call) {
9215
- if (this.match(14)) {
9216
- node.returnType = this.tsParseTypeAnnotation();
9376
+ at: this.state.curPosition()
9377
+ });
9378
+ }
9379
+ super.parseClassStaticBlock(classBody, member);
9380
+ } else {
9381
+ this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
9382
+ }
9383
+ };
9384
+ if (member.declare) {
9385
+ this.tsInAmbientContext(callParseClassMemberWithIsStatic);
9386
+ } else {
9387
+ callParseClassMemberWithIsStatic();
9217
9388
  }
9218
- return super.parseAsyncArrowFromCallExpression(node, call);
9219
9389
  }
9220
- parseMaybeAssign(refExpressionErrors, afterLeftParse) {
9221
- var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2, _jsx4, _typeCast3;
9222
- let state;
9223
- let jsx;
9224
- let typeCast;
9225
- if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
9226
- state = this.state.clone();
9227
- jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9228
- if (!jsx.error) return jsx.node;
9229
- const {
9230
- context
9231
- } = this.state;
9232
- const currentContext = context[context.length - 1];
9233
- if (currentContext === types.j_oTag || currentContext === types.j_expr) {
9234
- context.pop();
9390
+ parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
9391
+ const idx = this.tsTryParseIndexSignature(member);
9392
+ if (idx) {
9393
+ classBody.body.push(idx);
9394
+ if (member.abstract) {
9395
+ this.raise(TSErrors.IndexSignatureHasAbstract, {
9396
+ at: member
9397
+ });
9235
9398
  }
9236
- }
9237
- if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
9238
- return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9239
- }
9240
- if (!state || state === this.state) state = this.state.clone();
9241
- let typeParameters;
9242
- const arrow = this.tryParse(abort => {
9243
- var _expr$extra, _typeParameters;
9244
- typeParameters = this.tsParseTypeParameters();
9245
- const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9246
- if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
9247
- abort();
9399
+ if (member.accessibility) {
9400
+ this.raise(TSErrors.IndexSignatureHasAccessibility, {
9401
+ at: member,
9402
+ modifier: member.accessibility
9403
+ });
9248
9404
  }
9249
- if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
9250
- this.resetStartLocationFromNode(expr, typeParameters);
9405
+ if (member.declare) {
9406
+ this.raise(TSErrors.IndexSignatureHasDeclare, {
9407
+ at: member
9408
+ });
9251
9409
  }
9252
- expr.typeParameters = typeParameters;
9253
- return expr;
9254
- }, state);
9255
- if (!arrow.error && !arrow.aborted) {
9256
- if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9257
- return arrow.node;
9258
- }
9259
- if (!jsx) {
9260
- assert(!this.hasPlugin("jsx"));
9261
- typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9262
- if (!typeCast.error) return typeCast.node;
9263
- }
9264
- if ((_jsx2 = jsx) != null && _jsx2.node) {
9265
- this.state = jsx.failState;
9266
- return jsx.node;
9410
+ if (member.override) {
9411
+ this.raise(TSErrors.IndexSignatureHasOverride, {
9412
+ at: member
9413
+ });
9414
+ }
9415
+ return;
9267
9416
  }
9268
- if (arrow.node) {
9269
- this.state = arrow.failState;
9270
- if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9271
- return arrow.node;
9417
+ if (!this.state.inAbstractClass && member.abstract) {
9418
+ this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
9419
+ at: member
9420
+ });
9272
9421
  }
9273
- if ((_typeCast = typeCast) != null && _typeCast.node) {
9274
- this.state = typeCast.failState;
9275
- return typeCast.node;
9422
+ if (member.override) {
9423
+ if (!state.hadSuperClass) {
9424
+ this.raise(TSErrors.OverrideNotInSubClass, {
9425
+ at: member
9426
+ });
9427
+ }
9276
9428
  }
9277
- if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
9278
- if (arrow.thrown) throw arrow.error;
9279
- if ((_typeCast2 = typeCast) != null && _typeCast2.thrown) throw typeCast.error;
9280
- throw ((_jsx4 = jsx) == null ? void 0 : _jsx4.error) || arrow.error || ((_typeCast3 = typeCast) == null ? void 0 : _typeCast3.error);
9429
+ super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
9281
9430
  }
9282
- reportReservedArrowTypeParam(node) {
9283
- var _node$extra;
9284
- if (node.params.length === 1 && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
9285
- this.raise(TSErrors.ReservedArrowTypeParam, {
9286
- at: node
9431
+ parsePostMemberNameModifiers(methodOrProp) {
9432
+ const optional = this.eat(17);
9433
+ if (optional) methodOrProp.optional = true;
9434
+ if (methodOrProp.readonly && this.match(10)) {
9435
+ this.raise(TSErrors.ClassMethodHasReadonly, {
9436
+ at: methodOrProp
9287
9437
  });
9288
9438
  }
9289
- }
9290
- parseMaybeUnary(refExpressionErrors, sawUnary) {
9291
- if (!this.hasPlugin("jsx") && this.match(47)) {
9292
- return this.tsParseTypeAssertion();
9293
- } else {
9294
- return super.parseMaybeUnary(refExpressionErrors, sawUnary);
9439
+ if (methodOrProp.declare && this.match(10)) {
9440
+ this.raise(TSErrors.ClassMethodHasDeclare, {
9441
+ at: methodOrProp
9442
+ });
9295
9443
  }
9296
9444
  }
9297
- parseArrow(node) {
9298
- if (this.match(14)) {
9299
- const result = this.tryParse(abort => {
9300
- const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
9301
- if (this.canInsertSemicolon() || !this.match(19)) abort();
9302
- return returnType;
9303
- });
9304
- if (result.aborted) return;
9305
- if (!result.thrown) {
9306
- if (result.error) this.state = result.failState;
9307
- node.returnType = result.node;
9445
+ parseExpressionStatement(node, expr, decorators) {
9446
+ const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
9447
+ return decl || super.parseExpressionStatement(node, expr, decorators);
9448
+ }
9449
+ shouldParseExportDeclaration() {
9450
+ if (this.tsIsDeclarationStart()) return true;
9451
+ return super.shouldParseExportDeclaration();
9452
+ }
9453
+ parseConditional(expr, startLoc, refExpressionErrors) {
9454
+ if (!this.state.maybeInArrowParameters || !this.match(17)) {
9455
+ return super.parseConditional(expr, startLoc, refExpressionErrors);
9456
+ }
9457
+ const result = this.tryParse(() => super.parseConditional(expr, startLoc));
9458
+ if (!result.node) {
9459
+ if (result.error) {
9460
+ super.setOptionalParametersError(refExpressionErrors, result.error);
9308
9461
  }
9462
+ return expr;
9309
9463
  }
9310
- return super.parseArrow(node);
9464
+ if (result.error) this.state = result.failState;
9465
+ return result.node;
9311
9466
  }
9312
- parseAssignableListItemTypes(param) {
9467
+ parseParenItem(node, startLoc) {
9468
+ node = super.parseParenItem(node, startLoc);
9313
9469
  if (this.eat(17)) {
9314
- if (param.type !== "Identifier" && !this.state.isAmbientContext && !this.state.inType) {
9315
- this.raise(TSErrors.PatternIsOptional, {
9316
- at: param
9317
- });
9318
- }
9319
- param.optional = true;
9470
+ node.optional = true;
9471
+ this.resetEndLocation(node);
9320
9472
  }
9321
- const type = this.tsTryParseTypeAnnotation();
9322
- if (type) param.typeAnnotation = type;
9323
- this.resetEndLocation(param);
9324
- return param;
9325
- }
9326
- isAssignable(node, isBinding) {
9327
- switch (node.type) {
9328
- case "TSTypeCastExpression":
9329
- return this.isAssignable(node.expression, isBinding);
9330
- case "TSParameterProperty":
9331
- return true;
9332
- default:
9333
- return super.isAssignable(node, isBinding);
9473
+ if (this.match(14)) {
9474
+ const typeCastNode = this.startNodeAt(startLoc);
9475
+ typeCastNode.expression = node;
9476
+ typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
9477
+ return this.finishNode(typeCastNode, "TSTypeCastExpression");
9334
9478
  }
9479
+ return node;
9335
9480
  }
9336
- toAssignable(node, isLHS = false) {
9337
- switch (node.type) {
9338
- case "ParenthesizedExpression":
9339
- this.toAssignableParenthesizedExpression(node, isLHS);
9340
- break;
9341
- case "TSAsExpression":
9342
- case "TSSatisfiesExpression":
9343
- case "TSNonNullExpression":
9344
- case "TSTypeAssertion":
9345
- if (isLHS) {
9346
- this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
9347
- at: node
9348
- });
9349
- } else {
9350
- this.raise(TSErrors.UnexpectedTypeCastInParameter, {
9351
- at: node
9352
- });
9353
- }
9354
- this.toAssignable(node.expression, isLHS);
9355
- break;
9356
- case "AssignmentExpression":
9357
- if (!isLHS && node.left.type === "TSTypeCastExpression") {
9358
- node.left = this.typeCastToParameter(node.left);
9359
- }
9360
- default:
9361
- super.toAssignable(node, isLHS);
9481
+ parseExportDeclaration(node) {
9482
+ if (!this.state.isAmbientContext && this.isContextual(123)) {
9483
+ return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
9362
9484
  }
9363
- }
9364
- toAssignableParenthesizedExpression(node, isLHS) {
9365
- switch (node.expression.type) {
9366
- case "TSAsExpression":
9367
- case "TSSatisfiesExpression":
9368
- case "TSNonNullExpression":
9369
- case "TSTypeAssertion":
9370
- case "ParenthesizedExpression":
9371
- this.toAssignable(node.expression, isLHS);
9372
- break;
9373
- default:
9374
- super.toAssignable(node, isLHS);
9485
+ const startLoc = this.state.startLoc;
9486
+ const isDeclare = this.eatContextual(123);
9487
+ if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
9488
+ throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
9489
+ at: this.state.startLoc
9490
+ });
9375
9491
  }
9376
- }
9377
- checkToRestConversion(node, allowPattern) {
9378
- switch (node.type) {
9379
- case "TSAsExpression":
9380
- case "TSSatisfiesExpression":
9381
- case "TSTypeAssertion":
9382
- case "TSNonNullExpression":
9383
- this.checkToRestConversion(node.expression, false);
9384
- break;
9385
- default:
9386
- super.checkToRestConversion(node, allowPattern);
9492
+ const isIdentifier = tokenIsIdentifier(this.state.type);
9493
+ const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
9494
+ if (!declaration) return null;
9495
+ if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
9496
+ node.exportKind = "type";
9387
9497
  }
9498
+ if (isDeclare) {
9499
+ this.resetStartLocation(declaration, startLoc);
9500
+ declaration.declare = true;
9501
+ }
9502
+ return declaration;
9388
9503
  }
9389
- isValidLVal(type, isUnparenthesizedInAssign, binding) {
9390
- return getOwn$1({
9391
- TSTypeCastExpression: true,
9392
- TSParameterProperty: "parameter",
9393
- TSNonNullExpression: "expression",
9394
- TSAsExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
9395
- TSSatisfiesExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
9396
- TSTypeAssertion: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true]
9397
- }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
9398
- }
9399
- parseBindingAtom() {
9400
- switch (this.state.type) {
9401
- case 78:
9402
- return this.parseIdentifier(true);
9403
- default:
9404
- return super.parseBindingAtom();
9504
+ parseClassId(node, isStatement, optionalId, bindingType) {
9505
+ if ((!isStatement || optionalId) && this.isContextual(111)) {
9506
+ return;
9405
9507
  }
9508
+ super.parseClassId(node, isStatement, optionalId, node.declare ? BIND_TS_AMBIENT : BIND_CLASS);
9509
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
9510
+ if (typeParameters) node.typeParameters = typeParameters;
9406
9511
  }
9407
- parseMaybeDecoratorArguments(expr) {
9408
- if (this.match(47) || this.match(51)) {
9409
- const typeArguments = this.tsParseTypeArgumentsInExpression();
9410
- if (this.match(10)) {
9411
- const call = super.parseMaybeDecoratorArguments(expr);
9412
- call.typeParameters = typeArguments;
9413
- return call;
9512
+ parseClassPropertyAnnotation(node) {
9513
+ if (!node.optional) {
9514
+ if (this.eat(35)) {
9515
+ node.definite = true;
9516
+ } else if (this.eat(17)) {
9517
+ node.optional = true;
9414
9518
  }
9415
- this.unexpected(null, 10);
9416
9519
  }
9417
- return super.parseMaybeDecoratorArguments(expr);
9520
+ const type = this.tsTryParseTypeAnnotation();
9521
+ if (type) node.typeAnnotation = type;
9418
9522
  }
9419
- checkCommaAfterRest(close) {
9420
- if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
9421
- this.next();
9422
- return false;
9423
- } else {
9424
- return super.checkCommaAfterRest(close);
9523
+ parseClassProperty(node) {
9524
+ this.parseClassPropertyAnnotation(node);
9525
+ if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
9526
+ this.raise(TSErrors.DeclareClassFieldHasInitializer, {
9527
+ at: this.state.startLoc
9528
+ });
9425
9529
  }
9426
- }
9427
- isClassMethod() {
9428
- return this.match(47) || super.isClassMethod();
9429
- }
9430
- isClassProperty() {
9431
- return this.match(35) || this.match(14) || super.isClassProperty();
9432
- }
9433
- parseMaybeDefault(startLoc, left) {
9434
- const node = super.parseMaybeDefault(startLoc, left);
9435
- if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
9436
- this.raise(TSErrors.TypeAnnotationAfterAssign, {
9437
- at: node.typeAnnotation
9530
+ if (node.abstract && this.match(29)) {
9531
+ const {
9532
+ key
9533
+ } = node;
9534
+ this.raise(TSErrors.AbstractPropertyHasInitializer, {
9535
+ at: this.state.startLoc,
9536
+ propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
9438
9537
  });
9439
9538
  }
9440
- return node;
9539
+ return super.parseClassProperty(node);
9441
9540
  }
9442
- getTokenFromCode(code) {
9443
- if (this.state.inType) {
9444
- if (code === 62) {
9445
- return this.finishOp(48, 1);
9446
- }
9447
- if (code === 60) {
9448
- return this.finishOp(47, 1);
9449
- }
9541
+ parseClassPrivateProperty(node) {
9542
+ if (node.abstract) {
9543
+ this.raise(TSErrors.PrivateElementHasAbstract, {
9544
+ at: node
9545
+ });
9450
9546
  }
9451
- return super.getTokenFromCode(code);
9547
+ if (node.accessibility) {
9548
+ this.raise(TSErrors.PrivateElementHasAccessibility, {
9549
+ at: node,
9550
+ modifier: node.accessibility
9551
+ });
9552
+ }
9553
+ this.parseClassPropertyAnnotation(node);
9554
+ return super.parseClassPrivateProperty(node);
9452
9555
  }
9453
- reScan_lt_gt() {
9454
- const {
9455
- type
9456
- } = this.state;
9457
- if (type === 47) {
9458
- this.state.pos -= 1;
9459
- this.readToken_lt();
9460
- } else if (type === 48) {
9461
- this.state.pos -= 1;
9462
- this.readToken_gt();
9556
+ parseClassAccessorProperty(node) {
9557
+ this.parseClassPropertyAnnotation(node);
9558
+ if (node.optional) {
9559
+ this.raise(TSErrors.AccessorCannotBeOptional, {
9560
+ at: node
9561
+ });
9463
9562
  }
9563
+ return super.parseClassAccessorProperty(node);
9464
9564
  }
9465
- reScan_lt() {
9565
+ pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
9566
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9567
+ if (typeParameters && isConstructor) {
9568
+ this.raise(TSErrors.ConstructorHasTypeParameters, {
9569
+ at: typeParameters
9570
+ });
9571
+ }
9466
9572
  const {
9467
- type
9468
- } = this.state;
9469
- if (type === 51) {
9470
- this.state.pos -= 2;
9471
- this.finishOp(47, 1);
9472
- return 47;
9573
+ declare = false,
9574
+ kind
9575
+ } = method;
9576
+ if (declare && (kind === "get" || kind === "set")) {
9577
+ this.raise(TSErrors.DeclareAccessor, {
9578
+ at: method,
9579
+ kind
9580
+ });
9473
9581
  }
9474
- return type;
9582
+ if (typeParameters) method.typeParameters = typeParameters;
9583
+ super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
9475
9584
  }
9476
- toAssignableList(exprList, trailingCommaLoc, isLHS) {
9477
- for (let i = 0; i < exprList.length; i++) {
9478
- const expr = exprList[i];
9479
- if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
9480
- exprList[i] = this.typeCastToParameter(expr);
9481
- }
9482
- }
9483
- super.toAssignableList(exprList, trailingCommaLoc, isLHS);
9585
+ pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
9586
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9587
+ if (typeParameters) method.typeParameters = typeParameters;
9588
+ super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
9484
9589
  }
9485
- typeCastToParameter(node) {
9486
- node.expression.typeAnnotation = node.typeAnnotation;
9487
- this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
9488
- return node.expression;
9590
+ declareClassPrivateMethodInScope(node, kind) {
9591
+ if (node.type === "TSDeclareMethod") return;
9592
+ if (node.type === "MethodDefinition" && !node.value.body) return;
9593
+ super.declareClassPrivateMethodInScope(node, kind);
9489
9594
  }
9490
- shouldParseArrow(params) {
9491
- if (this.match(14)) {
9492
- return params.every(expr => this.isAssignable(expr, true));
9595
+ parseClassSuper(node) {
9596
+ super.parseClassSuper(node);
9597
+ if (node.superClass && (this.match(47) || this.match(51))) {
9598
+ node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
9599
+ }
9600
+ if (this.eatContextual(111)) {
9601
+ node.implements = this.tsParseHeritageClause("implements");
9493
9602
  }
9494
- return super.shouldParseArrow(params);
9495
9603
  }
9496
- shouldParseAsyncArrow() {
9497
- return this.match(14) || super.shouldParseAsyncArrow();
9604
+ parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
9605
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9606
+ if (typeParameters) prop.typeParameters = typeParameters;
9607
+ return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
9498
9608
  }
9499
- canHaveLeadingDecorator() {
9500
- return super.canHaveLeadingDecorator() || this.isAbstractClass();
9609
+ parseFunctionParams(node, isConstructor) {
9610
+ const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
9611
+ if (typeParameters) node.typeParameters = typeParameters;
9612
+ super.parseFunctionParams(node, isConstructor);
9501
9613
  }
9502
- jsxParseOpeningElementAfterName(node) {
9503
- if (this.match(47) || this.match(51)) {
9504
- const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
9505
- if (typeArguments) node.typeParameters = typeArguments;
9614
+ parseVarId(decl, kind) {
9615
+ super.parseVarId(decl, kind);
9616
+ if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
9617
+ decl.definite = true;
9506
9618
  }
9507
- return super.jsxParseOpeningElementAfterName(node);
9508
- }
9509
- getGetterSetterExpectedParamCount(method) {
9510
- const baseCount = super.getGetterSetterExpectedParamCount(method);
9511
- const params = this.getObjectOrClassMethodParams(method);
9512
- const firstParam = params[0];
9513
- const hasContextParam = firstParam && this.isThisParam(firstParam);
9514
- return hasContextParam ? baseCount + 1 : baseCount;
9515
- }
9516
- parseCatchClauseParam() {
9517
- const param = super.parseCatchClauseParam();
9518
9619
  const type = this.tsTryParseTypeAnnotation();
9519
9620
  if (type) {
9520
- param.typeAnnotation = type;
9521
- this.resetEndLocation(param);
9621
+ decl.id.typeAnnotation = type;
9622
+ this.resetEndLocation(decl.id);
9522
9623
  }
9523
- return param;
9524
9624
  }
9525
- tsInAmbientContext(cb) {
9526
- const oldIsAmbientContext = this.state.isAmbientContext;
9527
- this.state.isAmbientContext = true;
9528
- try {
9529
- return cb();
9530
- } finally {
9531
- this.state.isAmbientContext = oldIsAmbientContext;
9625
+ parseAsyncArrowFromCallExpression(node, call) {
9626
+ if (this.match(14)) {
9627
+ node.returnType = this.tsParseTypeAnnotation();
9532
9628
  }
9629
+ return super.parseAsyncArrowFromCallExpression(node, call);
9533
9630
  }
9534
- parseClass(node, isStatement, optionalId) {
9535
- const oldInAbstractClass = this.state.inAbstractClass;
9536
- this.state.inAbstractClass = !!node.abstract;
9537
- try {
9538
- return super.parseClass(node, isStatement, optionalId);
9539
- } finally {
9540
- this.state.inAbstractClass = oldInAbstractClass;
9631
+ parseMaybeAssign(refExpressionErrors, afterLeftParse) {
9632
+ var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2, _jsx4, _typeCast3;
9633
+ let state;
9634
+ let jsx;
9635
+ let typeCast;
9636
+ if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
9637
+ state = this.state.clone();
9638
+ jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9639
+ if (!jsx.error) return jsx.node;
9640
+ const {
9641
+ context
9642
+ } = this.state;
9643
+ const currentContext = context[context.length - 1];
9644
+ if (currentContext === types.j_oTag || currentContext === types.j_expr) {
9645
+ context.pop();
9646
+ }
9647
+ }
9648
+ if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
9649
+ return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9650
+ }
9651
+ if (!state || state === this.state) state = this.state.clone();
9652
+ let typeParameters;
9653
+ const arrow = this.tryParse(abort => {
9654
+ var _expr$extra, _typeParameters;
9655
+ typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
9656
+ const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
9657
+ if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
9658
+ abort();
9659
+ }
9660
+ if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
9661
+ this.resetStartLocationFromNode(expr, typeParameters);
9662
+ }
9663
+ expr.typeParameters = typeParameters;
9664
+ return expr;
9665
+ }, state);
9666
+ if (!arrow.error && !arrow.aborted) {
9667
+ if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9668
+ return arrow.node;
9669
+ }
9670
+ if (!jsx) {
9671
+ assert(!this.hasPlugin("jsx"));
9672
+ typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
9673
+ if (!typeCast.error) return typeCast.node;
9674
+ }
9675
+ if ((_jsx2 = jsx) != null && _jsx2.node) {
9676
+ this.state = jsx.failState;
9677
+ return jsx.node;
9678
+ }
9679
+ if (arrow.node) {
9680
+ this.state = arrow.failState;
9681
+ if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
9682
+ return arrow.node;
9541
9683
  }
9542
- }
9543
- tsParseAbstractDeclaration(node, decorators) {
9544
- if (this.match(80)) {
9545
- node.abstract = true;
9546
- return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
9547
- } else if (this.isContextual(127)) {
9548
- if (!this.hasFollowingLineBreak()) {
9549
- node.abstract = true;
9550
- this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
9551
- at: node
9552
- });
9553
- return this.tsParseInterfaceDeclaration(node);
9554
- }
9555
- } else {
9556
- this.unexpected(null, 80);
9684
+ if ((_typeCast = typeCast) != null && _typeCast.node) {
9685
+ this.state = typeCast.failState;
9686
+ return typeCast.node;
9557
9687
  }
9688
+ if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
9689
+ if (arrow.thrown) throw arrow.error;
9690
+ if ((_typeCast2 = typeCast) != null && _typeCast2.thrown) throw typeCast.error;
9691
+ throw ((_jsx4 = jsx) == null ? void 0 : _jsx4.error) || arrow.error || ((_typeCast3 = typeCast) == null ? void 0 : _typeCast3.error);
9558
9692
  }
9559
- parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
9560
- const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
9561
- if (method.abstract) {
9562
- const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
9563
- if (hasBody) {
9564
- const {
9565
- key
9566
- } = method;
9567
- this.raise(TSErrors.AbstractMethodHasImplementation, {
9568
- at: method,
9569
- methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
9570
- });
9571
- }
9693
+ reportReservedArrowTypeParam(node) {
9694
+ var _node$extra;
9695
+ if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
9696
+ this.raise(TSErrors.ReservedArrowTypeParam, {
9697
+ at: node
9698
+ });
9572
9699
  }
9573
- return method;
9574
- }
9575
- tsParseTypeParameterName() {
9576
- const typeName = this.parseIdentifier();
9577
- return typeName.name;
9578
- }
9579
- shouldParseAsAmbientContext() {
9580
- return !!this.getPluginOption("typescript", "dts");
9581
9700
  }
9582
- parse() {
9583
- if (this.shouldParseAsAmbientContext()) {
9584
- this.state.isAmbientContext = true;
9701
+ parseMaybeUnary(refExpressionErrors, sawUnary) {
9702
+ if (!this.hasPlugin("jsx") && this.match(47)) {
9703
+ return this.tsParseTypeAssertion();
9704
+ } else {
9705
+ return super.parseMaybeUnary(refExpressionErrors, sawUnary);
9585
9706
  }
9586
- return super.parse();
9587
9707
  }
9588
- getExpression() {
9589
- if (this.shouldParseAsAmbientContext()) {
9590
- this.state.isAmbientContext = true;
9708
+ parseArrow(node) {
9709
+ if (this.match(14)) {
9710
+ const result = this.tryParse(abort => {
9711
+ const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
9712
+ if (this.canInsertSemicolon() || !this.match(19)) abort();
9713
+ return returnType;
9714
+ });
9715
+ if (result.aborted) return;
9716
+ if (!result.thrown) {
9717
+ if (result.error) this.state = result.failState;
9718
+ node.returnType = result.node;
9719
+ }
9591
9720
  }
9592
- return super.getExpression();
9721
+ return super.parseArrow(node);
9593
9722
  }
9594
- parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
9595
- if (!isString && isMaybeTypeOnly) {
9596
- this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
9597
- return this.finishNode(node, "ExportSpecifier");
9723
+ parseAssignableListItemTypes(param, flags) {
9724
+ if (!(flags & ParseBindingListFlags.IS_FUNCTION_PARAMS)) return param;
9725
+ if (this.eat(17)) {
9726
+ param.optional = true;
9598
9727
  }
9599
- node.exportKind = "value";
9600
- return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
9728
+ const type = this.tsTryParseTypeAnnotation();
9729
+ if (type) param.typeAnnotation = type;
9730
+ this.resetEndLocation(param);
9731
+ return param;
9601
9732
  }
9602
- parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
9603
- if (!importedIsString && isMaybeTypeOnly) {
9604
- this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
9605
- return this.finishNode(specifier, "ImportSpecifier");
9733
+ isAssignable(node, isBinding) {
9734
+ switch (node.type) {
9735
+ case "TSTypeCastExpression":
9736
+ return this.isAssignable(node.expression, isBinding);
9737
+ case "TSParameterProperty":
9738
+ return true;
9739
+ default:
9740
+ return super.isAssignable(node, isBinding);
9606
9741
  }
9607
- specifier.importKind = "value";
9608
- return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
9609
9742
  }
9610
- parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
9611
- const leftOfAsKey = isImport ? "imported" : "local";
9612
- const rightOfAsKey = isImport ? "local" : "exported";
9613
- let leftOfAs = node[leftOfAsKey];
9614
- let rightOfAs;
9615
- let hasTypeSpecifier = false;
9616
- let canParseAsKeyword = true;
9617
- const loc = leftOfAs.loc.start;
9618
- if (this.isContextual(93)) {
9619
- const firstAs = this.parseIdentifier();
9620
- if (this.isContextual(93)) {
9621
- const secondAs = this.parseIdentifier();
9622
- if (tokenIsKeywordOrIdentifier(this.state.type)) {
9623
- hasTypeSpecifier = true;
9624
- leftOfAs = firstAs;
9625
- rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
9626
- canParseAsKeyword = false;
9743
+ toAssignable(node, isLHS = false) {
9744
+ switch (node.type) {
9745
+ case "ParenthesizedExpression":
9746
+ this.toAssignableParenthesizedExpression(node, isLHS);
9747
+ break;
9748
+ case "TSAsExpression":
9749
+ case "TSSatisfiesExpression":
9750
+ case "TSNonNullExpression":
9751
+ case "TSTypeAssertion":
9752
+ if (isLHS) {
9753
+ this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
9754
+ at: node
9755
+ });
9627
9756
  } else {
9628
- rightOfAs = secondAs;
9629
- canParseAsKeyword = false;
9757
+ this.raise(TSErrors.UnexpectedTypeCastInParameter, {
9758
+ at: node
9759
+ });
9630
9760
  }
9631
- } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
9632
- canParseAsKeyword = false;
9633
- rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
9634
- } else {
9635
- hasTypeSpecifier = true;
9636
- leftOfAs = firstAs;
9637
- }
9638
- } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
9639
- hasTypeSpecifier = true;
9640
- if (isImport) {
9641
- leftOfAs = this.parseIdentifier(true);
9642
- if (!this.isContextual(93)) {
9643
- this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
9761
+ this.toAssignable(node.expression, isLHS);
9762
+ break;
9763
+ case "AssignmentExpression":
9764
+ if (!isLHS && node.left.type === "TSTypeCastExpression") {
9765
+ node.left = this.typeCastToParameter(node.left);
9644
9766
  }
9645
- } else {
9646
- leftOfAs = this.parseModuleExportName();
9647
- }
9648
- }
9649
- if (hasTypeSpecifier && isInTypeOnlyImportExport) {
9650
- this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
9651
- at: loc
9652
- });
9653
- }
9654
- node[leftOfAsKey] = leftOfAs;
9655
- node[rightOfAsKey] = rightOfAs;
9656
- const kindKey = isImport ? "importKind" : "exportKind";
9657
- node[kindKey] = hasTypeSpecifier ? "type" : "value";
9658
- if (canParseAsKeyword && this.eatContextual(93)) {
9659
- node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
9660
- }
9661
- if (!node[rightOfAsKey]) {
9662
- node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
9663
- }
9664
- if (isImport) {
9665
- this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
9767
+ default:
9768
+ super.toAssignable(node, isLHS);
9666
9769
  }
9667
9770
  }
9668
- });
9669
- function isPossiblyLiteralEnum(expression) {
9670
- if (expression.type !== "MemberExpression") return false;
9671
- const {
9672
- computed,
9673
- property
9674
- } = expression;
9675
- if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
9676
- return false;
9677
- }
9678
- return isUncomputedMemberExpressionChain(expression.object);
9679
- }
9680
- function isValidAmbientConstInitializer(expression, estree) {
9681
- var _expression$extra;
9682
- const {
9683
- type
9684
- } = expression;
9685
- if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
9686
- return false;
9687
- }
9688
- if (estree) {
9689
- if (type === "Literal") {
9690
- const {
9691
- value
9692
- } = expression;
9693
- if (typeof value === "string" || typeof value === "boolean") {
9694
- return true;
9695
- }
9696
- }
9697
- } else {
9698
- if (type === "StringLiteral" || type === "BooleanLiteral") {
9699
- return true;
9771
+ toAssignableParenthesizedExpression(node, isLHS) {
9772
+ switch (node.expression.type) {
9773
+ case "TSAsExpression":
9774
+ case "TSSatisfiesExpression":
9775
+ case "TSNonNullExpression":
9776
+ case "TSTypeAssertion":
9777
+ case "ParenthesizedExpression":
9778
+ this.toAssignable(node.expression, isLHS);
9779
+ break;
9780
+ default:
9781
+ super.toAssignable(node, isLHS);
9700
9782
  }
9701
9783
  }
9702
- if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
9703
- return true;
9704
- }
9705
- if (type === "TemplateLiteral" && expression.expressions.length === 0) {
9706
- return true;
9784
+ checkToRestConversion(node, allowPattern) {
9785
+ switch (node.type) {
9786
+ case "TSAsExpression":
9787
+ case "TSSatisfiesExpression":
9788
+ case "TSTypeAssertion":
9789
+ case "TSNonNullExpression":
9790
+ this.checkToRestConversion(node.expression, false);
9791
+ break;
9792
+ default:
9793
+ super.checkToRestConversion(node, allowPattern);
9794
+ }
9707
9795
  }
9708
- if (isPossiblyLiteralEnum(expression)) {
9709
- return true;
9796
+ isValidLVal(type, isUnparenthesizedInAssign, binding) {
9797
+ return getOwn({
9798
+ TSTypeCastExpression: true,
9799
+ TSParameterProperty: "parameter",
9800
+ TSNonNullExpression: "expression",
9801
+ TSAsExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
9802
+ TSSatisfiesExpression: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true],
9803
+ TSTypeAssertion: (binding !== BIND_NONE || !isUnparenthesizedInAssign) && ["expression", true]
9804
+ }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
9710
9805
  }
9711
- return false;
9712
- }
9713
- function isNumber(expression, estree) {
9714
- if (estree) {
9715
- return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
9716
- } else {
9717
- return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
9806
+ parseBindingAtom() {
9807
+ switch (this.state.type) {
9808
+ case 78:
9809
+ return this.parseIdentifier(true);
9810
+ default:
9811
+ return super.parseBindingAtom();
9812
+ }
9718
9813
  }
9719
- }
9720
- function isNegativeNumber(expression, estree) {
9721
- if (expression.type === "UnaryExpression") {
9722
- const {
9723
- operator,
9724
- argument
9725
- } = expression;
9726
- if (operator === "-" && isNumber(argument, estree)) {
9727
- return true;
9814
+ parseMaybeDecoratorArguments(expr) {
9815
+ if (this.match(47) || this.match(51)) {
9816
+ const typeArguments = this.tsParseTypeArgumentsInExpression();
9817
+ if (this.match(10)) {
9818
+ const call = super.parseMaybeDecoratorArguments(expr);
9819
+ call.typeParameters = typeArguments;
9820
+ return call;
9821
+ }
9822
+ this.unexpected(null, 10);
9728
9823
  }
9824
+ return super.parseMaybeDecoratorArguments(expr);
9729
9825
  }
9730
- return false;
9731
- }
9732
- function isUncomputedMemberExpressionChain(expression) {
9733
- if (expression.type === "Identifier") return true;
9734
- if (expression.type !== "MemberExpression") return false;
9735
- if (expression.computed) return false;
9736
- return isUncomputedMemberExpressionChain(expression.object);
9737
- }
9738
-
9739
- const PlaceholderErrors = ParseErrorEnum`placeholders`({
9740
- ClassNameIsRequired: "A class name is required.",
9741
- UnexpectedSpace: "Unexpected space in placeholder."
9742
- });
9743
- var placeholders = (superClass => class PlaceholdersParserMixin extends superClass {
9744
- parsePlaceholder(expectedNode) {
9745
- if (this.match(142)) {
9746
- const node = this.startNode();
9826
+ checkCommaAfterRest(close) {
9827
+ if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
9747
9828
  this.next();
9748
- this.assertNoSpace();
9749
- node.name = super.parseIdentifier(true);
9750
- this.assertNoSpace();
9751
- this.expect(142);
9752
- return this.finishPlaceholder(node, expectedNode);
9829
+ return false;
9830
+ } else {
9831
+ return super.checkCommaAfterRest(close);
9753
9832
  }
9754
9833
  }
9755
- finishPlaceholder(node, expectedNode) {
9756
- const isFinished = !!(node.expectedNode && node.type === "Placeholder");
9757
- node.expectedNode = expectedNode;
9758
- return isFinished ? node : this.finishNode(node, "Placeholder");
9834
+ isClassMethod() {
9835
+ return this.match(47) || super.isClassMethod();
9836
+ }
9837
+ isClassProperty() {
9838
+ return this.match(35) || this.match(14) || super.isClassProperty();
9839
+ }
9840
+ parseMaybeDefault(startLoc, left) {
9841
+ const node = super.parseMaybeDefault(startLoc, left);
9842
+ if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
9843
+ this.raise(TSErrors.TypeAnnotationAfterAssign, {
9844
+ at: node.typeAnnotation
9845
+ });
9846
+ }
9847
+ return node;
9759
9848
  }
9760
9849
  getTokenFromCode(code) {
9761
- if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
9762
- return this.finishOp(142, 2);
9850
+ if (this.state.inType) {
9851
+ if (code === 62) {
9852
+ return this.finishOp(48, 1);
9853
+ }
9854
+ if (code === 60) {
9855
+ return this.finishOp(47, 1);
9856
+ }
9763
9857
  }
9764
9858
  return super.getTokenFromCode(code);
9765
9859
  }
9766
- parseExprAtom(refExpressionErrors) {
9767
- return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
9768
- }
9769
- parseIdentifier(liberal) {
9770
- return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
9860
+ reScan_lt_gt() {
9861
+ const {
9862
+ type
9863
+ } = this.state;
9864
+ if (type === 47) {
9865
+ this.state.pos -= 1;
9866
+ this.readToken_lt();
9867
+ } else if (type === 48) {
9868
+ this.state.pos -= 1;
9869
+ this.readToken_gt();
9870
+ }
9771
9871
  }
9772
- checkReservedWord(word, startLoc, checkKeywords, isBinding) {
9773
- if (word !== undefined) {
9774
- super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
9872
+ reScan_lt() {
9873
+ const {
9874
+ type
9875
+ } = this.state;
9876
+ if (type === 51) {
9877
+ this.state.pos -= 2;
9878
+ this.finishOp(47, 1);
9879
+ return 47;
9775
9880
  }
9881
+ return type;
9776
9882
  }
9777
- parseBindingAtom() {
9778
- return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
9883
+ toAssignableList(exprList, trailingCommaLoc, isLHS) {
9884
+ for (let i = 0; i < exprList.length; i++) {
9885
+ const expr = exprList[i];
9886
+ if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
9887
+ exprList[i] = this.typeCastToParameter(expr);
9888
+ }
9889
+ }
9890
+ super.toAssignableList(exprList, trailingCommaLoc, isLHS);
9779
9891
  }
9780
- isValidLVal(type, isParenthesized, binding) {
9781
- return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
9892
+ typeCastToParameter(node) {
9893
+ node.expression.typeAnnotation = node.typeAnnotation;
9894
+ this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
9895
+ return node.expression;
9782
9896
  }
9783
- toAssignable(node, isLHS) {
9784
- if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
9785
- node.expectedNode = "Pattern";
9786
- } else {
9787
- super.toAssignable(node, isLHS);
9897
+ shouldParseArrow(params) {
9898
+ if (this.match(14)) {
9899
+ return params.every(expr => this.isAssignable(expr, true));
9788
9900
  }
9901
+ return super.shouldParseArrow(params);
9789
9902
  }
9790
- chStartsBindingIdentifier(ch, pos) {
9791
- if (super.chStartsBindingIdentifier(ch, pos)) {
9792
- return true;
9793
- }
9794
- const nextToken = this.lookahead();
9795
- if (nextToken.type === 142) {
9796
- return true;
9797
- }
9798
- return false;
9903
+ shouldParseAsyncArrow() {
9904
+ return this.match(14) || super.shouldParseAsyncArrow();
9799
9905
  }
9800
- verifyBreakContinue(node, isBreak) {
9801
- if (node.label && node.label.type === "Placeholder") return;
9802
- super.verifyBreakContinue(node, isBreak);
9906
+ canHaveLeadingDecorator() {
9907
+ return super.canHaveLeadingDecorator() || this.isAbstractClass();
9803
9908
  }
9804
- parseExpressionStatement(node, expr) {
9805
- if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
9806
- return super.parseExpressionStatement(node, expr);
9807
- }
9808
- if (this.match(14)) {
9809
- const stmt = node;
9810
- stmt.label = this.finishPlaceholder(expr, "Identifier");
9811
- this.next();
9812
- stmt.body = super.parseStatementOrFunctionDeclaration(false);
9813
- return this.finishNode(stmt, "LabeledStatement");
9909
+ jsxParseOpeningElementAfterName(node) {
9910
+ if (this.match(47) || this.match(51)) {
9911
+ const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
9912
+ if (typeArguments) node.typeParameters = typeArguments;
9814
9913
  }
9815
- this.semicolon();
9816
- node.name = expr.name;
9817
- return this.finishPlaceholder(node, "Statement");
9914
+ return super.jsxParseOpeningElementAfterName(node);
9818
9915
  }
9819
- parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
9820
- return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
9916
+ getGetterSetterExpectedParamCount(method) {
9917
+ const baseCount = super.getGetterSetterExpectedParamCount(method);
9918
+ const params = this.getObjectOrClassMethodParams(method);
9919
+ const firstParam = params[0];
9920
+ const hasContextParam = firstParam && this.isThisParam(firstParam);
9921
+ return hasContextParam ? baseCount + 1 : baseCount;
9821
9922
  }
9822
- parseFunctionId(requireId) {
9823
- return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
9923
+ parseCatchClauseParam() {
9924
+ const param = super.parseCatchClauseParam();
9925
+ const type = this.tsTryParseTypeAnnotation();
9926
+ if (type) {
9927
+ param.typeAnnotation = type;
9928
+ this.resetEndLocation(param);
9929
+ }
9930
+ return param;
9931
+ }
9932
+ tsInAmbientContext(cb) {
9933
+ const oldIsAmbientContext = this.state.isAmbientContext;
9934
+ this.state.isAmbientContext = true;
9935
+ try {
9936
+ return cb();
9937
+ } finally {
9938
+ this.state.isAmbientContext = oldIsAmbientContext;
9939
+ }
9824
9940
  }
9825
9941
  parseClass(node, isStatement, optionalId) {
9826
- const type = isStatement ? "ClassDeclaration" : "ClassExpression";
9827
- this.next();
9828
- const oldStrict = this.state.strict;
9829
- const placeholder = this.parsePlaceholder("Identifier");
9830
- if (placeholder) {
9831
- if (this.match(81) || this.match(142) || this.match(5)) {
9832
- node.id = placeholder;
9833
- } else if (optionalId || !isStatement) {
9834
- node.id = null;
9835
- node.body = this.finishPlaceholder(placeholder, "ClassBody");
9836
- return this.finishNode(node, type);
9837
- } else {
9838
- throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
9839
- at: this.state.startLoc
9942
+ const oldInAbstractClass = this.state.inAbstractClass;
9943
+ this.state.inAbstractClass = !!node.abstract;
9944
+ try {
9945
+ return super.parseClass(node, isStatement, optionalId);
9946
+ } finally {
9947
+ this.state.inAbstractClass = oldInAbstractClass;
9948
+ }
9949
+ }
9950
+ tsParseAbstractDeclaration(node, decorators) {
9951
+ if (this.match(80)) {
9952
+ node.abstract = true;
9953
+ return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
9954
+ } else if (this.isContextual(127)) {
9955
+ if (!this.hasFollowingLineBreak()) {
9956
+ node.abstract = true;
9957
+ this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
9958
+ at: node
9840
9959
  });
9960
+ return this.tsParseInterfaceDeclaration(node);
9841
9961
  }
9842
9962
  } else {
9843
- this.parseClassId(node, isStatement, optionalId);
9844
- }
9845
- super.parseClassSuper(node);
9846
- node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
9847
- return this.finishNode(node, type);
9848
- }
9849
- parseExport(node, decorators) {
9850
- const placeholder = this.parsePlaceholder("Identifier");
9851
- if (!placeholder) return super.parseExport(node, decorators);
9852
- if (!this.isContextual(97) && !this.match(12)) {
9853
- node.specifiers = [];
9854
- node.source = null;
9855
- node.declaration = this.finishPlaceholder(placeholder, "Declaration");
9856
- return this.finishNode(node, "ExportNamedDeclaration");
9963
+ this.unexpected(null, 80);
9857
9964
  }
9858
- this.expectPlugin("exportDefaultFrom");
9859
- const specifier = this.startNode();
9860
- specifier.exported = placeholder;
9861
- node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
9862
- return super.parseExport(node, decorators);
9863
9965
  }
9864
- isExportDefaultSpecifier() {
9865
- if (this.match(65)) {
9866
- const next = this.nextTokenStart();
9867
- if (this.isUnparsedContextual(next, "from")) {
9868
- if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
9869
- return true;
9870
- }
9966
+ parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
9967
+ const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
9968
+ if (method.abstract) {
9969
+ const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
9970
+ if (hasBody) {
9971
+ const {
9972
+ key
9973
+ } = method;
9974
+ this.raise(TSErrors.AbstractMethodHasImplementation, {
9975
+ at: method,
9976
+ methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
9977
+ });
9871
9978
  }
9872
9979
  }
9873
- return super.isExportDefaultSpecifier();
9980
+ return method;
9874
9981
  }
9875
- maybeParseExportDefaultSpecifier(node) {
9876
- if (node.specifiers && node.specifiers.length > 0) {
9877
- return true;
9878
- }
9879
- return super.maybeParseExportDefaultSpecifier(node);
9982
+ tsParseTypeParameterName() {
9983
+ const typeName = this.parseIdentifier();
9984
+ return typeName.name;
9880
9985
  }
9881
- checkExport(node) {
9882
- const {
9883
- specifiers
9884
- } = node;
9885
- if (specifiers != null && specifiers.length) {
9886
- node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
9887
- }
9888
- super.checkExport(node);
9889
- node.specifiers = specifiers;
9986
+ shouldParseAsAmbientContext() {
9987
+ return !!this.getPluginOption("typescript", "dts");
9890
9988
  }
9891
- parseImport(node) {
9892
- const placeholder = this.parsePlaceholder("Identifier");
9893
- if (!placeholder) return super.parseImport(node);
9894
- node.specifiers = [];
9895
- if (!this.isContextual(97) && !this.match(12)) {
9896
- node.source = this.finishPlaceholder(placeholder, "StringLiteral");
9897
- this.semicolon();
9898
- return this.finishNode(node, "ImportDeclaration");
9899
- }
9900
- const specifier = this.startNodeAtNode(placeholder);
9901
- specifier.local = placeholder;
9902
- node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
9903
- if (this.eat(12)) {
9904
- const hasStarImport = this.maybeParseStarImportSpecifier(node);
9905
- if (!hasStarImport) this.parseNamedImportSpecifiers(node);
9989
+ parse() {
9990
+ if (this.shouldParseAsAmbientContext()) {
9991
+ this.state.isAmbientContext = true;
9906
9992
  }
9907
- this.expectContextual(97);
9908
- node.source = this.parseImportSource();
9909
- this.semicolon();
9910
- return this.finishNode(node, "ImportDeclaration");
9911
- }
9912
- parseImportSource() {
9913
- return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
9993
+ return super.parse();
9914
9994
  }
9915
- assertNoSpace() {
9916
- if (this.state.start > this.state.lastTokEndLoc.index) {
9917
- this.raise(PlaceholderErrors.UnexpectedSpace, {
9918
- at: this.state.lastTokEndLoc
9919
- });
9995
+ getExpression() {
9996
+ if (this.shouldParseAsAmbientContext()) {
9997
+ this.state.isAmbientContext = true;
9920
9998
  }
9999
+ return super.getExpression();
9921
10000
  }
9922
- });
9923
-
9924
- var v8intrinsic = (superClass => class V8IntrinsicMixin extends superClass {
9925
- parseV8Intrinsic() {
9926
- if (this.match(54)) {
9927
- const v8IntrinsicStartLoc = this.state.startLoc;
9928
- const node = this.startNode();
9929
- this.next();
9930
- if (tokenIsIdentifier(this.state.type)) {
9931
- const name = this.parseIdentifierName();
9932
- const identifier = this.createIdentifier(node, name);
9933
- identifier.type = "V8IntrinsicIdentifier";
9934
- if (this.match(10)) {
9935
- return identifier;
9936
- }
9937
- }
9938
- this.unexpected(v8IntrinsicStartLoc);
10001
+ parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
10002
+ if (!isString && isMaybeTypeOnly) {
10003
+ this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
10004
+ return this.finishNode(node, "ExportSpecifier");
9939
10005
  }
10006
+ node.exportKind = "value";
10007
+ return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
9940
10008
  }
9941
- parseExprAtom(refExpressionErrors) {
9942
- return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
10009
+ parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
10010
+ if (!importedIsString && isMaybeTypeOnly) {
10011
+ this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
10012
+ return this.finishNode(specifier, "ImportSpecifier");
10013
+ }
10014
+ specifier.importKind = "value";
10015
+ return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
9943
10016
  }
9944
- });
9945
-
9946
- function hasPlugin(plugins, expectedConfig) {
9947
- const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
9948
- const expectedKeys = Object.keys(expectedOptions);
9949
- const expectedOptionsIsEmpty = expectedKeys.length === 0;
9950
- return plugins.some(p => {
9951
- if (typeof p === "string") {
9952
- return expectedOptionsIsEmpty && p === expectedName;
9953
- } else {
9954
- const [pluginName, pluginOptions] = p;
9955
- if (pluginName !== expectedName) {
9956
- return false;
10017
+ parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
10018
+ const leftOfAsKey = isImport ? "imported" : "local";
10019
+ const rightOfAsKey = isImport ? "local" : "exported";
10020
+ let leftOfAs = node[leftOfAsKey];
10021
+ let rightOfAs;
10022
+ let hasTypeSpecifier = false;
10023
+ let canParseAsKeyword = true;
10024
+ const loc = leftOfAs.loc.start;
10025
+ if (this.isContextual(93)) {
10026
+ const firstAs = this.parseIdentifier();
10027
+ if (this.isContextual(93)) {
10028
+ const secondAs = this.parseIdentifier();
10029
+ if (tokenIsKeywordOrIdentifier(this.state.type)) {
10030
+ hasTypeSpecifier = true;
10031
+ leftOfAs = firstAs;
10032
+ rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10033
+ canParseAsKeyword = false;
10034
+ } else {
10035
+ rightOfAs = secondAs;
10036
+ canParseAsKeyword = false;
10037
+ }
10038
+ } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
10039
+ canParseAsKeyword = false;
10040
+ rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
10041
+ } else {
10042
+ hasTypeSpecifier = true;
10043
+ leftOfAs = firstAs;
9957
10044
  }
9958
- for (const key of expectedKeys) {
9959
- if (pluginOptions[key] !== expectedOptions[key]) {
9960
- return false;
10045
+ } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
10046
+ hasTypeSpecifier = true;
10047
+ if (isImport) {
10048
+ leftOfAs = this.parseIdentifier(true);
10049
+ if (!this.isContextual(93)) {
10050
+ this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
9961
10051
  }
10052
+ } else {
10053
+ leftOfAs = this.parseModuleExportName();
9962
10054
  }
9963
- return true;
9964
10055
  }
9965
- });
9966
- }
9967
- function getPluginOption(plugins, name, option) {
9968
- const plugin = plugins.find(plugin => {
9969
- if (Array.isArray(plugin)) {
9970
- return plugin[0] === name;
9971
- } else {
9972
- return plugin === name;
10056
+ if (hasTypeSpecifier && isInTypeOnlyImportExport) {
10057
+ this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
10058
+ at: loc
10059
+ });
9973
10060
  }
9974
- });
9975
- if (plugin && Array.isArray(plugin) && plugin.length > 1) {
9976
- return plugin[1][option];
9977
- }
9978
- return null;
9979
- }
9980
- const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
9981
- const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
9982
- const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
9983
- function validatePlugins(plugins) {
9984
- if (hasPlugin(plugins, "decorators")) {
9985
- if (hasPlugin(plugins, "decorators-legacy")) {
9986
- throw new Error("Cannot use the decorators and decorators-legacy plugin together");
10061
+ node[leftOfAsKey] = leftOfAs;
10062
+ node[rightOfAsKey] = rightOfAs;
10063
+ const kindKey = isImport ? "importKind" : "exportKind";
10064
+ node[kindKey] = hasTypeSpecifier ? "type" : "value";
10065
+ if (canParseAsKeyword && this.eatContextual(93)) {
10066
+ node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
9987
10067
  }
9988
- const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
9989
- if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
9990
- throw new Error("'decoratorsBeforeExport' must be a boolean.");
10068
+ if (!node[rightOfAsKey]) {
10069
+ node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
9991
10070
  }
9992
- const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
9993
- if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
9994
- throw new Error("'allowCallParenthesized' must be a boolean.");
10071
+ if (isImport) {
10072
+ this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? BIND_TS_TYPE_IMPORT : BIND_FLAGS_TS_IMPORT);
9995
10073
  }
9996
10074
  }
9997
- if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
9998
- throw new Error("Cannot combine flow and typescript plugins.");
10075
+ });
10076
+ function isPossiblyLiteralEnum(expression) {
10077
+ if (expression.type !== "MemberExpression") return false;
10078
+ const {
10079
+ computed,
10080
+ property
10081
+ } = expression;
10082
+ if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
10083
+ return false;
9999
10084
  }
10000
- if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
10001
- throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
10085
+ return isUncomputedMemberExpressionChain(expression.object);
10086
+ }
10087
+ function isValidAmbientConstInitializer(expression, estree) {
10088
+ var _expression$extra;
10089
+ const {
10090
+ type
10091
+ } = expression;
10092
+ if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
10093
+ return false;
10002
10094
  }
10003
- if (hasPlugin(plugins, "pipelineOperator")) {
10004
- const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
10005
- if (!PIPELINE_PROPOSALS.includes(proposal)) {
10006
- const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
10007
- throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
10008
- }
10009
- const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
10010
- syntaxType: "hash"
10011
- }]);
10012
- if (proposal === "hack") {
10013
- if (hasPlugin(plugins, "placeholders")) {
10014
- throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
10015
- }
10016
- if (hasPlugin(plugins, "v8intrinsic")) {
10017
- throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
10018
- }
10019
- const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
10020
- if (!TOPIC_TOKENS.includes(topicToken)) {
10021
- const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
10022
- throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
10023
- }
10024
- if (topicToken === "#" && tupleSyntaxIsHash) {
10025
- throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
10095
+ if (estree) {
10096
+ if (type === "Literal") {
10097
+ const {
10098
+ value
10099
+ } = expression;
10100
+ if (typeof value === "string" || typeof value === "boolean") {
10101
+ return true;
10026
10102
  }
10027
- } else if (proposal === "smart" && tupleSyntaxIsHash) {
10028
- throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
10029
10103
  }
10030
- }
10031
- if (hasPlugin(plugins, "moduleAttributes")) {
10032
- {
10033
- if (hasPlugin(plugins, "importAssertions")) {
10034
- throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
10035
- }
10036
- const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
10037
- if (moduleAttributesVersionPluginOption !== "may-2020") {
10038
- throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
10039
- }
10104
+ } else {
10105
+ if (type === "StringLiteral" || type === "BooleanLiteral") {
10106
+ return true;
10040
10107
  }
10041
10108
  }
10042
- if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
10043
- throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
10109
+ if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
10110
+ return true;
10111
+ }
10112
+ if (type === "TemplateLiteral" && expression.expressions.length === 0) {
10113
+ return true;
10044
10114
  }
10045
- if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
10046
- const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
10047
- error.missingPlugins = "doExpressions";
10048
- throw error;
10115
+ if (isPossiblyLiteralEnum(expression)) {
10116
+ return true;
10049
10117
  }
10118
+ return false;
10050
10119
  }
10051
- const mixinPlugins = {
10052
- estree,
10053
- jsx,
10054
- flow,
10055
- typescript,
10056
- v8intrinsic,
10057
- placeholders
10058
- };
10059
- const mixinPluginNames = Object.keys(mixinPlugins);
10060
-
10061
- const defaultOptions = {
10062
- sourceType: "script",
10063
- sourceFilename: undefined,
10064
- startColumn: 0,
10065
- startLine: 1,
10066
- allowAwaitOutsideFunction: false,
10067
- allowReturnOutsideFunction: false,
10068
- allowImportExportEverywhere: false,
10069
- allowSuperOutsideMethod: false,
10070
- allowUndeclaredExports: false,
10071
- plugins: [],
10072
- strictMode: null,
10073
- ranges: false,
10074
- tokens: false,
10075
- createParenthesizedExpressions: false,
10076
- errorRecovery: false,
10077
- attachComment: true
10078
- };
10079
- function getOptions(opts) {
10080
- const options = {};
10081
- for (const key of Object.keys(defaultOptions)) {
10082
- options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
10120
+ function isNumber(expression, estree) {
10121
+ if (estree) {
10122
+ return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
10123
+ } else {
10124
+ return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
10083
10125
  }
10084
- return options;
10085
10126
  }
10086
-
10087
- const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
10088
- const unwrapParenthesizedExpression = node => {
10089
- return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
10090
- };
10091
- class LValParser extends NodeUtils {
10092
- toAssignable(node, isLHS = false) {
10093
- var _node$extra, _node$extra3;
10094
- let parenthesized = undefined;
10095
- if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
10096
- parenthesized = unwrapParenthesizedExpression(node);
10097
- if (isLHS) {
10098
- if (parenthesized.type === "Identifier") {
10099
- this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
10100
- at: node
10101
- });
10102
- } else if (parenthesized.type !== "MemberExpression") {
10103
- this.raise(Errors.InvalidParenthesizedAssignment, {
10104
- at: node
10105
- });
10106
- }
10107
- } else {
10108
- this.raise(Errors.InvalidParenthesizedAssignment, {
10109
- at: node
10110
- });
10111
- }
10127
+ function isNegativeNumber(expression, estree) {
10128
+ if (expression.type === "UnaryExpression") {
10129
+ const {
10130
+ operator,
10131
+ argument
10132
+ } = expression;
10133
+ if (operator === "-" && isNumber(argument, estree)) {
10134
+ return true;
10112
10135
  }
10113
- switch (node.type) {
10114
- case "Identifier":
10115
- case "ObjectPattern":
10116
- case "ArrayPattern":
10117
- case "AssignmentPattern":
10118
- case "RestElement":
10119
- break;
10120
- case "ObjectExpression":
10121
- node.type = "ObjectPattern";
10122
- for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
10123
- var _node$extra2;
10124
- const prop = node.properties[i];
10125
- const isLast = i === last;
10126
- this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
10127
- if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
10128
- this.raise(Errors.RestTrailingComma, {
10129
- at: node.extra.trailingCommaLoc
10130
- });
10131
- }
10132
- }
10133
- break;
10134
- case "ObjectProperty":
10135
- {
10136
- const {
10137
- key,
10138
- value
10139
- } = node;
10140
- if (this.isPrivateName(key)) {
10141
- this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
10142
- }
10143
- this.toAssignable(value, isLHS);
10144
- break;
10145
- }
10146
- case "SpreadElement":
10147
- {
10148
- throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
10149
- }
10150
- case "ArrayExpression":
10151
- node.type = "ArrayPattern";
10152
- this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
10153
- break;
10154
- case "AssignmentExpression":
10155
- if (node.operator !== "=") {
10156
- this.raise(Errors.MissingEqInAssignment, {
10157
- at: node.left.loc.end
10158
- });
10159
- }
10160
- node.type = "AssignmentPattern";
10161
- delete node.operator;
10162
- this.toAssignable(node.left, isLHS);
10163
- break;
10164
- case "ParenthesizedExpression":
10165
- this.toAssignable(parenthesized, isLHS);
10166
- break;
10136
+ }
10137
+ return false;
10138
+ }
10139
+ function isUncomputedMemberExpressionChain(expression) {
10140
+ if (expression.type === "Identifier") return true;
10141
+ if (expression.type !== "MemberExpression") return false;
10142
+ if (expression.computed) return false;
10143
+ return isUncomputedMemberExpressionChain(expression.object);
10144
+ }
10145
+
10146
+ const PlaceholderErrors = ParseErrorEnum`placeholders`({
10147
+ ClassNameIsRequired: "A class name is required.",
10148
+ UnexpectedSpace: "Unexpected space in placeholder."
10149
+ });
10150
+ var placeholders = (superClass => class PlaceholdersParserMixin extends superClass {
10151
+ parsePlaceholder(expectedNode) {
10152
+ if (this.match(142)) {
10153
+ const node = this.startNode();
10154
+ this.next();
10155
+ this.assertNoSpace();
10156
+ node.name = super.parseIdentifier(true);
10157
+ this.assertNoSpace();
10158
+ this.expect(142);
10159
+ return this.finishPlaceholder(node, expectedNode);
10167
10160
  }
10168
10161
  }
10169
- toAssignableObjectExpressionProp(prop, isLast, isLHS) {
10170
- if (prop.type === "ObjectMethod") {
10171
- this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
10172
- at: prop.key
10173
- });
10174
- } else if (prop.type === "SpreadElement") {
10175
- prop.type = "RestElement";
10176
- const arg = prop.argument;
10177
- this.checkToRestConversion(arg, false);
10178
- this.toAssignable(arg, isLHS);
10179
- if (!isLast) {
10180
- this.raise(Errors.RestTrailingComma, {
10181
- at: prop
10182
- });
10183
- }
10184
- } else {
10185
- this.toAssignable(prop, isLHS);
10162
+ finishPlaceholder(node, expectedNode) {
10163
+ const isFinished = !!(node.expectedNode && node.type === "Placeholder");
10164
+ node.expectedNode = expectedNode;
10165
+ return isFinished ? node : this.finishNode(node, "Placeholder");
10166
+ }
10167
+ getTokenFromCode(code) {
10168
+ if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
10169
+ return this.finishOp(142, 2);
10186
10170
  }
10171
+ return super.getTokenFromCode(code);
10187
10172
  }
10188
- toAssignableList(exprList, trailingCommaLoc, isLHS) {
10189
- const end = exprList.length - 1;
10190
- for (let i = 0; i <= end; i++) {
10191
- const elt = exprList[i];
10192
- if (!elt) continue;
10193
- if (elt.type === "SpreadElement") {
10194
- elt.type = "RestElement";
10195
- const arg = elt.argument;
10196
- this.checkToRestConversion(arg, true);
10197
- this.toAssignable(arg, isLHS);
10198
- } else {
10199
- this.toAssignable(elt, isLHS);
10200
- }
10201
- if (elt.type === "RestElement") {
10202
- if (i < end) {
10203
- this.raise(Errors.RestTrailingComma, {
10204
- at: elt
10205
- });
10206
- } else if (trailingCommaLoc) {
10207
- this.raise(Errors.RestTrailingComma, {
10208
- at: trailingCommaLoc
10209
- });
10210
- }
10211
- }
10173
+ parseExprAtom(refExpressionErrors) {
10174
+ return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
10175
+ }
10176
+ parseIdentifier(liberal) {
10177
+ return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
10178
+ }
10179
+ checkReservedWord(word, startLoc, checkKeywords, isBinding) {
10180
+ if (word !== undefined) {
10181
+ super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
10212
10182
  }
10213
10183
  }
10214
- isAssignable(node, isBinding) {
10215
- switch (node.type) {
10216
- case "Identifier":
10217
- case "ObjectPattern":
10218
- case "ArrayPattern":
10219
- case "AssignmentPattern":
10220
- case "RestElement":
10221
- return true;
10222
- case "ObjectExpression":
10223
- {
10224
- const last = node.properties.length - 1;
10225
- return node.properties.every((prop, i) => {
10226
- return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
10227
- });
10228
- }
10229
- case "ObjectProperty":
10230
- return this.isAssignable(node.value);
10231
- case "SpreadElement":
10232
- return this.isAssignable(node.argument);
10233
- case "ArrayExpression":
10234
- return node.elements.every(element => element === null || this.isAssignable(element));
10235
- case "AssignmentExpression":
10236
- return node.operator === "=";
10237
- case "ParenthesizedExpression":
10238
- return this.isAssignable(node.expression);
10239
- case "MemberExpression":
10240
- case "OptionalMemberExpression":
10241
- return !isBinding;
10242
- default:
10243
- return false;
10184
+ parseBindingAtom() {
10185
+ return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
10186
+ }
10187
+ isValidLVal(type, isParenthesized, binding) {
10188
+ return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
10189
+ }
10190
+ toAssignable(node, isLHS) {
10191
+ if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
10192
+ node.expectedNode = "Pattern";
10193
+ } else {
10194
+ super.toAssignable(node, isLHS);
10244
10195
  }
10245
10196
  }
10246
- toReferencedList(exprList, isParenthesizedExpr) {
10247
- return exprList;
10197
+ chStartsBindingIdentifier(ch, pos) {
10198
+ if (super.chStartsBindingIdentifier(ch, pos)) {
10199
+ return true;
10200
+ }
10201
+ const nextToken = this.lookahead();
10202
+ if (nextToken.type === 142) {
10203
+ return true;
10204
+ }
10205
+ return false;
10248
10206
  }
10249
- toReferencedListDeep(exprList, isParenthesizedExpr) {
10250
- this.toReferencedList(exprList, isParenthesizedExpr);
10251
- for (const expr of exprList) {
10252
- if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
10253
- this.toReferencedListDeep(expr.elements);
10254
- }
10207
+ verifyBreakContinue(node, isBreak) {
10208
+ if (node.label && node.label.type === "Placeholder") return;
10209
+ super.verifyBreakContinue(node, isBreak);
10210
+ }
10211
+ parseExpressionStatement(node, expr) {
10212
+ if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) {
10213
+ return super.parseExpressionStatement(node, expr);
10214
+ }
10215
+ if (this.match(14)) {
10216
+ const stmt = node;
10217
+ stmt.label = this.finishPlaceholder(expr, "Identifier");
10218
+ this.next();
10219
+ stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
10220
+ return this.finishNode(stmt, "LabeledStatement");
10255
10221
  }
10222
+ this.semicolon();
10223
+ node.name = expr.name;
10224
+ return this.finishPlaceholder(node, "Statement");
10256
10225
  }
10257
- parseSpread(refExpressionErrors) {
10258
- const node = this.startNode();
10259
- this.next();
10260
- node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
10261
- return this.finishNode(node, "SpreadElement");
10226
+ parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
10227
+ return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
10262
10228
  }
10263
- parseRestBinding() {
10264
- const node = this.startNode();
10229
+ parseFunctionId(requireId) {
10230
+ return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
10231
+ }
10232
+ parseClass(node, isStatement, optionalId) {
10233
+ const type = isStatement ? "ClassDeclaration" : "ClassExpression";
10265
10234
  this.next();
10266
- node.argument = this.parseBindingAtom();
10267
- return this.finishNode(node, "RestElement");
10235
+ const oldStrict = this.state.strict;
10236
+ const placeholder = this.parsePlaceholder("Identifier");
10237
+ if (placeholder) {
10238
+ if (this.match(81) || this.match(142) || this.match(5)) {
10239
+ node.id = placeholder;
10240
+ } else if (optionalId || !isStatement) {
10241
+ node.id = null;
10242
+ node.body = this.finishPlaceholder(placeholder, "ClassBody");
10243
+ return this.finishNode(node, type);
10244
+ } else {
10245
+ throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
10246
+ at: this.state.startLoc
10247
+ });
10248
+ }
10249
+ } else {
10250
+ this.parseClassId(node, isStatement, optionalId);
10251
+ }
10252
+ super.parseClassSuper(node);
10253
+ node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
10254
+ return this.finishNode(node, type);
10268
10255
  }
10269
- parseBindingAtom() {
10270
- switch (this.state.type) {
10271
- case 0:
10272
- {
10273
- const node = this.startNode();
10274
- this.next();
10275
- node.elements = this.parseBindingList(3, 93, true);
10276
- return this.finishNode(node, "ArrayPattern");
10277
- }
10278
- case 5:
10279
- return this.parseObjectLike(8, true);
10256
+ parseExport(node, decorators) {
10257
+ const placeholder = this.parsePlaceholder("Identifier");
10258
+ if (!placeholder) return super.parseExport(node, decorators);
10259
+ if (!this.isContextual(97) && !this.match(12)) {
10260
+ node.specifiers = [];
10261
+ node.source = null;
10262
+ node.declaration = this.finishPlaceholder(placeholder, "Declaration");
10263
+ return this.finishNode(node, "ExportNamedDeclaration");
10280
10264
  }
10281
- return this.parseIdentifier();
10265
+ this.expectPlugin("exportDefaultFrom");
10266
+ const specifier = this.startNode();
10267
+ specifier.exported = placeholder;
10268
+ node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
10269
+ return super.parseExport(node, decorators);
10282
10270
  }
10283
- parseBindingList(close, closeCharCode, allowEmpty, allowModifiers) {
10284
- const elts = [];
10285
- let first = true;
10286
- while (!this.eat(close)) {
10287
- if (first) {
10288
- first = false;
10289
- } else {
10290
- this.expect(12);
10291
- }
10292
- if (allowEmpty && this.match(12)) {
10293
- elts.push(null);
10294
- } else if (this.eat(close)) {
10295
- break;
10296
- } else if (this.match(21)) {
10297
- elts.push(this.parseAssignableListItemTypes(this.parseRestBinding()));
10298
- if (!this.checkCommaAfterRest(closeCharCode)) {
10299
- this.expect(close);
10300
- break;
10301
- }
10302
- } else {
10303
- const decorators = [];
10304
- if (this.match(26) && this.hasPlugin("decorators")) {
10305
- this.raise(Errors.UnsupportedParameterDecorator, {
10306
- at: this.state.startLoc
10307
- });
10308
- }
10309
- while (this.match(26)) {
10310
- decorators.push(this.parseDecorator());
10271
+ isExportDefaultSpecifier() {
10272
+ if (this.match(65)) {
10273
+ const next = this.nextTokenStart();
10274
+ if (this.isUnparsedContextual(next, "from")) {
10275
+ if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
10276
+ return true;
10311
10277
  }
10312
- elts.push(this.parseAssignableListItem(allowModifiers, decorators));
10313
10278
  }
10314
10279
  }
10315
- return elts;
10280
+ return super.isExportDefaultSpecifier();
10316
10281
  }
10317
- parseBindingRestProperty(prop) {
10318
- this.next();
10319
- prop.argument = this.parseIdentifier();
10320
- this.checkCommaAfterRest(125);
10321
- return this.finishNode(prop, "RestElement");
10282
+ maybeParseExportDefaultSpecifier(node) {
10283
+ if (node.specifiers && node.specifiers.length > 0) {
10284
+ return true;
10285
+ }
10286
+ return super.maybeParseExportDefaultSpecifier(node);
10322
10287
  }
10323
- parseBindingProperty() {
10324
- const prop = this.startNode();
10288
+ checkExport(node) {
10325
10289
  const {
10326
- type,
10327
- startLoc
10328
- } = this.state;
10329
- if (type === 21) {
10330
- return this.parseBindingRestProperty(prop);
10331
- } else if (type === 136) {
10332
- this.expectPlugin("destructuringPrivate", startLoc);
10333
- this.classScope.usePrivateName(this.state.value, startLoc);
10334
- prop.key = this.parsePrivateName();
10335
- } else {
10336
- this.parsePropertyName(prop);
10290
+ specifiers
10291
+ } = node;
10292
+ if (specifiers != null && specifiers.length) {
10293
+ node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
10337
10294
  }
10338
- prop.method = false;
10339
- return this.parseObjPropValue(prop, startLoc, false, false, true, false);
10295
+ super.checkExport(node);
10296
+ node.specifiers = specifiers;
10340
10297
  }
10341
- parseAssignableListItem(allowModifiers, decorators) {
10342
- const left = this.parseMaybeDefault();
10343
- this.parseAssignableListItemTypes(left);
10344
- const elt = this.parseMaybeDefault(left.loc.start, left);
10345
- if (decorators.length) {
10346
- left.decorators = decorators;
10298
+ parseImport(node) {
10299
+ const placeholder = this.parsePlaceholder("Identifier");
10300
+ if (!placeholder) return super.parseImport(node);
10301
+ node.specifiers = [];
10302
+ if (!this.isContextual(97) && !this.match(12)) {
10303
+ node.source = this.finishPlaceholder(placeholder, "StringLiteral");
10304
+ this.semicolon();
10305
+ return this.finishNode(node, "ImportDeclaration");
10347
10306
  }
10348
- return elt;
10349
- }
10350
- parseAssignableListItemTypes(param) {
10351
- return param;
10352
- }
10353
- parseMaybeDefault(startLoc, left) {
10354
- var _startLoc, _left;
10355
- (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
10356
- left = (_left = left) != null ? _left : this.parseBindingAtom();
10357
- if (!this.eat(29)) return left;
10358
- const node = this.startNodeAt(startLoc);
10359
- node.left = left;
10360
- node.right = this.parseMaybeAssignAllowIn();
10361
- return this.finishNode(node, "AssignmentPattern");
10307
+ const specifier = this.startNodeAtNode(placeholder);
10308
+ specifier.local = placeholder;
10309
+ node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
10310
+ if (this.eat(12)) {
10311
+ const hasStarImport = this.maybeParseStarImportSpecifier(node);
10312
+ if (!hasStarImport) this.parseNamedImportSpecifiers(node);
10313
+ }
10314
+ this.expectContextual(97);
10315
+ node.source = this.parseImportSource();
10316
+ this.semicolon();
10317
+ return this.finishNode(node, "ImportDeclaration");
10362
10318
  }
10363
- isValidLVal(type, isUnparenthesizedInAssign, binding) {
10364
- return getOwn({
10365
- AssignmentPattern: "left",
10366
- RestElement: "argument",
10367
- ObjectProperty: "value",
10368
- ParenthesizedExpression: "expression",
10369
- ArrayPattern: "elements",
10370
- ObjectPattern: "properties"
10371
- }, type);
10319
+ parseImportSource() {
10320
+ return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
10372
10321
  }
10373
- checkLVal(expression, {
10374
- in: ancestor,
10375
- binding = BIND_NONE,
10376
- checkClashes = false,
10377
- strictModeChanged = false,
10378
- hasParenthesizedAncestor = false
10379
- }) {
10380
- var _expression$extra;
10381
- const type = expression.type;
10382
- if (this.isObjectMethod(expression)) return;
10383
- if (type === "MemberExpression") {
10384
- if (binding !== BIND_NONE) {
10385
- this.raise(Errors.InvalidPropertyBindingPattern, {
10386
- at: expression
10387
- });
10388
- }
10389
- return;
10322
+ assertNoSpace() {
10323
+ if (this.state.start > this.state.lastTokEndLoc.index) {
10324
+ this.raise(PlaceholderErrors.UnexpectedSpace, {
10325
+ at: this.state.lastTokEndLoc
10326
+ });
10390
10327
  }
10391
- if (type === "Identifier") {
10392
- this.checkIdentifier(expression, binding, strictModeChanged);
10393
- const {
10394
- name
10395
- } = expression;
10396
- if (checkClashes) {
10397
- if (checkClashes.has(name)) {
10398
- this.raise(Errors.ParamDupe, {
10399
- at: expression
10400
- });
10401
- } else {
10402
- checkClashes.add(name);
10328
+ }
10329
+ });
10330
+
10331
+ var v8intrinsic = (superClass => class V8IntrinsicMixin extends superClass {
10332
+ parseV8Intrinsic() {
10333
+ if (this.match(54)) {
10334
+ const v8IntrinsicStartLoc = this.state.startLoc;
10335
+ const node = this.startNode();
10336
+ this.next();
10337
+ if (tokenIsIdentifier(this.state.type)) {
10338
+ const name = this.parseIdentifierName();
10339
+ const identifier = this.createIdentifier(node, name);
10340
+ identifier.type = "V8IntrinsicIdentifier";
10341
+ if (this.match(10)) {
10342
+ return identifier;
10403
10343
  }
10404
10344
  }
10405
- return;
10406
- }
10407
- const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
10408
- if (validity === true) return;
10409
- if (validity === false) {
10410
- const ParseErrorClass = binding === BIND_NONE ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
10411
- this.raise(ParseErrorClass, {
10412
- at: expression,
10413
- ancestor
10414
- });
10415
- return;
10345
+ this.unexpected(v8IntrinsicStartLoc);
10416
10346
  }
10417
- const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
10418
- const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? {
10419
- type
10420
- } : ancestor;
10421
- for (const child of [].concat(expression[key])) {
10422
- if (child) {
10423
- this.checkLVal(child, {
10424
- in: nextAncestor,
10425
- binding,
10426
- checkClashes,
10427
- strictModeChanged,
10428
- hasParenthesizedAncestor: isParenthesizedExpression
10429
- });
10347
+ }
10348
+ parseExprAtom(refExpressionErrors) {
10349
+ return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
10350
+ }
10351
+ });
10352
+
10353
+ function hasPlugin(plugins, expectedConfig) {
10354
+ const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
10355
+ const expectedKeys = Object.keys(expectedOptions);
10356
+ const expectedOptionsIsEmpty = expectedKeys.length === 0;
10357
+ return plugins.some(p => {
10358
+ if (typeof p === "string") {
10359
+ return expectedOptionsIsEmpty && p === expectedName;
10360
+ } else {
10361
+ const [pluginName, pluginOptions] = p;
10362
+ if (pluginName !== expectedName) {
10363
+ return false;
10364
+ }
10365
+ for (const key of expectedKeys) {
10366
+ if (pluginOptions[key] !== expectedOptions[key]) {
10367
+ return false;
10368
+ }
10430
10369
  }
10370
+ return true;
10371
+ }
10372
+ });
10373
+ }
10374
+ function getPluginOption(plugins, name, option) {
10375
+ const plugin = plugins.find(plugin => {
10376
+ if (Array.isArray(plugin)) {
10377
+ return plugin[0] === name;
10378
+ } else {
10379
+ return plugin === name;
10431
10380
  }
10381
+ });
10382
+ if (plugin && Array.isArray(plugin) && plugin.length > 1) {
10383
+ return plugin[1][option];
10432
10384
  }
10433
- checkIdentifier(at, bindingType, strictModeChanged = false) {
10434
- if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
10435
- if (bindingType === BIND_NONE) {
10436
- this.raise(Errors.StrictEvalArguments, {
10437
- at,
10438
- referenceName: at.name
10439
- });
10440
- } else {
10441
- this.raise(Errors.StrictEvalArgumentsBinding, {
10442
- at,
10443
- bindingName: at.name
10444
- });
10445
- }
10385
+ return null;
10386
+ }
10387
+ const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
10388
+ const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
10389
+ const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
10390
+ function validatePlugins(plugins) {
10391
+ if (hasPlugin(plugins, "decorators")) {
10392
+ if (hasPlugin(plugins, "decorators-legacy")) {
10393
+ throw new Error("Cannot use the decorators and decorators-legacy plugin together");
10446
10394
  }
10447
- if (bindingType & BIND_FLAGS_NO_LET_IN_LEXICAL && at.name === "let") {
10448
- this.raise(Errors.LetInLexicalBinding, {
10449
- at
10450
- });
10395
+ const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
10396
+ if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
10397
+ throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
10451
10398
  }
10452
- if (!(bindingType & BIND_NONE)) {
10453
- this.declareNameFromIdentifier(at, bindingType);
10399
+ const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
10400
+ if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
10401
+ throw new Error("'allowCallParenthesized' must be a boolean.");
10454
10402
  }
10455
10403
  }
10456
- declareNameFromIdentifier(identifier, binding) {
10457
- this.scope.declareName(identifier.name, binding, identifier.loc.start);
10404
+ if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
10405
+ throw new Error("Cannot combine flow and typescript plugins.");
10458
10406
  }
10459
- checkToRestConversion(node, allowPattern) {
10460
- switch (node.type) {
10461
- case "ParenthesizedExpression":
10462
- this.checkToRestConversion(node.expression, allowPattern);
10463
- break;
10464
- case "Identifier":
10465
- case "MemberExpression":
10466
- break;
10467
- case "ArrayExpression":
10468
- case "ObjectExpression":
10469
- if (allowPattern) break;
10470
- default:
10471
- this.raise(Errors.InvalidRestAssignmentPattern, {
10472
- at: node
10473
- });
10407
+ if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
10408
+ throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
10409
+ }
10410
+ if (hasPlugin(plugins, "pipelineOperator")) {
10411
+ const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
10412
+ if (!PIPELINE_PROPOSALS.includes(proposal)) {
10413
+ const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
10414
+ throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
10415
+ }
10416
+ const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
10417
+ syntaxType: "hash"
10418
+ }]);
10419
+ if (proposal === "hack") {
10420
+ if (hasPlugin(plugins, "placeholders")) {
10421
+ throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
10422
+ }
10423
+ if (hasPlugin(plugins, "v8intrinsic")) {
10424
+ throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
10425
+ }
10426
+ const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
10427
+ if (!TOPIC_TOKENS.includes(topicToken)) {
10428
+ const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
10429
+ throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
10430
+ }
10431
+ if (topicToken === "#" && tupleSyntaxIsHash) {
10432
+ throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
10433
+ }
10434
+ } else if (proposal === "smart" && tupleSyntaxIsHash) {
10435
+ throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
10474
10436
  }
10475
10437
  }
10476
- checkCommaAfterRest(close) {
10477
- if (!this.match(12)) {
10478
- return false;
10438
+ if (hasPlugin(plugins, "moduleAttributes")) {
10439
+ {
10440
+ if (hasPlugin(plugins, "importAssertions")) {
10441
+ throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
10442
+ }
10443
+ const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
10444
+ if (moduleAttributesVersionPluginOption !== "may-2020") {
10445
+ throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
10446
+ }
10479
10447
  }
10480
- this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
10481
- at: this.state.startLoc
10482
- });
10483
- return true;
10484
10448
  }
10449
+ if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
10450
+ throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
10451
+ }
10452
+ if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
10453
+ const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
10454
+ error.missingPlugins = "doExpressions";
10455
+ throw error;
10456
+ }
10457
+ }
10458
+ const mixinPlugins = {
10459
+ estree,
10460
+ jsx,
10461
+ flow,
10462
+ typescript,
10463
+ v8intrinsic,
10464
+ placeholders
10465
+ };
10466
+ const mixinPluginNames = Object.keys(mixinPlugins);
10467
+
10468
+ const defaultOptions = {
10469
+ sourceType: "script",
10470
+ sourceFilename: undefined,
10471
+ startColumn: 0,
10472
+ startLine: 1,
10473
+ allowAwaitOutsideFunction: false,
10474
+ allowReturnOutsideFunction: false,
10475
+ allowNewTargetOutsideFunction: false,
10476
+ allowImportExportEverywhere: false,
10477
+ allowSuperOutsideMethod: false,
10478
+ allowUndeclaredExports: false,
10479
+ plugins: [],
10480
+ strictMode: null,
10481
+ ranges: false,
10482
+ tokens: false,
10483
+ createParenthesizedExpressions: false,
10484
+ errorRecovery: false,
10485
+ attachComment: true,
10486
+ annexB: true
10487
+ };
10488
+ function getOptions(opts) {
10489
+ if (opts && opts.annexB != null && opts.annexB !== false) {
10490
+ throw new Error("The `annexB` option can only be set to `false`.");
10491
+ }
10492
+ const options = {};
10493
+ for (const key of Object.keys(defaultOptions)) {
10494
+ options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key];
10495
+ }
10496
+ return options;
10485
10497
  }
10486
10498
 
10487
10499
  class ExpressionParser extends LValParser {
@@ -10873,9 +10885,14 @@ class ExpressionParser extends LValParser {
10873
10885
  }
10874
10886
  let optional = false;
10875
10887
  if (type === 18) {
10876
- if (noCalls && this.lookaheadCharCode() === 40) {
10877
- state.stop = true;
10878
- return base;
10888
+ if (noCalls) {
10889
+ this.raise(Errors.OptionalChainingNoNew, {
10890
+ at: this.state.startLoc
10891
+ });
10892
+ if (this.lookaheadCharCode() === 40) {
10893
+ state.stop = true;
10894
+ return base;
10895
+ }
10879
10896
  }
10880
10897
  state.optionalChainMember = optional = true;
10881
10898
  this.next();
@@ -11519,7 +11536,7 @@ class ExpressionParser extends LValParser {
11519
11536
  const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
11520
11537
  this.next();
11521
11538
  const metaProp = this.parseMetaProperty(node, meta, "target");
11522
- if (!this.scope.inNonArrowFunction && !this.scope.inClass) {
11539
+ if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
11523
11540
  this.raise(Errors.UnexpectedNewTarget, {
11524
11541
  at: metaProp
11525
11542
  });
@@ -11540,20 +11557,11 @@ class ExpressionParser extends LValParser {
11540
11557
  return this.finishNode(node, "NewExpression");
11541
11558
  }
11542
11559
  parseNewCallee(node) {
11543
- var _node$callee$extra;
11544
11560
  node.callee = this.parseNoCallExpr();
11545
11561
  if (node.callee.type === "Import") {
11546
11562
  this.raise(Errors.ImportCallNotNewExpression, {
11547
11563
  at: node.callee
11548
11564
  });
11549
- } else if (this.isOptionalChain(node.callee) && !((_node$callee$extra = node.callee.extra) != null && _node$callee$extra.parenthesized)) {
11550
- this.raise(Errors.OptionalChainingNoNew, {
11551
- at: this.state.lastTokEndLoc
11552
- });
11553
- } else if (this.eat(18)) {
11554
- this.raise(Errors.OptionalChainingNoNew, {
11555
- at: this.state.startLoc
11556
- });
11557
11565
  }
11558
11566
  }
11559
11567
  parseTemplateElement(isTagged) {
@@ -11841,10 +11849,9 @@ class ExpressionParser extends LValParser {
11841
11849
  parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
11842
11850
  this.initFunction(node, isAsync);
11843
11851
  node.generator = isGenerator;
11844
- const allowModifiers = isConstructor;
11845
11852
  this.scope.enter(SCOPE_FUNCTION | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
11846
11853
  this.prodParam.enter(functionFlags(isAsync, node.generator));
11847
- this.parseFunctionParams(node, allowModifiers);
11854
+ this.parseFunctionParams(node, isConstructor);
11848
11855
  const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
11849
11856
  this.prodParam.exit();
11850
11857
  this.scope.exit();
@@ -12029,7 +12036,21 @@ class ExpressionParser extends LValParser {
12029
12036
  if (!canBeReservedWord(word)) {
12030
12037
  return;
12031
12038
  }
12032
- if (word === "yield") {
12039
+ if (checkKeywords && isKeyword(word)) {
12040
+ this.raise(Errors.UnexpectedKeyword, {
12041
+ at: startLoc,
12042
+ keyword: word
12043
+ });
12044
+ return;
12045
+ }
12046
+ const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
12047
+ if (reservedTest(word, this.inModule)) {
12048
+ this.raise(Errors.UnexpectedReservedWord, {
12049
+ at: startLoc,
12050
+ reservedWord: word
12051
+ });
12052
+ return;
12053
+ } else if (word === "yield") {
12033
12054
  if (this.prodParam.hasYield) {
12034
12055
  this.raise(Errors.YieldBindingIdentifier, {
12035
12056
  at: startLoc
@@ -12060,20 +12081,6 @@ class ExpressionParser extends LValParser {
12060
12081
  return;
12061
12082
  }
12062
12083
  }
12063
- if (checkKeywords && isKeyword(word)) {
12064
- this.raise(Errors.UnexpectedKeyword, {
12065
- at: startLoc,
12066
- keyword: word
12067
- });
12068
- return;
12069
- }
12070
- const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
12071
- if (reservedTest(word, this.inModule)) {
12072
- this.raise(Errors.UnexpectedReservedWord, {
12073
- at: startLoc,
12074
- reservedWord: word
12075
- });
12076
- }
12077
12084
  }
12078
12085
  isAwaitAllowed() {
12079
12086
  if (this.prodParam.hasAwait) return true;
@@ -12518,10 +12525,17 @@ class StatementParser extends ExpressionParser {
12518
12525
  return this.parseStatementLike(ParseStatementFlag.AllowImportExport | ParseStatementFlag.AllowDeclaration | ParseStatementFlag.AllowFunctionDeclaration | ParseStatementFlag.AllowLabeledFunction);
12519
12526
  }
12520
12527
  parseStatementListItem() {
12521
- return this.parseStatementLike(ParseStatementFlag.AllowDeclaration | ParseStatementFlag.AllowFunctionDeclaration | ParseStatementFlag.AllowLabeledFunction);
12528
+ return this.parseStatementLike(ParseStatementFlag.AllowDeclaration | ParseStatementFlag.AllowFunctionDeclaration | (!this.options.annexB || this.state.strict ? 0 : ParseStatementFlag.AllowLabeledFunction));
12522
12529
  }
12523
- parseStatementOrFunctionDeclaration(disallowLabeledFunction) {
12524
- return this.parseStatementLike(ParseStatementFlag.AllowFunctionDeclaration | (disallowLabeledFunction ? 0 : ParseStatementFlag.AllowLabeledFunction));
12530
+ parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
12531
+ let flags = ParseStatementFlag.StatementOnly;
12532
+ if (this.options.annexB && !this.state.strict) {
12533
+ flags |= ParseStatementFlag.AllowFunctionDeclaration;
12534
+ if (allowLabeledFunction) {
12535
+ flags |= ParseStatementFlag.AllowLabeledFunction;
12536
+ }
12537
+ }
12538
+ return this.parseStatementLike(flags);
12525
12539
  }
12526
12540
  parseStatement() {
12527
12541
  return this.parseStatementLike(ParseStatementFlag.StatementOnly);
@@ -12552,16 +12566,10 @@ class StatementParser extends ExpressionParser {
12552
12566
  return this.parseForStatement(node);
12553
12567
  case 68:
12554
12568
  if (this.lookaheadCharCode() === 46) break;
12555
- if (!allowDeclaration) {
12556
- if (this.state.strict) {
12557
- this.raise(Errors.StrictFunction, {
12558
- at: this.state.startLoc
12559
- });
12560
- } else if (!allowFunctionDeclaration) {
12561
- this.raise(Errors.SloppyFunction, {
12562
- at: this.state.startLoc
12563
- });
12564
- }
12569
+ if (!allowFunctionDeclaration) {
12570
+ this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
12571
+ at: this.state.startLoc
12572
+ });
12565
12573
  }
12566
12574
  return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
12567
12575
  case 80:
@@ -12687,11 +12695,20 @@ class StatementParser extends ExpressionParser {
12687
12695
  }
12688
12696
  decoratorsEnabledBeforeExport() {
12689
12697
  if (this.hasPlugin("decorators-legacy")) return true;
12690
- return this.hasPlugin("decorators") && !!this.getPluginOption("decorators", "decoratorsBeforeExport");
12698
+ return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
12691
12699
  }
12692
12700
  maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
12693
12701
  if (maybeDecorators) {
12694
- classNode.decorators = 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
+ }
12695
12712
  this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
12696
12713
  if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
12697
12714
  }
@@ -12900,8 +12917,8 @@ class StatementParser extends ExpressionParser {
12900
12917
  parseIfStatement(node) {
12901
12918
  this.next();
12902
12919
  node.test = this.parseHeaderExpression();
12903
- node.consequent = this.parseStatementOrFunctionDeclaration(true);
12904
- node.alternate = this.eat(66) ? this.parseStatementOrFunctionDeclaration(true) : null;
12920
+ node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
12921
+ node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
12905
12922
  return this.finishNode(node, "IfStatement");
12906
12923
  }
12907
12924
  parseReturnStatement(node) {
@@ -12973,8 +12990,7 @@ class StatementParser extends ExpressionParser {
12973
12990
  }
12974
12991
  parseCatchClauseParam() {
12975
12992
  const param = this.parseBindingAtom();
12976
- const simple = param.type === "Identifier";
12977
- this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0);
12993
+ this.scope.enter(this.options.annexB && param.type === "Identifier" ? SCOPE_SIMPLE_CATCH : 0);
12978
12994
  this.checkLVal(param, {
12979
12995
  in: {
12980
12996
  type: "CatchClause"
@@ -13063,7 +13079,7 @@ class StatementParser extends ExpressionParser {
13063
13079
  kind: kind,
13064
13080
  statementStart: this.state.start
13065
13081
  });
13066
- node.body = flags & ParseStatementFlag.AllowLabeledFunction ? this.parseStatementOrFunctionDeclaration(false) : this.parseStatement();
13082
+ node.body = flags & ParseStatementFlag.AllowLabeledFunction ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
13067
13083
  this.state.labels.pop();
13068
13084
  node.label = expr;
13069
13085
  return this.finishNode(node, "LabeledStatement");
@@ -13145,7 +13161,7 @@ class StatementParser extends ExpressionParser {
13145
13161
  } else {
13146
13162
  node.await = awaitAt !== null;
13147
13163
  }
13148
- if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
13164
+ 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")) {
13149
13165
  this.raise(Errors.ForInOfLoopInitializer, {
13150
13166
  at: init,
13151
13167
  type: isForIn ? "ForInStatement" : "ForOfStatement"
@@ -13250,15 +13266,15 @@ class StatementParser extends ExpressionParser {
13250
13266
  parseFunctionId(requireId) {
13251
13267
  return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
13252
13268
  }
13253
- parseFunctionParams(node, allowModifiers) {
13269
+ parseFunctionParams(node, isConstructor) {
13254
13270
  this.expect(10);
13255
13271
  this.expressionScope.enter(newParameterDeclarationScope());
13256
- node.params = this.parseBindingList(11, 41, false, allowModifiers);
13272
+ node.params = this.parseBindingList(11, 41, ParseBindingListFlags.IS_FUNCTION_PARAMS | (isConstructor ? ParseBindingListFlags.IS_CONSTRUCTOR_PARAMS : 0));
13257
13273
  this.expressionScope.exit();
13258
13274
  }
13259
13275
  registerFunctionStatementId(node) {
13260
13276
  if (!node.id) return;
13261
- this.scope.declareName(node.id.name, this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION, node.id.loc.start);
13277
+ this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION, node.id.loc.start);
13262
13278
  }
13263
13279
  parseClass(node, isStatement, optionalId) {
13264
13280
  this.next();
@@ -13731,7 +13747,7 @@ class StatementParser extends ExpressionParser {
13731
13747
  return this.parseClass(expr, true, true);
13732
13748
  }
13733
13749
  if (this.match(26)) {
13734
- if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport")) {
13750
+ if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
13735
13751
  this.raise(Errors.DecoratorBeforeExport, {
13736
13752
  at: this.state.startLoc
13737
13753
  });
@@ -13806,8 +13822,8 @@ class StatementParser extends ExpressionParser {
13806
13822
  if (type === 26) {
13807
13823
  this.expectOnePlugin(["decorators", "decorators-legacy"]);
13808
13824
  if (this.hasPlugin("decorators")) {
13809
- if (this.getPluginOption("decorators", "decoratorsBeforeExport")) {
13810
- throw this.raise(Errors.DecoratorBeforeExport, {
13825
+ if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
13826
+ this.raise(Errors.DecoratorBeforeExport, {
13811
13827
  at: this.state.startLoc
13812
13828
  });
13813
13829
  }