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

Allow tuple rest trailing comma #10800

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
7 changes: 6 additions & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -618,7 +618,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const restNode: N.TsRestType = this.startNode();
this.next(); // skips ellipsis
restNode.typeAnnotation = this.tsParseType();
this.checkCommaAfterRest(charCodes.rightSquareBracket);
if (
this.match(tt.comma) &&
this.lookaheadCharCode() !== charCodes.rightSquareBracket
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there already a test for when ...a, is not followed by ]?

Copy link
Contributor Author

@yeonjuan yeonjuan Dec 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@nicolo-ribaudo yes! in the tuple-rest-invalid.

) {
this.raiseRestNotLast(this.state.start);
}
return this.finishNode(restNode, "TSRestType");
}

Expand Down
@@ -0,0 +1 @@
let x: [string, ...string[],]
@@ -0,0 +1,178 @@
{
"type": "File",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"program": {
"type": "Program",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 29
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 29
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 5,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 29
}
},
"typeAnnotation": {
"type": "TSTupleType",
"start": 7,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 29
}
},
"elementTypes": [
{
"type": "TSStringKeyword",
"start": 8,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 14
}
}
},
{
"type": "TSRestType",
"start": 16,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 27
}
},
"typeAnnotation": {
"type": "TSArrayType",
"start": 19,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 27
}
},
"elementType": {
"type": "TSStringKeyword",
"start": 19,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 25
}
}
}
}
}
]
}
}
},
"init": null
}
],
"kind": "let"
}
],
"directives": []
}
}