Allow unknown/any in TS catch clause param (#11755)

This commit is contained in:
Brian Ng
2020-06-30 03:40:20 -05:00
committed by Huáng Jùnliàng
parent 5b4b3a3e4a
commit 8a1d7e41f2
7 changed files with 337 additions and 6 deletions

View File

@@ -636,6 +636,16 @@ export default class StatementParser extends ExpressionParser {
return this.finishNode(node, "ThrowStatement");
}
parseCatchClauseParam(): N.Identifier {
const param = this.parseBindingAtom();
const simple = param.type === "Identifier";
this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0);
this.checkLVal(param, BIND_LEXICAL, null, "catch clause");
return param;
}
parseTryStatement(node: N.TryStatement): N.TryStatement {
this.next();
@@ -647,10 +657,7 @@ export default class StatementParser extends ExpressionParser {
this.next();
if (this.match(tt.parenL)) {
this.expect(tt.parenL);
clause.param = this.parseBindingAtom();
const simple = clause.param.type === "Identifier";
this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0);
this.checkLVal(clause.param, BIND_LEXICAL, null, "catch clause");
clause.param = this.parseCatchClauseParam();
this.expect(tt.parenR);
} else {
clause.param = null;

View File

@@ -2660,4 +2660,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return hasContextParam ? baseCount + 1 : baseCount;
}
parseCatchClauseParam(): N.Identifier {
const param = super.parseCatchClauseParam();
const type = this.tsTryParseTypeAnnotation();
if (type) {
param.type = type;
}
return param;
}
};