fix lookup regression again (#26762)

* fix lookup regression again

* add test case
This commit is contained in:
Wenlu Wang
2018-08-30 08:48:49 -07:00
committed by Nathan Shively-Sanders
parent c327ab40bc
commit 038f665171
11 changed files with 46 additions and 6 deletions
+1 -1
View File
@@ -1212,7 +1212,7 @@ namespace ts {
}
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
// expression inside parameter will lookup as normal variable scope when targeting es2015+
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration !== lastLocation) {
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration.pos > lastLocation.end) {
useResult = false;
}
else if (result.flags & SymbolFlags.FunctionScopedVariable) {
@@ -55,4 +55,6 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(29
class Foo {
constructor(public x = 12, public y = x) {}
}
function f8(foo1: string, bar = foo1) { }
@@ -34,6 +34,8 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}
function f8(foo1: string, bar = foo1) { }
//// [parameterInitializersForwardReferencing1.js]
@@ -81,3 +83,6 @@ var Foo = /** @class */ (function () {
}
return Foo;
}());
function f8(foo1, bar) {
if (bar === void 0) { bar = foo1; }
}
@@ -84,3 +84,9 @@ class Foo {
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1.ts, 33, 16))
}
function f8(foo1: string, bar = foo1) { }
>f8 : Symbol(f8, Decl(parameterInitializersForwardReferencing1.ts, 34, 1))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1.ts, 36, 12))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1.ts, 36, 25))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1.ts, 36, 12))
@@ -92,3 +92,9 @@ class Foo {
>x : number
}
function f8(foo1: string, bar = foo1) { }
>f8 : (foo1: string, bar?: string) => void
>foo1 : string
>bar : string
>foo1 : string
@@ -42,4 +42,6 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
class Foo {
constructor(public x = 12, public y = x) {}
}
function f8(foo1: string, bar = foo1) { }
@@ -34,6 +34,8 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}
function f8(foo1: string, bar = foo1) { }
//// [parameterInitializersForwardReferencing1_es6.js]
@@ -67,3 +69,4 @@ class Foo {
this.y = y;
}
}
function f8(foo1, bar = foo1) { }
@@ -42,7 +42,7 @@ function f4 (foo, bar = foo) {
>f4 : Symbol(f4, Decl(parameterInitializersForwardReferencing1_es6.ts, 14, 1))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 13))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 17))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 13))
return bar
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 17))
@@ -84,3 +84,9 @@ class Foo {
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 16))
}
function f8(foo1: string, bar = foo1) { }
>f8 : Symbol(f8, Decl(parameterInitializersForwardReferencing1_es6.ts, 34, 1))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 12))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 25))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 12))
@@ -45,13 +45,13 @@ function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
}
function f4 (foo, bar = foo) {
>f4 : (foo: any, bar?: string) => string
>f4 : (foo: any, bar?: any) => any
>foo : any
>bar : any
>foo : any
>bar : string
>foo : string
return bar
>bar : string
>bar : any
}
function f5 (a = a) {
@@ -92,3 +92,9 @@ class Foo {
>x : number
}
function f8(foo1: string, bar = foo1) { }
>f8 : (foo1: string, bar?: string) => void
>foo1 : string
>bar : string
>foo1 : string
@@ -33,3 +33,5 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}
function f8(foo1: string, bar = foo1) { }
@@ -35,3 +35,5 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}
function f8(foo1: string, bar = foo1) { }