From 957cf79304a041ec6506fd06bc24c0de59da2a31 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Jun 2025 21:09:09 +0000 Subject: [PATCH] Fix empty statement handling in using declaration for-of loops Co-authored-by: weswigham <2932786+weswigham@users.noreply.github.com> --- src/compiler/transformers/esnext.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 0cdb03ad253..7b5aeb3bdd1 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -317,8 +317,11 @@ export function transformESNext(context: TransformationContext): (x: SourceFile const usingVarStatement = factory.createVariableStatement(/*modifiers*/ undefined, usingVarList); // Wrap the original loop body in an additional block scope to handle shadowing - // Don't create an extra block if the original statement is empty - const isEmptyBlock = isBlock(node.statement) && node.statement.statements.length === 0; + // Don't create an extra block if the original statement is empty or contains only empty statements + const isEmptyBlock = isBlock(node.statement) && ( + node.statement.statements.length === 0 || + node.statement.statements.every(stmt => stmt.kind === SyntaxKind.EmptyStatement) + ); const shouldWrapInBlock = !isEmptyBlock; const statements: Statement[] = [usingVarStatement];