Skip to content
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
9 changes: 7 additions & 2 deletions src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,14 @@ namespace ts {
}

const staticProperties = getProperties(node, /*requireInitializer*/ false, /*isStatic*/ true);
let pendingPrivateStateAssignment: BinaryExpression | undefined;
if (shouldTransformPrivateElements && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) {
const temp = factory.createTempVariable(hoistVariableDeclaration, /* reservedInNestedScopes */ true);
getPrivateIdentifierEnvironment().classConstructor = factory.cloneNode(temp);
getPendingExpressions().push(factory.createAssignment(
pendingPrivateStateAssignment = factory.createAssignment(
temp,
factory.getInternalName(node)
));
);
}

const extendsClauseElement = getEffectiveBaseTypeNode(node);
Expand All @@ -682,6 +683,10 @@ namespace ts {
)
];

if (pendingPrivateStateAssignment) {
getPendingExpressions().unshift(pendingPrivateStateAssignment);
}

// Write any pending expressions from elided or moved computed property names
if (some(pendingExpressions)) {
statements.push(factory.createExpressionStatement(factory.inlineExpressions(pendingExpressions)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//// [privateNameComputedPropertyName4.ts]
// https://github.com/microsoft/TypeScript/issues/44113
class C1 {
static #qux = 42;
["bar"] () {}
}
class C2 {
static #qux = 42;
static ["bar"] () {}
}
class C3 {
static #qux = 42;
static ["bar"] = "test";
}


//// [privateNameComputedPropertyName4.js]
var _a, _C1_qux, _b, _C2_qux, _c, _C3_qux;
// https://github.com/microsoft/TypeScript/issues/44113
class C1 {
["bar"]() { }
}
_a = C1;
_C1_qux = { value: 42 };
class C2 {
static ["bar"]() { }
}
_b = C2;
_C2_qux = { value: 42 };
class C3 {
}
_c = C3;
_C3_qux = { value: 42 };
Object.defineProperty(C3, "bar", {
enumerable: true,
configurable: true,
writable: true,
value: "test"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// [privateNameComputedPropertyName4.ts]
// https://github.com/microsoft/TypeScript/issues/44113
class C1 {
static #qux = 42;
["bar"] () {}
}
class C2 {
static #qux = 42;
static ["bar"] () {}
}
class C3 {
static #qux = 42;
static ["bar"] = "test";
}


//// [privateNameComputedPropertyName4.js]
// https://github.com/microsoft/TypeScript/issues/44113
class C1 {
static #qux = 42;
["bar"]() { }
}
class C2 {
static #qux = 42;
static ["bar"]() { }
}
class C3 {
static #qux = 42;
static ["bar"] = "test";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @target: esnext, es2015
// @useDefineForClassFields: true
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/44113
class C1 {
static #qux = 42;
["bar"] () {}
}
class C2 {
static #qux = 42;
static ["bar"] () {}
}
class C3 {
static #qux = 42;
static ["bar"] = "test";
}