Skip to content

Commit

Permalink
Do not throw an error for optional binding pattern params in function…
Browse files Browse the repository at this point in the history
… declaration (#12085)
  • Loading branch information
sosukesuzuki committed Sep 21, 2020
1 parent 18d13d0 commit 3628c52
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -2526,7 +2526,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// Allow type annotations inside of a parameter list.
parseAssignableListItemTypes(param: N.Pattern) {
if (this.eat(tt.question)) {
if (param.type !== "Identifier") {
if (param.type !== "Identifier" && !this.state.isDeclareContext) {
this.raise(param.start, TSErrors.PatternIsOptional);
}

Expand Down
@@ -0,0 +1 @@
declare function f([]?, {})
@@ -0,0 +1,38 @@
{
"type": "File",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
"program": {
"type": "Program",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "TSDeclareFunction",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
"declare": true,
"id": {
"type": "Identifier",
"start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18},"identifierName":"f"},
"name": "f"
},
"generator": false,
"async": false,
"params": [
{
"type": "ArrayPattern",
"start":19,"end":22,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":22}},
"elements": [],
"optional": true
},
{
"type": "ObjectPattern",
"start":24,"end":26,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":26}},
"properties": []
}
]
}
],
"directives": []
}
}

0 comments on commit 3628c52

Please sign in to comment.