Skip to content

Fixes broken emit with useDefineForClassFields + private field #35898

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

Merged
merged 2 commits into from
Jan 9, 2020
Merged
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
3 changes: 2 additions & 1 deletion src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,9 @@ namespace ts {
return undefined;
}

const propertyOriginalNode = getOriginalNode(property);
const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression)
: hasModifier(getOriginalNode(property), ModifierFlags.ParameterPropertyModifier) && isIdentifier(propertyName) ? propertyName
: isParameterPropertyDeclaration(propertyOriginalNode, propertyOriginalNode.parent) && isIdentifier(propertyName) ? propertyName
: createVoidZero();

if (emitAssignment || isPrivateIdentifier(propertyName)) {
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/defineProperty(target=es5).js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var x: "p" = "p"
class A {
a = this.y
b
public c;
["computed"] = 13
;[x] = 14
m() { }
Expand All @@ -11,8 +12,10 @@ class A {
declare notEmitted;
}
class B {
public a;
}
class C extends B {
declare public a;
z = this.ka
constructor(public ka: number) {
super()
Expand Down Expand Up @@ -57,6 +60,12 @@ var A = /** @class */ (function () {
writable: true,
value: void 0
});
Object.defineProperty(this, "c", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "computed", {
enumerable: true,
configurable: true,
Expand Down Expand Up @@ -87,6 +96,12 @@ var A = /** @class */ (function () {
_a = x;
var B = /** @class */ (function () {
function B() {
Object.defineProperty(this, "a", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
return B;
}());
Expand Down
57 changes: 33 additions & 24 deletions tests/baselines/reference/defineProperty(target=es5).symbols
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,68 @@ class A {

a = this.y
>a : Symbol(A.a, Decl(defineProperty.ts, 1, 9))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))

b
>b : Symbol(A.b, Decl(defineProperty.ts, 2, 14))

public c;
>c : Symbol(A.c, Decl(defineProperty.ts, 3, 5))

["computed"] = 13
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))

;[x] = 14
>[x] : Symbol(A[x], Decl(defineProperty.ts, 5, 5))
>[x] : Symbol(A[x], Decl(defineProperty.ts, 6, 5))
>x : Symbol(x, Decl(defineProperty.ts, 0, 3))

m() { }
>m : Symbol(A.m, Decl(defineProperty.ts, 5, 13))
>m : Symbol(A.m, Decl(defineProperty.ts, 6, 13))

constructor(public readonly y: number) { }
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))

z = this.y
>z : Symbol(A.z, Decl(defineProperty.ts, 7, 46))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>z : Symbol(A.z, Decl(defineProperty.ts, 8, 46))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))

declare notEmitted;
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 8, 14))
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 9, 14))
}
class B {
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))

public a;
>a : Symbol(B.a, Decl(defineProperty.ts, 12, 9))
}
class C extends B {
>C : Symbol(C, Decl(defineProperty.ts, 12, 1))
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
>C : Symbol(C, Decl(defineProperty.ts, 14, 1))
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))

declare public a;
>a : Symbol(C.a, Decl(defineProperty.ts, 15, 19))

z = this.ka
>z : Symbol(C.z, Decl(defineProperty.ts, 13, 19))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>z : Symbol(C.z, Decl(defineProperty.ts, 16, 21))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))

constructor(public ka: number) {
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))

super()
>super : Symbol(B, Decl(defineProperty.ts, 10, 1))
>super : Symbol(B, Decl(defineProperty.ts, 11, 1))
}
ki = this.ka
>ki : Symbol(C.ki, Decl(defineProperty.ts, 17, 5))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>ki : Symbol(C.ki, Decl(defineProperty.ts, 20, 5))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
}

9 changes: 9 additions & 0 deletions tests/baselines/reference/defineProperty(target=es5).types
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class A {
b
>b : any

public c;
>c : any

["computed"] = 13
>["computed"] : number
>"computed" : "computed"
Expand Down Expand Up @@ -42,11 +45,17 @@ class A {
}
class B {
>B : B

public a;
>a : any
}
class C extends B {
>C : C
>B : B

declare public a;
>a : any

z = this.ka
>z : number
>this.ka : number
Expand Down
5 changes: 5 additions & 0 deletions tests/baselines/reference/defineProperty(target=esnext).js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var x: "p" = "p"
class A {
a = this.y
b
public c;
["computed"] = 13
;[x] = 14
m() { }
Expand All @@ -11,8 +12,10 @@ class A {
declare notEmitted;
}
class B {
public a;
}
class C extends B {
declare public a;
z = this.ka
constructor(public ka: number) {
super()
Expand All @@ -27,6 +30,7 @@ class A {
y;
a = this.y;
b;
c;
["computed"] = 13;
[x] = 14;
m() { }
Expand All @@ -36,6 +40,7 @@ class A {
z = this.y;
}
class B {
a;
}
class C extends B {
ka;
Expand Down
57 changes: 33 additions & 24 deletions tests/baselines/reference/defineProperty(target=esnext).symbols
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,68 @@ class A {

a = this.y
>a : Symbol(A.a, Decl(defineProperty.ts, 1, 9))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))

b
>b : Symbol(A.b, Decl(defineProperty.ts, 2, 14))

public c;
>c : Symbol(A.c, Decl(defineProperty.ts, 3, 5))

["computed"] = 13
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))

;[x] = 14
>[x] : Symbol(A[x], Decl(defineProperty.ts, 5, 5))
>[x] : Symbol(A[x], Decl(defineProperty.ts, 6, 5))
>x : Symbol(x, Decl(defineProperty.ts, 0, 3))

m() { }
>m : Symbol(A.m, Decl(defineProperty.ts, 5, 13))
>m : Symbol(A.m, Decl(defineProperty.ts, 6, 13))

constructor(public readonly y: number) { }
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))

z = this.y
>z : Symbol(A.z, Decl(defineProperty.ts, 7, 46))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>z : Symbol(A.z, Decl(defineProperty.ts, 8, 46))
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))

declare notEmitted;
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 8, 14))
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 9, 14))
}
class B {
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))

public a;
>a : Symbol(B.a, Decl(defineProperty.ts, 12, 9))
}
class C extends B {
>C : Symbol(C, Decl(defineProperty.ts, 12, 1))
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
>C : Symbol(C, Decl(defineProperty.ts, 14, 1))
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))

declare public a;
>a : Symbol(C.a, Decl(defineProperty.ts, 15, 19))

z = this.ka
>z : Symbol(C.z, Decl(defineProperty.ts, 13, 19))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>z : Symbol(C.z, Decl(defineProperty.ts, 16, 21))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))

constructor(public ka: number) {
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))

super()
>super : Symbol(B, Decl(defineProperty.ts, 10, 1))
>super : Symbol(B, Decl(defineProperty.ts, 11, 1))
}
ki = this.ka
>ki : Symbol(C.ki, Decl(defineProperty.ts, 17, 5))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
>ki : Symbol(C.ki, Decl(defineProperty.ts, 20, 5))
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
}

9 changes: 9 additions & 0 deletions tests/baselines/reference/defineProperty(target=esnext).types
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class A {
b
>b : any

public c;
>c : any

["computed"] = 13
>["computed"] : number
>"computed" : "computed"
Expand Down Expand Up @@ -42,11 +45,17 @@ class A {
}
class B {
>B : B

public a;
>a : any
}
class C extends B {
>C : C
>B : B

declare public a;
>a : any

z = this.ka
>z : number
>this.ka : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var x: "p" = "p"
class A {
a = this.y
b
public c;
["computed"] = 13
;[x] = 14
m() { }
Expand All @@ -12,8 +13,10 @@ class A {
declare notEmitted;
}
class B {
public a;
}
class C extends B {
declare public a;
z = this.ka
constructor(public ka: number) {
super()
Expand Down