Fixes broken emit with useDefineForClassFields + private field (#35898)

* Fixes broken emit with useDefineForClassFields + private field

* use simpler function for condition
This commit is contained in:
M.Yoshimura 2020-01-10 03:21:49 +09:00 committed by Nathan Shively-Sanders
parent 66b5c47854
commit 5fc917be2e
8 changed files with 109 additions and 49 deletions

View File

@ -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)) {

View File

@ -3,6 +3,7 @@ var x: "p" = "p"
class A {
a = this.y
b
public c;
["computed"] = 13
;[x] = 14
m() { }
@ -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()
@ -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,
@ -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;
}());

View File

@ -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))
}

View File

@ -15,6 +15,9 @@ class A {
b
>b : any
public c;
>c : any
["computed"] = 13
>["computed"] : number
>"computed" : "computed"
@ -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

View File

@ -3,6 +3,7 @@ var x: "p" = "p"
class A {
a = this.y
b
public c;
["computed"] = 13
;[x] = 14
m() { }
@ -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()
@ -27,6 +30,7 @@ class A {
y;
a = this.y;
b;
c;
["computed"] = 13;
[x] = 14;
m() { }
@ -36,6 +40,7 @@ class A {
z = this.y;
}
class B {
a;
}
class C extends B {
ka;

View File

@ -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))
}

View File

@ -15,6 +15,9 @@ class A {
b
>b : any
public c;
>c : any
["computed"] = 13
>["computed"] : number
>"computed" : "computed"
@ -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

View File

@ -4,6 +4,7 @@ var x: "p" = "p"
class A {
a = this.y
b
public c;
["computed"] = 13
;[x] = 14
m() { }
@ -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()