diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index 3f57904f1ba7..6f82aad4accf 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -164,8 +164,6 @@ const TSErrors = ParseErrorEnum`typescript`({ "Tuple members must be labeled with a simple identifier.", MissingInterfaceName: "'interface' declarations must be followed by an identifier.", - MixedLabeledAndUnlabeledElements: - "Tuple members must all have names or all not have names.", NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.", NonClassMethodPropertyHasAbstractModifer: @@ -1050,7 +1048,6 @@ export default (superClass: ClassWithMixin) => // Validate the elementTypes to ensure that no mandatory elements // follow optional elements let seenOptionalElement = false; - let labeledElements: boolean | null = null; node.elementTypes.forEach(elementNode => { const { type } = elementNode; @@ -1068,21 +1065,6 @@ export default (superClass: ClassWithMixin) => seenOptionalElement ||= (type === "TSNamedTupleMember" && elementNode.optional) || type === "TSOptionalType"; - - // When checking labels, check the argument of the spread operator - let checkType = type; - if (type === "TSRestType") { - elementNode = elementNode.typeAnnotation; - checkType = elementNode.type; - } - - const isLabeled = checkType === "TSNamedTupleMember"; - labeledElements ??= isLabeled; - if (labeledElements !== isLabeled) { - this.raise(TSErrors.MixedLabeledAndUnlabeledElements, { - at: elementNode, - }); - } }); return this.finishNode(node, "TSTupleType"); diff --git a/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-after-unlabeled/output.json b/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-after-unlabeled/output.json index bcf9d39017fa..24cdcfa013b0 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-after-unlabeled/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-after-unlabeled/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":19,"index":19}}, - "errors": [ - "SyntaxError: Tuple members must all have names or all not have names. (1:13)" - ], "program": { "type": "Program", "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":19,"index":19}}, diff --git a/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-before-unlabeled/output.json b/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-before-unlabeled/output.json index 3f09fc6cfcbf..b501337c076a 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-before-unlabeled/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-before-unlabeled/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":19,"index":19}}, - "errors": [ - "SyntaxError: Tuple members must all have names or all not have names. (1:16)" - ], "program": { "type": "Program", "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":19,"index":19}}, diff --git a/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-after-labeled/output.json b/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-after-labeled/output.json index 225d3cfb850a..1e2ba7269cd8 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-after-labeled/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-after-labeled/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, - "errors": [ - "SyntaxError: Tuple members must all have names or all not have names. (1:19)" - ], "program": { "type": "Program", "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, diff --git a/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-before-labeled/output.json b/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-before-labeled/output.json index 191be6340b03..44b44449e806 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-before-labeled/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/tuple-unlabeled-spread-before-labeled/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, - "errors": [ - "SyntaxError: Tuple members must all have names or all not have names. (1:16)" - ], "program": { "type": "Program", "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}},