Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5fc917b

Browse filesBrowse files
hikarino-mysandersn
authored andcommitted
Fixes broken emit with useDefineForClassFields + private field (microsoft#35898)
* Fixes broken emit with useDefineForClassFields + private field * use simpler function for condition
1 parent 66b5c47 commit 5fc917b
Copy full SHA for 5fc917b

8 files changed

+109-49Lines changed: 109 additions & 49 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/transformers/classFields.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/classFields.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,9 @@ namespace ts {
777777
return undefined;
778778
}
779779

780+
const propertyOriginalNode = getOriginalNode(property);
780781
const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression)
781-
: hasModifier(getOriginalNode(property), ModifierFlags.ParameterPropertyModifier) && isIdentifier(propertyName) ? propertyName
782+
: isParameterPropertyDeclaration(propertyOriginalNode, propertyOriginalNode.parent) && isIdentifier(propertyName) ? propertyName
782783
: createVoidZero();
783784

784785
if (emitAssignment || isPrivateIdentifier(propertyName)) {
Collapse file

‎tests/baselines/reference/defineProperty(target=es5).js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/defineProperty(target=es5).js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var x: "p" = "p"
33
class A {
44
a = this.y
55
b
6+
public c;
67
["computed"] = 13
78
;[x] = 14
89
m() { }
@@ -11,8 +12,10 @@ class A {
1112
declare notEmitted;
1213
}
1314
class B {
15+
public a;
1416
}
1517
class C extends B {
18+
declare public a;
1619
z = this.ka
1720
constructor(public ka: number) {
1821
super()
@@ -57,6 +60,12 @@ var A = /** @class */ (function () {
5760
writable: true,
5861
value: void 0
5962
});
63+
Object.defineProperty(this, "c", {
64+
enumerable: true,
65+
configurable: true,
66+
writable: true,
67+
value: void 0
68+
});
6069
Object.defineProperty(this, "computed", {
6170
enumerable: true,
6271
configurable: true,
@@ -87,6 +96,12 @@ var A = /** @class */ (function () {
8796
_a = x;
8897
var B = /** @class */ (function () {
8998
function B() {
99+
Object.defineProperty(this, "a", {
100+
enumerable: true,
101+
configurable: true,
102+
writable: true,
103+
value: void 0
104+
});
90105
}
91106
return B;
92107
}());
Collapse file

‎tests/baselines/reference/defineProperty(target=es5).symbols‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/defineProperty(target=es5).symbols
+33-24Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,68 @@ class A {
77

88
a = this.y
99
>a : Symbol(A.a, Decl(defineProperty.ts, 1, 9))
10-
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
10+
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
1111
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
12-
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
12+
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
1313

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

17+
public c;
18+
>c : Symbol(A.c, Decl(defineProperty.ts, 3, 5))
19+
1720
["computed"] = 13
18-
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
19-
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
21+
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))
22+
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))
2023

2124
;[x] = 14
22-
>[x] : Symbol(A[x], Decl(defineProperty.ts, 5, 5))
25+
>[x] : Symbol(A[x], Decl(defineProperty.ts, 6, 5))
2326
>x : Symbol(x, Decl(defineProperty.ts, 0, 3))
2427

2528
m() { }
26-
>m : Symbol(A.m, Decl(defineProperty.ts, 5, 13))
29+
>m : Symbol(A.m, Decl(defineProperty.ts, 6, 13))
2730

2831
constructor(public readonly y: number) { }
29-
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
32+
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
3033

3134
z = this.y
32-
>z : Symbol(A.z, Decl(defineProperty.ts, 7, 46))
33-
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
35+
>z : Symbol(A.z, Decl(defineProperty.ts, 8, 46))
36+
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
3437
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
35-
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
38+
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
3639

3740
declare notEmitted;
38-
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 8, 14))
41+
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 9, 14))
3942
}
4043
class B {
41-
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
44+
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))
45+
46+
public a;
47+
>a : Symbol(B.a, Decl(defineProperty.ts, 12, 9))
4248
}
4349
class C extends B {
44-
>C : Symbol(C, Decl(defineProperty.ts, 12, 1))
45-
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
50+
>C : Symbol(C, Decl(defineProperty.ts, 14, 1))
51+
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))
52+
53+
declare public a;
54+
>a : Symbol(C.a, Decl(defineProperty.ts, 15, 19))
4655

4756
z = this.ka
48-
>z : Symbol(C.z, Decl(defineProperty.ts, 13, 19))
49-
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
50-
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
51-
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
57+
>z : Symbol(C.z, Decl(defineProperty.ts, 16, 21))
58+
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
59+
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
60+
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
5261

5362
constructor(public ka: number) {
54-
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
63+
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
5564

5665
super()
57-
>super : Symbol(B, Decl(defineProperty.ts, 10, 1))
66+
>super : Symbol(B, Decl(defineProperty.ts, 11, 1))
5867
}
5968
ki = this.ka
60-
>ki : Symbol(C.ki, Decl(defineProperty.ts, 17, 5))
61-
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
62-
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
63-
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
69+
>ki : Symbol(C.ki, Decl(defineProperty.ts, 20, 5))
70+
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
71+
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
72+
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
6473
}
6574

Collapse file

‎tests/baselines/reference/defineProperty(target=es5).types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/defineProperty(target=es5).types
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class A {
1515
b
1616
>b : any
1717

18+
public c;
19+
>c : any
20+
1821
["computed"] = 13
1922
>["computed"] : number
2023
>"computed" : "computed"
@@ -42,11 +45,17 @@ class A {
4245
}
4346
class B {
4447
>B : B
48+
49+
public a;
50+
>a : any
4551
}
4652
class C extends B {
4753
>C : C
4854
>B : B
4955

56+
declare public a;
57+
>a : any
58+
5059
z = this.ka
5160
>z : number
5261
>this.ka : number
Collapse file

‎tests/baselines/reference/defineProperty(target=esnext).js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/defineProperty(target=esnext).js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var x: "p" = "p"
33
class A {
44
a = this.y
55
b
6+
public c;
67
["computed"] = 13
78
;[x] = 14
89
m() { }
@@ -11,8 +12,10 @@ class A {
1112
declare notEmitted;
1213
}
1314
class B {
15+
public a;
1416
}
1517
class C extends B {
18+
declare public a;
1619
z = this.ka
1720
constructor(public ka: number) {
1821
super()
@@ -27,6 +30,7 @@ class A {
2730
y;
2831
a = this.y;
2932
b;
33+
c;
3034
["computed"] = 13;
3135
[x] = 14;
3236
m() { }
@@ -36,6 +40,7 @@ class A {
3640
z = this.y;
3741
}
3842
class B {
43+
a;
3944
}
4045
class C extends B {
4146
ka;
Collapse file

‎tests/baselines/reference/defineProperty(target=esnext).symbols‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/defineProperty(target=esnext).symbols
+33-24Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,68 @@ class A {
77

88
a = this.y
99
>a : Symbol(A.a, Decl(defineProperty.ts, 1, 9))
10-
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
10+
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
1111
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
12-
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
12+
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
1313

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

17+
public c;
18+
>c : Symbol(A.c, Decl(defineProperty.ts, 3, 5))
19+
1720
["computed"] = 13
18-
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
19-
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 3, 5))
21+
>["computed"] : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))
22+
>"computed" : Symbol(A["computed"], Decl(defineProperty.ts, 4, 13))
2023

2124
;[x] = 14
22-
>[x] : Symbol(A[x], Decl(defineProperty.ts, 5, 5))
25+
>[x] : Symbol(A[x], Decl(defineProperty.ts, 6, 5))
2326
>x : Symbol(x, Decl(defineProperty.ts, 0, 3))
2427

2528
m() { }
26-
>m : Symbol(A.m, Decl(defineProperty.ts, 5, 13))
29+
>m : Symbol(A.m, Decl(defineProperty.ts, 6, 13))
2730

2831
constructor(public readonly y: number) { }
29-
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
32+
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
3033

3134
z = this.y
32-
>z : Symbol(A.z, Decl(defineProperty.ts, 7, 46))
33-
>this.y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
35+
>z : Symbol(A.z, Decl(defineProperty.ts, 8, 46))
36+
>this.y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
3437
>this : Symbol(A, Decl(defineProperty.ts, 0, 16))
35-
>y : Symbol(A.y, Decl(defineProperty.ts, 7, 16))
38+
>y : Symbol(A.y, Decl(defineProperty.ts, 8, 16))
3639

3740
declare notEmitted;
38-
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 8, 14))
41+
>notEmitted : Symbol(A.notEmitted, Decl(defineProperty.ts, 9, 14))
3942
}
4043
class B {
41-
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
44+
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))
45+
46+
public a;
47+
>a : Symbol(B.a, Decl(defineProperty.ts, 12, 9))
4248
}
4349
class C extends B {
44-
>C : Symbol(C, Decl(defineProperty.ts, 12, 1))
45-
>B : Symbol(B, Decl(defineProperty.ts, 10, 1))
50+
>C : Symbol(C, Decl(defineProperty.ts, 14, 1))
51+
>B : Symbol(B, Decl(defineProperty.ts, 11, 1))
52+
53+
declare public a;
54+
>a : Symbol(C.a, Decl(defineProperty.ts, 15, 19))
4655

4756
z = this.ka
48-
>z : Symbol(C.z, Decl(defineProperty.ts, 13, 19))
49-
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
50-
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
51-
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
57+
>z : Symbol(C.z, Decl(defineProperty.ts, 16, 21))
58+
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
59+
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
60+
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
5261

5362
constructor(public ka: number) {
54-
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
63+
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
5564

5665
super()
57-
>super : Symbol(B, Decl(defineProperty.ts, 10, 1))
66+
>super : Symbol(B, Decl(defineProperty.ts, 11, 1))
5867
}
5968
ki = this.ka
60-
>ki : Symbol(C.ki, Decl(defineProperty.ts, 17, 5))
61-
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
62-
>this : Symbol(C, Decl(defineProperty.ts, 12, 1))
63-
>ka : Symbol(C.ka, Decl(defineProperty.ts, 15, 16))
69+
>ki : Symbol(C.ki, Decl(defineProperty.ts, 20, 5))
70+
>this.ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
71+
>this : Symbol(C, Decl(defineProperty.ts, 14, 1))
72+
>ka : Symbol(C.ka, Decl(defineProperty.ts, 18, 16))
6473
}
6574

Collapse file

‎tests/baselines/reference/defineProperty(target=esnext).types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/defineProperty(target=esnext).types
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class A {
1515
b
1616
>b : any
1717

18+
public c;
19+
>c : any
20+
1821
["computed"] = 13
1922
>["computed"] : number
2023
>"computed" : "computed"
@@ -42,11 +45,17 @@ class A {
4245
}
4346
class B {
4447
>B : B
48+
49+
public a;
50+
>a : any
4551
}
4652
class C extends B {
4753
>C : C
4854
>B : B
4955

56+
declare public a;
57+
>a : any
58+
5059
z = this.ka
5160
>z : number
5261
>this.ka : number
Collapse file

‎tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts‎

Copy file name to clipboardExpand all lines: tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var x: "p" = "p"
44
class A {
55
a = this.y
66
b
7+
public c;
78
["computed"] = 13
89
;[x] = 14
910
m() { }
@@ -12,8 +13,10 @@ class A {
1213
declare notEmitted;
1314
}
1415
class B {
16+
public a;
1517
}
1618
class C extends B {
19+
declare public a;
1720
z = this.ka
1821
constructor(public ka: number) {
1922
super()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.