Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃 Pick PR #44186 (Move class name capture for private...) into release-4.3 #44188

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/compiler/transformers/classFields.ts
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
@@ -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"
});
@@ -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";
}
@@ -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";
}