Error on redeclaring a variable with let/const already defined as catch parameter

This commit is contained in:
unknown
2015-03-06 21:42:42 +01:00
parent 5ca703eeb4
commit b4d723217e

View File

@@ -9158,6 +9158,15 @@ module ts {
grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
}
else {
var identifierName = (<Identifier>catchClause.variableDeclaration.name).text;
var locals = catchClause.block.locals;
if (locals && locals[identifierName]) {
var localSymbol = locals[identifierName]
if (localSymbol && (localSymbol.flags & SymbolFlags.BlockScopedVariable) !== 0) {
grammarErrorOnNode(localSymbol.valueDeclaration, Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
}
}
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
// Catch production is eval or arguments
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>catchClause.variableDeclaration.name);