Cherry-pick PR #44186 into release-4.3 (#44188)

Component commits:
acdaf368c6 Move class name capture for private state until after declaration evaluates

Co-authored-by: Ron Buckton <rbuckton@microsoft.com>
This commit is contained in:
TypeScript Bot
2021-05-20 15:07:31 -07:00
committed by GitHub
parent dec8261174
commit fed2315062
4 changed files with 92 additions and 2 deletions

View File

@@ -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);
@@ -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)));