Do not throw an error for optional binding pattern params in function declaration (#12085)
This commit is contained in:
parent
18d13d0032
commit
3628c52867
@ -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);
|
||||
}
|
||||
|
||||
|
||||
1
packages/babel-parser/test/fixtures/typescript/function/declare-pattern-parameters/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/function/declare-pattern-parameters/input.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare function f([]?, {})
|
||||
38
packages/babel-parser/test/fixtures/typescript/function/declare-pattern-parameters/output.json
vendored
Normal file
38
packages/babel-parser/test/fixtures/typescript/function/declare-pattern-parameters/output.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user