From 19f01a2984b33bb7e77758840c4377a2dec279ae Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 6 Jun 2019 13:55:48 -0700 Subject: [PATCH 1/2] Add test for regression --- .../instanceMemberInitialization.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts index 6240da8078bd7..537f7b7f3a7c3 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts @@ -5,4 +5,10 @@ class C { var c = new C(); c.x = 3; var c2 = new C(); -var r = c.x === c2.x; \ No newline at end of file +var r = c.x === c2.x; + +// #31792 +export class MyMap { + constructor(private readonly Map_: typeof Map = Map) {} + private readonly store = new this.Map_(); +} From e203073d50649a934be6ccb8314a0af2f3046568 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 6 Jun 2019 15:08:35 -0700 Subject: [PATCH 2/2] Add transformed members to constructor body, not the original ones --- src/compiler/transformers/ts.ts | 2 +- .../reference/instanceMemberInitialization.js | 17 +++++++++++++++- .../instanceMemberInitialization.symbols | 20 +++++++++++++++++++ .../instanceMemberInitialization.types | 15 ++++++++++++++ .../instanceMemberInitialization.ts | 4 ++-- 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index adfe16c73f692..093f672ba93db 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -916,7 +916,7 @@ namespace ts { ); const parameters = transformConstructorParameters(constructor); - const body = transformConstructorBody(node.members, constructor, parametersWithPropertyAssignments); + const body = transformConstructorBody(existingMembers, constructor, parametersWithPropertyAssignments); members.push(startOnNewLine( setOriginalNode( setTextRange( diff --git a/tests/baselines/reference/instanceMemberInitialization.js b/tests/baselines/reference/instanceMemberInitialization.js index f153090d719f7..f5eec4aa4acc0 100644 --- a/tests/baselines/reference/instanceMemberInitialization.js +++ b/tests/baselines/reference/instanceMemberInitialization.js @@ -6,7 +6,14 @@ class C { var c = new C(); c.x = 3; var c2 = new C(); -var r = c.x === c2.x; +var r = c.x === c2.x; + +// #31792 +class MyMap { + constructor(private readonly Map_: { new(): any }) {} + private readonly store = new this.Map_(); +} + //// [instanceMemberInitialization.js] var C = /** @class */ (function () { @@ -19,3 +26,11 @@ var c = new C(); c.x = 3; var c2 = new C(); var r = c.x === c2.x; +// #31792 +var MyMap = /** @class */ (function () { + function MyMap(Map_) { + this.Map_ = Map_; + this.store = new this.Map_(); + } + return MyMap; +}()); diff --git a/tests/baselines/reference/instanceMemberInitialization.symbols b/tests/baselines/reference/instanceMemberInitialization.symbols index 4211713375901..210212f1a123e 100644 --- a/tests/baselines/reference/instanceMemberInitialization.symbols +++ b/tests/baselines/reference/instanceMemberInitialization.symbols @@ -28,3 +28,23 @@ var r = c.x === c2.x; >c2 : Symbol(c2, Decl(instanceMemberInitialization.ts, 6, 3)) >x : Symbol(C.x, Decl(instanceMemberInitialization.ts, 0, 9)) +// #31792 +class MyMap { +>MyMap : Symbol(MyMap, Decl(instanceMemberInitialization.ts, 7, 21)) +>K : Symbol(K, Decl(instanceMemberInitialization.ts, 10, 12)) +>V : Symbol(V, Decl(instanceMemberInitialization.ts, 10, 14)) + + constructor(private readonly Map_: { new(): any }) {} +>Map_ : Symbol(MyMap.Map_, Decl(instanceMemberInitialization.ts, 11, 13)) +>K : Symbol(K, Decl(instanceMemberInitialization.ts, 11, 42)) +>V : Symbol(V, Decl(instanceMemberInitialization.ts, 11, 44)) + + private readonly store = new this.Map_(); +>store : Symbol(MyMap.store, Decl(instanceMemberInitialization.ts, 11, 60)) +>this.Map_ : Symbol(MyMap.Map_, Decl(instanceMemberInitialization.ts, 11, 13)) +>this : Symbol(MyMap, Decl(instanceMemberInitialization.ts, 7, 21)) +>Map_ : Symbol(MyMap.Map_, Decl(instanceMemberInitialization.ts, 11, 13)) +>K : Symbol(K, Decl(instanceMemberInitialization.ts, 10, 12)) +>V : Symbol(V, Decl(instanceMemberInitialization.ts, 10, 14)) +} + diff --git a/tests/baselines/reference/instanceMemberInitialization.types b/tests/baselines/reference/instanceMemberInitialization.types index ca97ccac3336b..85cc64e9819cd 100644 --- a/tests/baselines/reference/instanceMemberInitialization.types +++ b/tests/baselines/reference/instanceMemberInitialization.types @@ -34,3 +34,18 @@ var r = c.x === c2.x; >c2 : C >x : number +// #31792 +class MyMap { +>MyMap : MyMap + + constructor(private readonly Map_: { new(): any }) {} +>Map_ : new () => any + + private readonly store = new this.Map_(); +>store : any +>new this.Map_() : any +>this.Map_ : new () => any +>this : this +>Map_ : new () => any +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts index 537f7b7f3a7c3..d99a8a4b7cc4d 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberInitialization.ts @@ -8,7 +8,7 @@ var c2 = new C(); var r = c.x === c2.x; // #31792 -export class MyMap { - constructor(private readonly Map_: typeof Map = Map) {} +class MyMap { + constructor(private readonly Map_: { new(): any }) {} private readonly store = new this.Map_(); }