mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-26 19:25:41 -05:00
Fix search for shadowed const declarations by a var declarations to search for any variable instead of only a blockScoped one to ensure we are not picking it up from a wrong scope.
This commit is contained in:
@@ -6776,8 +6776,8 @@ module ts {
|
||||
// }
|
||||
if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) {
|
||||
var symbol = getSymbolOfNode(node);
|
||||
var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.BlockScoped, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
|
||||
if (localDeclarationSymbol && localDeclarationSymbol !== symbol) {
|
||||
var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
|
||||
if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScoped) {
|
||||
if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) {
|
||||
error(node, Diagnostics.Cannot_redeclare_constant_0, symbolToString(localDeclarationSymbol));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//// [constDeclarationShadowedByVarDeclaration2.ts]
|
||||
|
||||
// No errors, const declaration is not shadowed
|
||||
function outer() {
|
||||
const x = 0;
|
||||
function inner() {
|
||||
var x = "inner";
|
||||
}
|
||||
}
|
||||
|
||||
//// [constDeclarationShadowedByVarDeclaration2.js]
|
||||
// No errors, const declaration is not shadowed
|
||||
function outer() {
|
||||
const x = 0;
|
||||
function inner() {
|
||||
var x = "inner";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts ===
|
||||
|
||||
// No errors, const declaration is not shadowed
|
||||
function outer() {
|
||||
>outer : () => void
|
||||
|
||||
const x = 0;
|
||||
>x : number
|
||||
|
||||
function inner() {
|
||||
>inner : () => void
|
||||
|
||||
var x = "inner";
|
||||
>x : string
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @target: ES6
|
||||
|
||||
// No errors, const declaration is not shadowed
|
||||
function outer() {
|
||||
const x = 0;
|
||||
function inner() {
|
||||
var x = "inner";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user