Skip to content

Commit 680c83d

Browse files
committed
fix(37791): fix incorrect private field access in a computed property name
1 parent e789cb1 commit 680c83d

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

src/compiler/transformers/classFields.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ namespace ts {
9090
return visitPropertyDeclaration(node as PropertyDeclaration);
9191
case SyntaxKind.VariableStatement:
9292
return visitVariableStatement(node as VariableStatement);
93-
case SyntaxKind.ComputedPropertyName:
94-
return visitComputedPropertyName(node as ComputedPropertyName);
9593
case SyntaxKind.PropertyAccessExpression:
9694
return visitPropertyAccessExpression(node as PropertyAccessExpression);
9795
case SyntaxKind.PrefixUnaryExpression:
@@ -184,7 +182,7 @@ namespace ts {
184182
let node = visitEachChild(name, visitor, context);
185183
if (some(pendingExpressions)) {
186184
const expressions = pendingExpressions;
187-
expressions.push(name.expression);
185+
expressions.push(node.expression);
188186
pendingExpressions = [];
189187
node = factory.updateComputedPropertyName(
190188
node,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @target: esnext, es2015
2+
3+
class A {
4+
#a = 'a';
5+
#b: string;
6+
7+
readonly #c = 'c';
8+
readonly #d: string;
9+
10+
#e = '';
11+
12+
constructor() {
13+
this.#b = 'b';
14+
this.#d = 'd';
15+
}
16+
17+
test() {
18+
const data: Record<string, string> = { a: 'a', b: 'b', c: 'c', d: 'd', e: 'e' };
19+
const {
20+
[this.#a]: a,
21+
[this.#b]: b,
22+
[this.#c]: c,
23+
[this.#d]: d,
24+
[this.#e = 'e']: e,
25+
} = data;
26+
console.log(a, b, c, d, e);
27+
28+
const a1 = data[this.#a];
29+
const b1 = data[this.#b];
30+
const c1 = data[this.#c];
31+
const d1 = data[this.#d];
32+
const e1 = data[this.#e];
33+
console.log(a1, b1, c1, d1);
34+
}
35+
}
36+
37+
new A().test();
38+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @target: esnext, es2015
2+
3+
let getX: (a: A) => number;
4+
5+
class A {
6+
#x = 100;
7+
8+
[(getX = (a: A) => a.#x, "_")]() {}
9+
}
10+
11+
console.log(getX(new A));
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @target: esnext, es2015
2+
3+
class Foo {
4+
#name;
5+
6+
constructor(name) {
7+
this.#name = name;
8+
}
9+
10+
getValue(x) {
11+
const obj = this;
12+
13+
class Bar {
14+
#y = 100;
15+
16+
[obj.#name]() {
17+
return x + this.#y;
18+
}
19+
}
20+
21+
return new Bar()[obj.#name]();
22+
}
23+
}
24+
25+
console.log(new Foo("NAME").getValue(100));

0 commit comments

Comments
 (0)