Skip to content

Commit 7dd2a5e

Browse files
authored
Fix crash in private accessor emit (#52785)
1 parent 2f43308 commit 7dd2a5e

File tree

5 files changed

+267
-1
lines changed

5 files changed

+267
-1
lines changed

src/compiler/transformers/classFields.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,14 @@ export function transformClassFields(context: TransformationContext): (x: Source
10131013
);
10141014
}
10151015

1016-
return visitEachChild(node, visitor, context);
1016+
return factory.updatePropertyDeclaration(
1017+
node,
1018+
visitNodes(node.modifiers, modifierVisitor, isModifier),
1019+
visitNode(node.name, propertyNameVisitor, isPropertyName),
1020+
/*questionOrExclamationToken*/ undefined,
1021+
/*type*/ undefined,
1022+
visitNode(node.initializer, visitor, isExpression)
1023+
);
10171024
}
10181025

10191026
function transformPublicFieldInitializer(node: PropertyDeclaration) {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//// [tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorNoUseDefineForClassFields.ts] ////
2+
3+
//// [file1.ts]
4+
// https://github.com/microsoft/TypeScript/issues/51528
5+
class C1 {
6+
static accessor x = 0;
7+
}
8+
9+
//// [file2.ts]
10+
class C2 {
11+
static accessor #x = 0;
12+
}
13+
14+
//// [file3.ts]
15+
class C3 {
16+
static accessor #x = 0;
17+
accessor #y = 0;
18+
}
19+
20+
//// [file3.ts]
21+
class C3 {
22+
accessor x = 0;
23+
}
24+
25+
//// [file4.ts]
26+
class C4 {
27+
accessor #x = 0;
28+
}
29+
30+
//// [file5.ts]
31+
class C5 {
32+
x = 0;
33+
accessor #x = 1;
34+
}
35+
36+
//// [file6.ts]
37+
class C6 {
38+
accessor #x = 0;
39+
x = 1;
40+
}
41+
42+
43+
//// [file1.js]
44+
// https://github.com/microsoft/TypeScript/issues/51528
45+
class C1 {
46+
static accessor x = 0;
47+
}
48+
//// [file2.js]
49+
class C2 {
50+
static accessor #x = 0;
51+
}
52+
//// [file3.js]
53+
class C3 {
54+
accessor x = 0;
55+
}
56+
//// [file4.js]
57+
class C4 {
58+
accessor #x = 0;
59+
}
60+
//// [file5.js]
61+
class C5 {
62+
constructor() {
63+
this.x = 0;
64+
this.#x_accessor_storage = 1;
65+
}
66+
#x_accessor_storage;
67+
get #x() { return this.#x_accessor_storage; }
68+
set #x(value) { this.#x_accessor_storage = value; }
69+
}
70+
//// [file6.js]
71+
class C6 {
72+
constructor() {
73+
this.#x_accessor_storage = 0;
74+
this.x = 1;
75+
}
76+
#x_accessor_storage;
77+
get #x() { return this.#x_accessor_storage; }
78+
set #x(value) { this.#x_accessor_storage = value; }
79+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file1.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/51528
3+
class C1 {
4+
>C1 : Symbol(C1, Decl(file1.ts, 0, 0))
5+
6+
static accessor x = 0;
7+
>x : Symbol(C1.x, Decl(file1.ts, 1, 10))
8+
}
9+
10+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file2.ts ===
11+
class C2 {
12+
>C2 : Symbol(C2, Decl(file2.ts, 0, 0))
13+
14+
static accessor #x = 0;
15+
>#x : Symbol(C2.#x, Decl(file2.ts, 0, 10))
16+
}
17+
18+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file3.ts ===
19+
class C3 {
20+
>C3 : Symbol(C3, Decl(file3.ts, 0, 0))
21+
22+
static accessor #x = 0;
23+
>x : Symbol(C3.x, Decl(file3.ts, 0, 10))
24+
25+
accessor #y = 0;
26+
}
27+
28+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file3.ts ===
29+
class C3 {
30+
>C3 : Symbol(C3, Decl(file3.ts, 0, 0))
31+
32+
accessor x = 0;
33+
>x : Symbol(C3.x, Decl(file3.ts, 0, 10))
34+
}
35+
36+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file4.ts ===
37+
class C4 {
38+
>C4 : Symbol(C4, Decl(file4.ts, 0, 0))
39+
40+
accessor #x = 0;
41+
>#x : Symbol(C4.#x, Decl(file4.ts, 0, 10))
42+
}
43+
44+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file5.ts ===
45+
class C5 {
46+
>C5 : Symbol(C5, Decl(file5.ts, 0, 0))
47+
48+
x = 0;
49+
>x : Symbol(C5.x, Decl(file5.ts, 0, 10))
50+
51+
accessor #x = 1;
52+
>#x : Symbol(C5.#x, Decl(file5.ts, 1, 10))
53+
}
54+
55+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file6.ts ===
56+
class C6 {
57+
>C6 : Symbol(C6, Decl(file6.ts, 0, 0))
58+
59+
accessor #x = 0;
60+
>#x : Symbol(C6.#x, Decl(file6.ts, 0, 10))
61+
62+
x = 1;
63+
>x : Symbol(C6.x, Decl(file6.ts, 1, 20))
64+
}
65+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file1.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/51528
3+
class C1 {
4+
>C1 : C1
5+
6+
static accessor x = 0;
7+
>x : number
8+
>0 : 0
9+
}
10+
11+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file2.ts ===
12+
class C2 {
13+
>C2 : C2
14+
15+
static accessor #x = 0;
16+
>#x : number
17+
>0 : 0
18+
}
19+
20+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file3.ts ===
21+
class C3 {
22+
>C3 : C3
23+
24+
static accessor #x = 0;
25+
>x : number
26+
>0 : 0
27+
28+
accessor #y = 0;
29+
}
30+
31+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file3.ts ===
32+
class C3 {
33+
>C3 : C3
34+
35+
accessor x = 0;
36+
>x : number
37+
>0 : 0
38+
}
39+
40+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file4.ts ===
41+
class C4 {
42+
>C4 : C4
43+
44+
accessor #x = 0;
45+
>#x : number
46+
>0 : 0
47+
}
48+
49+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file5.ts ===
50+
class C5 {
51+
>C5 : C5
52+
53+
x = 0;
54+
>x : number
55+
>0 : 0
56+
57+
accessor #x = 1;
58+
>#x : number
59+
>1 : 1
60+
}
61+
62+
=== tests/cases/conformance/classes/propertyMemberDeclarations/file6.ts ===
63+
class C6 {
64+
>C6 : C6
65+
66+
accessor #x = 0;
67+
>#x : number
68+
>0 : 0
69+
70+
x = 1;
71+
>x : number
72+
>1 : 1
73+
}
74+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// @target: esnext
2+
// @useDefineForClassFields: false
3+
4+
// @filename: file1.ts
5+
// https://github.com/microsoft/TypeScript/issues/51528
6+
class C1 {
7+
static accessor x = 0;
8+
}
9+
10+
// @filename: file2.ts
11+
class C2 {
12+
static accessor #x = 0;
13+
}
14+
15+
// @filename: file3.ts
16+
class C3 {
17+
static accessor #x = 0;
18+
accessor #y = 0;
19+
}
20+
21+
// @filename: file3.ts
22+
class C3 {
23+
accessor x = 0;
24+
}
25+
26+
// @filename: file4.ts
27+
class C4 {
28+
accessor #x = 0;
29+
}
30+
31+
// @filename: file5.ts
32+
class C5 {
33+
x = 0;
34+
accessor #x = 1;
35+
}
36+
37+
// @filename: file6.ts
38+
class C6 {
39+
accessor #x = 0;
40+
x = 1;
41+
}

0 commit comments

Comments
 (0)