fix(40222): fix crash on using destructuring in a catch clause (#40240)

This commit is contained in:
Alex T
2020-09-08 21:49:45 +03:00
committed by GitHub
parent fa89ce6158
commit 15084465b7
6 changed files with 137 additions and 6 deletions

View File

@@ -34237,12 +34237,15 @@ namespace ts {
if (catchClause) {
// Grammar checking
if (catchClause.variableDeclaration) {
if (catchClause.variableDeclaration.type && getTypeOfNode(catchClause.variableDeclaration) === errorType) {
grammarErrorOnFirstToken(catchClause.variableDeclaration.type,
Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
const declaration = catchClause.variableDeclaration;
if (declaration.type) {
const type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false);
if (type && !(type.flags & TypeFlags.AnyOrUnknown)) {
grammarErrorOnFirstToken(declaration.type, Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
}
}
else if (catchClause.variableDeclaration.initializer) {
grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
else if (declaration.initializer) {
grammarErrorOnFirstToken(declaration.initializer, Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
}
else {
const blockLocals = catchClause.block.locals;