Allow trailing comma after rest parameter in TSDeclareFunction (#13101)
* fix(ts): allow trailing comma after rest parameter in `TSDeclareFunction` * Apply code review changes Co-Authored-By: Nicolò Ribaudo <7000710+nicolo-ribaudo@users.noreply.github.com>
This commit is contained in:
parent
6b57145d38
commit
42e630e8a2
@ -2789,6 +2789,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return super.parseMaybeDecoratorArguments(expr);
|
||||
}
|
||||
|
||||
checkCommaAfterRest(close) {
|
||||
if (
|
||||
this.state.isDeclareContext &&
|
||||
this.match(tt.comma) &&
|
||||
this.lookaheadCharCode() === close
|
||||
) {
|
||||
this.next();
|
||||
} else {
|
||||
super.checkCommaAfterRest(close);
|
||||
}
|
||||
}
|
||||
|
||||
// === === === === === === === === === === === === === === === ===
|
||||
// Note: All below methods are duplicates of something in flow.js.
|
||||
// Not sure what the best way to combine these is.
|
||||
|
||||
1
packages/babel-parser/test/fixtures/typescript/declare/function-rest-trailing-comma/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/declare/function-rest-trailing-comma/input.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare function foo(...args: any[], )
|
||||
48
packages/babel-parser/test/fixtures/typescript/declare/function-rest-trailing-comma/output.json
vendored
Normal file
48
packages/babel-parser/test/fixtures/typescript/declare/function-rest-trailing-comma/output.json
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "TSDeclareFunction",
|
||||
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}},
|
||||
"declare": true,
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":17,"end":20,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":20},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "RestElement",
|
||||
"start":21,"end":35,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":35}},
|
||||
"argument": {
|
||||
"type": "Identifier",
|
||||
"start":24,"end":28,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":28},"identifierName":"args"},
|
||||
"name": "args"
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start":28,"end":35,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":35}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSArrayType",
|
||||
"start":30,"end":35,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":35}},
|
||||
"elementType": {
|
||||
"type": "TSAnyKeyword",
|
||||
"start":30,"end":33,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":33}}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user