mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
fix(40222): fix crash on using destructuring in a catch clause (#40240)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user