Skip to content

Commit e203073

Browse files
committed
Add transformed members to constructor body, not the original ones
1 parent 19f01a2 commit e203073

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ namespace ts {
916916
);
917917

918918
const parameters = transformConstructorParameters(constructor);
919-
const body = transformConstructorBody(node.members, constructor, parametersWithPropertyAssignments);
919+
const body = transformConstructorBody(existingMembers, constructor, parametersWithPropertyAssignments);
920920
members.push(startOnNewLine(
921921
setOriginalNode(
922922
setTextRange(

tests/baselines/reference/instanceMemberInitialization.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ class C {
66
var c = new C();
77
c.x = 3;
88
var c2 = new C();
9-
var r = c.x === c2.x;
9+
var r = c.x === c2.x;
10+
11+
// #31792
12+
class MyMap<K, V> {
13+
constructor(private readonly Map_: { new<K, V>(): any }) {}
14+
private readonly store = new this.Map_<K, V>();
15+
}
16+
1017

1118
//// [instanceMemberInitialization.js]
1219
var C = /** @class */ (function () {
@@ -19,3 +26,11 @@ var c = new C();
1926
c.x = 3;
2027
var c2 = new C();
2128
var r = c.x === c2.x;
29+
// #31792
30+
var MyMap = /** @class */ (function () {
31+
function MyMap(Map_) {
32+
this.Map_ = Map_;
33+
this.store = new this.Map_();
34+
}
35+
return MyMap;
36+
}());

tests/baselines/reference/instanceMemberInitialization.symbols

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,23 @@ var r = c.x === c2.x;
2828
>c2 : Symbol(c2, Decl(instanceMemberInitialization.ts, 6, 3))
2929
>x : Symbol(C.x, Decl(instanceMemberInitialization.ts, 0, 9))
3030

31+
// #31792
32+
class MyMap<K, V> {
33+
>MyMap : Symbol(MyMap, Decl(instanceMemberInitialization.ts, 7, 21))
34+
>K : Symbol(K, Decl(instanceMemberInitialization.ts, 10, 12))
35+
>V : Symbol(V, Decl(instanceMemberInitialization.ts, 10, 14))
36+
37+
constructor(private readonly Map_: { new<K, V>(): any }) {}
38+
>Map_ : Symbol(MyMap.Map_, Decl(instanceMemberInitialization.ts, 11, 13))
39+
>K : Symbol(K, Decl(instanceMemberInitialization.ts, 11, 42))
40+
>V : Symbol(V, Decl(instanceMemberInitialization.ts, 11, 44))
41+
42+
private readonly store = new this.Map_<K, V>();
43+
>store : Symbol(MyMap.store, Decl(instanceMemberInitialization.ts, 11, 60))
44+
>this.Map_ : Symbol(MyMap.Map_, Decl(instanceMemberInitialization.ts, 11, 13))
45+
>this : Symbol(MyMap, Decl(instanceMemberInitialization.ts, 7, 21))
46+
>Map_ : Symbol(MyMap.Map_, Decl(instanceMemberInitialization.ts, 11, 13))
47+
>K : Symbol(K, Decl(instanceMemberInitialization.ts, 10, 12))
48+
>V : Symbol(V, Decl(instanceMemberInitialization.ts, 10, 14))
49+
}
50+

tests/baselines/reference/instanceMemberInitialization.types

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ var r = c.x === c2.x;
3434
>c2 : C
3535
>x : number
3636

37+
// #31792
38+
class MyMap<K, V> {
39+
>MyMap : MyMap<K, V>
40+
41+
constructor(private readonly Map_: { new<K, V>(): any }) {}
42+
>Map_ : new <K, V>() => any
43+
44+
private readonly store = new this.Map_<K, V>();
45+
>store : any
46+
>new this.Map_<K, V>() : any
47+
>this.Map_ : new <K, V>() => any
48+
>this : this
49+
>Map_ : new <K, V>() => any
50+
}
51+

tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var c2 = new C();
88
var r = c.x === c2.x;
99

1010
// #31792
11-
export class MyMap<K, V> {
12-
constructor(private readonly Map_: typeof Map = Map) {}
11+
class MyMap<K, V> {
12+
constructor(private readonly Map_: { new<K, V>(): any }) {}
1313
private readonly store = new this.Map_<K, V>();
1414
}

0 commit comments

Comments
 (0)