mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Fix class emit in converted loop body (#36795)
This commit is contained in:
@@ -2002,10 +2002,16 @@ namespace ts {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
function isVariableStatementOfTypeScriptClassWrapper(node: VariableStatement) {
|
||||
return node.declarationList.declarations.length === 1
|
||||
&& !!node.declarationList.declarations[0].initializer
|
||||
&& !!(getEmitFlags(node.declarationList.declarations[0].initializer) & EmitFlags.TypeScriptClassWrapper);
|
||||
}
|
||||
|
||||
function visitVariableStatement(node: VariableStatement): Statement | undefined {
|
||||
const ancestorFacts = enterSubtree(HierarchyFacts.None, hasModifier(node, ModifierFlags.Export) ? HierarchyFacts.ExportedVariableStatement : HierarchyFacts.None);
|
||||
let updated: Statement | undefined;
|
||||
if (convertedLoopState && (node.declarationList.flags & NodeFlags.BlockScoped) === 0) {
|
||||
if (convertedLoopState && (node.declarationList.flags & NodeFlags.BlockScoped) === 0 && !isVariableStatementOfTypeScriptClassWrapper(node)) {
|
||||
// we are inside a converted loop - hoist variable declarations
|
||||
let assignments: Expression[] | undefined;
|
||||
for (const decl of node.declarationList.declarations) {
|
||||
@@ -3606,7 +3612,13 @@ namespace ts {
|
||||
// The class statements are the statements generated by visiting the first statement with initializer of the
|
||||
// body (1), while all other statements are added to remainingStatements (2)
|
||||
const isVariableStatementWithInitializer = (stmt: Statement) => isVariableStatement(stmt) && !!first(stmt.declarationList.declarations).initializer;
|
||||
|
||||
// visit the class body statements outside of any converted loop body.
|
||||
const savedConvertedLoopState = convertedLoopState;
|
||||
convertedLoopState = undefined;
|
||||
const bodyStatements = visitNodes(body.statements, visitor, isStatement);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
|
||||
const classStatements = filter(bodyStatements, isVariableStatementWithInitializer);
|
||||
const remainingStatements = filter(bodyStatements, stmt => !isVariableStatementWithInitializer(stmt));
|
||||
const varStatement = cast(first(classStatements), isVariableStatement);
|
||||
|
||||
Reference in New Issue
Block a user