From 64fa7fbecbede0b33acdff69cb63e7425ff6c23b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 13 Mar 2015 11:52:14 -0700 Subject: [PATCH] use Value meaning as a filter when resolving names to prevent skipping other value in favor of block-scoped variables --- src/compiler/checker.ts | 2 +- .../letConstMatchingParameterNames.js | 28 ++++++++++++++ .../letConstMatchingParameterNames.types | 37 +++++++++++++++++++ .../letConstMatchingParameterNames.ts | 15 ++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/letConstMatchingParameterNames.js create mode 100644 tests/baselines/reference/letConstMatchingParameterNames.types create mode 100644 tests/cases/compiler/letConstMatchingParameterNames.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1500a47f19..782ffccc0e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11072,7 +11072,7 @@ module ts { var symbol = declarationSymbol || getNodeLinks(n).resolvedSymbol || - resolveName(n, n.text, SymbolFlags.BlockScopedVariable | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); var isLetOrConst = symbol && diff --git a/tests/baselines/reference/letConstMatchingParameterNames.js b/tests/baselines/reference/letConstMatchingParameterNames.js new file mode 100644 index 0000000000..a11405b9f8 --- /dev/null +++ b/tests/baselines/reference/letConstMatchingParameterNames.js @@ -0,0 +1,28 @@ +//// [letConstMatchingParameterNames.ts] +let parent = true; +const parent2 = true; +declare function use(a: any); + +function a() { + + let parent = 1; + const parent2 = 2; + + function b(parent: string, parent2: number) { + use(parent); + use(parent2); + } +} + + +//// [letConstMatchingParameterNames.js] +var parent = true; +var parent2 = true; +function a() { + var _parent = 1; + var _parent2 = 2; + function b(parent, parent2) { + use(parent); + use(parent2); + } +} diff --git a/tests/baselines/reference/letConstMatchingParameterNames.types b/tests/baselines/reference/letConstMatchingParameterNames.types new file mode 100644 index 0000000000..66fccc637d --- /dev/null +++ b/tests/baselines/reference/letConstMatchingParameterNames.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/letConstMatchingParameterNames.ts === +let parent = true; +>parent : boolean + +const parent2 = true; +>parent2 : boolean + +declare function use(a: any); +>use : (a: any) => any +>a : any + +function a() { +>a : () => void + + let parent = 1; +>parent : number + + const parent2 = 2; +>parent2 : number + + function b(parent: string, parent2: number) { +>b : (parent: string, parent2: number) => void +>parent : string +>parent2 : number + + use(parent); +>use(parent) : any +>use : (a: any) => any +>parent : string + + use(parent2); +>use(parent2) : any +>use : (a: any) => any +>parent2 : number + } +} + diff --git a/tests/cases/compiler/letConstMatchingParameterNames.ts b/tests/cases/compiler/letConstMatchingParameterNames.ts new file mode 100644 index 0000000000..e749912ad8 --- /dev/null +++ b/tests/cases/compiler/letConstMatchingParameterNames.ts @@ -0,0 +1,15 @@ +// @target: es5 +let parent = true; +const parent2 = true; +declare function use(a: any); + +function a() { + + let parent = 1; + const parent2 = 2; + + function b(parent: string, parent2: number) { + use(parent); + use(parent2); + } +}