Skip to content

Commit 038f665

Browse files
Kingwlsandersn
authored andcommitted
fix lookup regression again (#26762)
* fix lookup regression again * add test case
1 parent c327ab4 commit 038f665

11 files changed

+46
-6
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ namespace ts {
12121212
}
12131213
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
12141214
// expression inside parameter will lookup as normal variable scope when targeting es2015+
1215-
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration !== lastLocation) {
1215+
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration.pos > lastLocation.end) {
12161216
useResult = false;
12171217
}
12181218
else if (result.flags & SymbolFlags.FunctionScopedVariable) {

tests/baselines/reference/parameterInitializersForwardReferencing1.errors.txt

+2
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(29
5555
class Foo {
5656
constructor(public x = 12, public y = x) {}
5757
}
58+
59+
function f8(foo1: string, bar = foo1) { }
5860

tests/baselines/reference/parameterInitializersForwardReferencing1.js

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ function f7({[foo]: bar}: any[]) {
3434
class Foo {
3535
constructor(public x = 12, public y = x) {}
3636
}
37+
38+
function f8(foo1: string, bar = foo1) { }
3739

3840

3941
//// [parameterInitializersForwardReferencing1.js]
@@ -81,3 +83,6 @@ var Foo = /** @class */ (function () {
8183
}
8284
return Foo;
8385
}());
86+
function f8(foo1, bar) {
87+
if (bar === void 0) { bar = foo1; }
88+
}

tests/baselines/reference/parameterInitializersForwardReferencing1.symbols

+6
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,9 @@ class Foo {
8484
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1.ts, 33, 16))
8585
}
8686

87+
function f8(foo1: string, bar = foo1) { }
88+
>f8 : Symbol(f8, Decl(parameterInitializersForwardReferencing1.ts, 34, 1))
89+
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1.ts, 36, 12))
90+
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1.ts, 36, 25))
91+
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1.ts, 36, 12))
92+

tests/baselines/reference/parameterInitializersForwardReferencing1.types

+6
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ class Foo {
9292
>x : number
9393
}
9494

95+
function f8(foo1: string, bar = foo1) { }
96+
>f8 : (foo1: string, bar?: string) => void
97+
>foo1 : string
98+
>bar : string
99+
>foo1 : string
100+

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.errors.txt

+2
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
4242
class Foo {
4343
constructor(public x = 12, public y = x) {}
4444
}
45+
46+
function f8(foo1: string, bar = foo1) { }
4547

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.js

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ function f7({[foo]: bar}: any[]) {
3434
class Foo {
3535
constructor(public x = 12, public y = x) {}
3636
}
37+
38+
function f8(foo1: string, bar = foo1) { }
3739

3840

3941
//// [parameterInitializersForwardReferencing1_es6.js]
@@ -67,3 +69,4 @@ class Foo {
6769
this.y = y;
6870
}
6971
}
72+
function f8(foo1, bar = foo1) { }

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.symbols

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function f4 (foo, bar = foo) {
4242
>f4 : Symbol(f4, Decl(parameterInitializersForwardReferencing1_es6.ts, 14, 1))
4343
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 13))
4444
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 17))
45-
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
45+
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 13))
4646

4747
return bar
4848
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 17))
@@ -84,3 +84,9 @@ class Foo {
8484
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 16))
8585
}
8686

87+
function f8(foo1: string, bar = foo1) { }
88+
>f8 : Symbol(f8, Decl(parameterInitializersForwardReferencing1_es6.ts, 34, 1))
89+
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 12))
90+
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 25))
91+
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 12))
92+

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.types

+10-4
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
4545
}
4646

4747
function f4 (foo, bar = foo) {
48-
>f4 : (foo: any, bar?: string) => string
48+
>f4 : (foo: any, bar?: any) => any
49+
>foo : any
50+
>bar : any
4951
>foo : any
50-
>bar : string
51-
>foo : string
5252

5353
return bar
54-
>bar : string
54+
>bar : any
5555
}
5656

5757
function f5 (a = a) {
@@ -92,3 +92,9 @@ class Foo {
9292
>x : number
9393
}
9494

95+
function f8(foo1: string, bar = foo1) { }
96+
>f8 : (foo1: string, bar?: string) => void
97+
>foo1 : string
98+
>bar : string
99+
>foo1 : string
100+

tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ function f7({[foo]: bar}: any[]) {
3333
class Foo {
3434
constructor(public x = 12, public y = x) {}
3535
}
36+
37+
function f8(foo1: string, bar = foo1) { }

tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ function f7({[foo]: bar}: any[]) {
3535
class Foo {
3636
constructor(public x = 12, public y = x) {}
3737
}
38+
39+
function f8(foo1: string, bar = foo1) { }

0 commit comments

Comments
 (0)