Skip to content

Commit

Permalink
refactor: raise error and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Harpica committed Feb 24, 2023
1 parent 1026aa3 commit 6f3897d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -1144,6 +1144,9 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
} else {
type = this.tsParseType();
optional = this.eat(tt.question);
// In this case (labeled === true) could be only in invalid label.
// E.g. [x.y:type]
// An error is raised while processing node.
labeled = this.eat(tt.colon);
}

Expand All @@ -1157,20 +1160,11 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
} else {
labeledNode = this.startNodeAtNode<N.TsNamedTupleMember>(type);
labeledNode.optional = optional;
if (
type.type === "TSTypeReference" &&
!type.typeParameters &&
type.typeName.type === "Identifier"
) {
labeledNode.label = type.typeName;
labeledNode.elementType = this.tsParseType();
} else {
this.raise(TSErrors.InvalidTupleMemberLabel, { at: type });
// @ts-expect-error This produces an invalid AST, but at least we don't drop
// nodes representing the invalid source.
labeledNode.label = type;
labeledNode.elementType = this.tsParseType();
}
this.raise(TSErrors.InvalidTupleMemberLabel, { at: type });
// @ts-expect-error This produces an invalid AST, but at least we don't drop
// nodes representing the invalid source.
labeledNode.label = type;
labeledNode.elementType = this.tsParseType();
}
type = this.finishNode(labeledNode, "TSNamedTupleMember");
} else if (optional) {
Expand Down

0 comments on commit 6f3897d

Please sign in to comment.