Skip to content

Commit 957cf79

Browse files
Copilotweswigham
andcommitted
Fix empty statement handling in using declaration for-of loops
Co-authored-by: weswigham <2932786+weswigham@users.noreply.github.com>
1 parent 0b3bf33 commit 957cf79

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/compiler/transformers/esnext.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ export function transformESNext(context: TransformationContext): (x: SourceFile
317317
const usingVarStatement = factory.createVariableStatement(/*modifiers*/ undefined, usingVarList);
318318

319319
// Wrap the original loop body in an additional block scope to handle shadowing
320-
// Don't create an extra block if the original statement is empty
321-
const isEmptyBlock = isBlock(node.statement) && node.statement.statements.length === 0;
320+
// Don't create an extra block if the original statement is empty or contains only empty statements
321+
const isEmptyBlock = isBlock(node.statement) && (
322+
node.statement.statements.length === 0 ||
323+
node.statement.statements.every(stmt => stmt.kind === SyntaxKind.EmptyStatement)
324+
);
322325
const shouldWrapInBlock = !isEmptyBlock;
323326

324327
const statements: Statement[] = [usingVarStatement];

0 commit comments

Comments
 (0)