Do not throw an error for optional binding pattern params in function declaration (#12085)

This commit is contained in:
Sosuke Suzuki
2020-09-21 23:14:13 +09:00
committed by GitHub
parent 18d13d0032
commit 3628c52867
3 changed files with 40 additions and 1 deletions

View File

@@ -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);
}