Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type annotations originating in property initializers being emitted in constructor #31805

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ namespace ts {
);

const parameters = transformConstructorParameters(constructor);
const body = transformConstructorBody(node.members, constructor, parametersWithPropertyAssignments);
const body = transformConstructorBody(existingMembers, constructor, parametersWithPropertyAssignments);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: node.members are the original, untransformed members; existingMembers have been transformed through visitTypeScript.

members.push(startOnNewLine(
setOriginalNode(
setTextRange(
Expand Down
17 changes: 16 additions & 1 deletion tests/baselines/reference/instanceMemberInitialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, V> {
constructor(private readonly Map_: { new<K, V>(): any }) {}
private readonly store = new this.Map_<K, V>();
}


//// [instanceMemberInitialization.js]
var C = /** @class */ (function () {
Expand All @@ -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;
}());
20 changes: 20 additions & 0 deletions tests/baselines/reference/instanceMemberInitialization.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, V> {
>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<K, V>(): 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_<K, V>();
>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))
}

15 changes: 15 additions & 0 deletions tests/baselines/reference/instanceMemberInitialization.types
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ var r = c.x === c2.x;
>c2 : C
>x : number

// #31792
class MyMap<K, V> {
>MyMap : MyMap<K, V>

constructor(private readonly Map_: { new<K, V>(): any }) {}
>Map_ : new <K, V>() => any

private readonly store = new this.Map_<K, V>();
>store : any
>new this.Map_<K, V>() : any
>this.Map_ : new <K, V>() => any
>this : this
>Map_ : new <K, V>() => any
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ 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<K, V> {
constructor(private readonly Map_: { new<K, V>(): any }) {}
private readonly store = new this.Map_<K, V>();
}