Skip to content

Commit b4d7232

Browse files
committed
Error on redeclaring a variable with let/const already defined as catch parameter
1 parent 5ca703e commit b4d7232

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/compiler/checker.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9158,6 +9158,15 @@ module ts {
91589158
grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
91599159
}
91609160
else {
9161+
var identifierName = (<Identifier>catchClause.variableDeclaration.name).text;
9162+
var locals = catchClause.block.locals;
9163+
if (locals && locals[identifierName]) {
9164+
var localSymbol = locals[identifierName]
9165+
if (localSymbol && (localSymbol.flags & SymbolFlags.BlockScopedVariable) !== 0) {
9166+
grammarErrorOnNode(localSymbol.valueDeclaration, Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
9167+
}
9168+
}
9169+
91619170
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
91629171
// Catch production is eval or arguments
91639172
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>catchClause.variableDeclaration.name);

0 commit comments

Comments
 (0)