perf(packages/codegen): reduce writes in printForOfStatement (#27594)

Perf optimization.

Combine writes when printing a `ForOfStatement`. Previous it was 2 writes (`for`, ` (`) or 3 (`for`, ` await`, ` (`). Now either is just one write.
This commit is contained in:
overlookmotel committed 2026-10-12 14:03:12 +00:00
1 parent 8d0ba201fd
commit e3780b5ab5
1 file changed
+3 -6
+3 -6
View File
@@ -744,18 +744,15 @@ function printForOfStatement(node: ESTree.ForOfStatement, state: State): void {
printIndent(state);
printSpaceBeforeIdentifier(state);
writeWithMap(state, "for", CAT_IDENT, node.start, node.end, node);
if (node.await) writeIdent(state, " await");
write(state, " (", CAT_OTHER);
const isNotAwait = node.await !== true;
writeWithMap(state, isNotAwait ? "for (" : "for await (", CAT_OTHER, node.start, node.end, node);
const { left } = node;
const leftType = left.type;
if (leftType === "VariableDeclaration") {
printVariableDeclaration(left, state, CTX_NONE);
} else {
const wrap = forOfHeadNeedsWrapping(left, leftType, node.await !== true);
const wrap = forOfHeadNeedsWrapping(left, leftType, isNotAwait);
if (wrap) write(state, "(", CAT_OTHER);
printAssignmentTarget(left, state);