Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript 4.0: Allow spread in the middle of tuples #11753

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 2 additions & 9 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -630,9 +630,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
/* skipFirstToken */ false,
);

// Validate the elementTypes to ensure:
// No mandatory elements may follow optional elements
// If there's a rest element, it must be at the end of the tuple
// Validate the elementTypes to ensure that no mandatory elements
// follow optional elements
let seenOptionalElement = false;
node.elementTypes.forEach(elementNode => {
if (elementNode.type === "TSOptionalType") {
Expand All @@ -651,12 +650,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const restNode: N.TsRestType = this.startNode();
this.next(); // skips ellipsis
restNode.typeAnnotation = this.tsParseType();
if (
this.match(tt.comma) &&
this.lookaheadCharCode() !== charCodes.rightSquareBracket
) {
this.raiseRestNotLast(this.state.start);
}
return this.finishNode(restNode, "TSRestType");
}

Expand Down

This file was deleted.

This file was deleted.

@@ -0,0 +1 @@
let x: [...[number, string], string]
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript"]
}
@@ -0,0 +1,62 @@
{
"type": "File",
"start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":36}},
"program": {
"type": "Program",
"start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":36}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":36}},
"declarations": [
{
"type": "VariableDeclarator",
"start":4,"end":36,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":36}},
"id": {
"type": "Identifier",
"start":4,"end":36,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":36},"identifierName":"x"},
"name": "x",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start":5,"end":36,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":36}},
"typeAnnotation": {
"type": "TSTupleType",
"start":7,"end":36,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":36}},
"elementTypes": [
{
"type": "TSRestType",
"start":8,"end":27,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":27}},
"typeAnnotation": {
"type": "TSTupleType",
"start":11,"end":27,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":27}},
"elementTypes": [
{
"type": "TSNumberKeyword",
"start":12,"end":18,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":18}}
},
{
"type": "TSStringKeyword",
"start":20,"end":26,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":26}}
}
]
}
},
{
"type": "TSStringKeyword",
"start":29,"end":35,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":35}}
}
]
}
}
},
"init": null
}
],
"kind": "let"
}
],
"directives": []
}
}