From 56ea2f94be36435b766a28dc5260c2e504a1b8d5 Mon Sep 17 00:00:00 2001 From: harpica Date: Thu, 16 Feb 2023 08:46:33 +0300 Subject: [PATCH] refactor: raise error and add comments --- .../src/plugins/typescript/index.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index 801d58d292ea..6fdbb40cb38b 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -1130,6 +1130,9 @@ export default (superClass: ClassWithMixin) => } 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); } @@ -1143,20 +1146,11 @@ export default (superClass: ClassWithMixin) => } else { labeledNode = this.startNodeAtNode(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) {