Skip to content

Commit f67d7e0

Browse files
Kingwlsandersn
authored andcommitted
add test case and fix regression (#26726)
1 parent 30f611b commit f67d7e0

11 files changed

+79
-2
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,8 @@ namespace ts {
12111211
: false;
12121212
}
12131213
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
1214-
// parameter initializer will lookup as normal variable scope when targeting es2015+
1215-
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && result.valueDeclaration !== lastLocation) {
1214+
// 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) {
12161216
useResult = false;
12171217
}
12181218
else if (result.flags & SymbolFlags.FunctionScopedVariable) {

tests/baselines/reference/parameterInitializersForwardReferencing1.errors.txt

+4
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(29
5151
!!! related TS2728 tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts:30:9: 'foo' is declared here.
5252
let foo: number = 2;
5353
}
54+
55+
class Foo {
56+
constructor(public x = 12, public y = x) {}
57+
}
5458

tests/baselines/reference/parameterInitializersForwardReferencing1.js

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ function f6 (async = async) {
3030
function f7({[foo]: bar}: any[]) {
3131
let foo: number = 2;
3232
}
33+
34+
class Foo {
35+
constructor(public x = 12, public y = x) {}
36+
}
3337

3438

3539
//// [parameterInitializersForwardReferencing1.js]
@@ -68,3 +72,12 @@ function f7(_a) {
6872
var _b = foo, bar = _a[_b];
6973
var foo = 2;
7074
}
75+
var Foo = /** @class */ (function () {
76+
function Foo(x, y) {
77+
if (x === void 0) { x = 12; }
78+
if (y === void 0) { y = x; }
79+
this.x = x;
80+
this.y = y;
81+
}
82+
return Foo;
83+
}());

tests/baselines/reference/parameterInitializersForwardReferencing1.symbols

+9
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ function f7({[foo]: bar}: any[]) {
7575
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1.ts, 29, 7))
7676
}
7777

78+
class Foo {
79+
>Foo : Symbol(Foo, Decl(parameterInitializersForwardReferencing1.ts, 30, 1))
80+
81+
constructor(public x = 12, public y = x) {}
82+
>x : Symbol(Foo.x, Decl(parameterInitializersForwardReferencing1.ts, 33, 16))
83+
>y : Symbol(Foo.y, Decl(parameterInitializersForwardReferencing1.ts, 33, 30))
84+
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1.ts, 33, 16))
85+
}
86+

tests/baselines/reference/parameterInitializersForwardReferencing1.types

+10
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ function f7({[foo]: bar}: any[]) {
8282
>2 : 2
8383
}
8484

85+
class Foo {
86+
>Foo : Foo
87+
88+
constructor(public x = 12, public y = x) {}
89+
>x : number
90+
>12 : 12
91+
>y : number
92+
>x : number
93+
}
94+

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.errors.txt

+4
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
3838
function f7({[foo]: bar}: any[]) {
3939
let foo: number = 2;
4040
}
41+
42+
class Foo {
43+
constructor(public x = 12, public y = x) {}
44+
}
4145

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.js

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ function f6 (async = async) {
3030
function f7({[foo]: bar}: any[]) {
3131
let foo: number = 2;
3232
}
33+
34+
class Foo {
35+
constructor(public x = 12, public y = x) {}
36+
}
3337

3438

3539
//// [parameterInitializersForwardReferencing1_es6.js]
@@ -57,3 +61,9 @@ function f6(async = async) {
5761
function f7({ [foo]: bar }) {
5862
let foo = 2;
5963
}
64+
class Foo {
65+
constructor(x = 12, y = x) {
66+
this.x = x;
67+
this.y = y;
68+
}
69+
}

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.symbols

+9
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ function f7({[foo]: bar}: any[]) {
7575
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 29, 7))
7676
}
7777

78+
class Foo {
79+
>Foo : Symbol(Foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 30, 1))
80+
81+
constructor(public x = 12, public y = x) {}
82+
>x : Symbol(Foo.x, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 16))
83+
>y : Symbol(Foo.y, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 30))
84+
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 16))
85+
}
86+

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.types

+10
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ function f7({[foo]: bar}: any[]) {
8282
>2 : 2
8383
}
8484

85+
class Foo {
86+
>Foo : Foo
87+
88+
constructor(public x = 12, public y = x) {}
89+
>x : number
90+
>12 : 12
91+
>y : number
92+
>x : number
93+
}
94+

tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts

+4
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ function f6 (async = async) {
2929
function f7({[foo]: bar}: any[]) {
3030
let foo: number = 2;
3131
}
32+
33+
class Foo {
34+
constructor(public x = 12, public y = x) {}
35+
}

tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ function f6 (async = async) {
3131
function f7({[foo]: bar}: any[]) {
3232
let foo: number = 2;
3333
}
34+
35+
class Foo {
36+
constructor(public x = 12, public y = x) {}
37+
}

0 commit comments

Comments
 (0)