Skip to content

Commit 40470ad

Browse files
committed
fix lookup regression again and again
1 parent d293b67 commit 40470ad

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,9 @@ namespace ts {
12131213
}
12141214
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
12151215
// expression inside parameter will lookup as normal variable scope when targeting es2015+
1216-
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration.pos > lastLocation.end) {
1216+
const functionLocation = <FunctionLikeDeclaration>location;
1217+
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) &&
1218+
functionLocation.body && result.valueDeclaration.pos >= functionLocation.body.pos && result.valueDeclaration.end <= functionLocation.body.end) {
12171219
useResult = false;
12181220
}
12191221
else if (result.flags & SymbolFlags.FunctionScopedVariable) {

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(13,20): error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
12
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(21,18): error TS2372: Parameter 'a' cannot be referenced in its initializer.
23
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(25,22): error TS2372: Parameter 'async' cannot be referenced in its initializer.
34

45

5-
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts (2 errors) ====
6+
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts (3 errors) ====
67
let foo: string = "";
78

89
function f1 (bar = foo) { // unexpected compiler error; works at runtime
@@ -16,6 +17,8 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
1617
}
1718

1819
function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
20+
~~~
21+
!!! error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
1922
return bar;
2023
}
2124

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at
3131
function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
3232
>f3 : Symbol(f3, Decl(parameterInitializersForwardReferencing1_es6.ts, 10, 1))
3333
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 12, 13))
34-
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
34+
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 12, 23))
3535
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 12, 23))
3636

3737
return bar;

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at
3434
}
3535

3636
function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
37-
>f3 : (bar?: string, foo?: number) => string
38-
>bar : string
39-
>foo : string
37+
>f3 : (bar?: number, foo?: number) => number
38+
>bar : number
39+
>foo : number
4040
>foo : number
4141
>2 : 2
4242

4343
return bar;
44-
>bar : string
44+
>bar : number
4545
}
4646

4747
function f4 (foo, bar = foo) {

0 commit comments

Comments
 (0)