Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow tuple rest trailing comma (#10800)
  • Loading branch information
yeonjuan authored and nicolo-ribaudo committed Dec 3, 2019
1 parent e74efd2 commit d18afbd
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 1 deletion.
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
) {
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": []
}
}

0 comments on commit d18afbd

Please sign in to comment.