mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-17 12:56:09 +00:00
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:
1 parent
8d0ba201fd
commit
e3780b5ab5
1 file changed
+3
-6
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user