mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-17 12:56:09 +00:00
fix(codegen): avoid extra indent before empty do-while bodies (#27407)
Indented empty `do…while` bodies currently print extra whitespace between `do` and `;`. Skip the empty statement's indentation in both the JavaScript and Rust printers, keeping the semicolon directly after `do`.
This commit is contained in:
1 parent
19c227d9fb
commit
f50257e4ac
4 files changed
+16
-2
No files matched your search
@@ -483,7 +483,13 @@ impl Gen for DoWhileStatement<'_> {
|
||||
p.print_block_statement(block, ctx);
|
||||
p.print_soft_space();
|
||||
}
|
||||
Statement::EmptyStatement(s) => s.print(p, ctx),
|
||||
Statement::EmptyStatement(s) => {
|
||||
p.print_comments_at(s.span.start);
|
||||
p.add_source_mapping(s.span);
|
||||
p.print_semicolon();
|
||||
p.print_soft_newline();
|
||||
p.print_indent();
|
||||
}
|
||||
_ => {
|
||||
p.print_soft_newline();
|
||||
p.indent();
|
||||
|
||||
@@ -320,7 +320,9 @@ fn for_stmt() {
|
||||
#[test]
|
||||
fn do_while_stmt() {
|
||||
test("do ; while (true)", "do;\nwhile (true);\n");
|
||||
test("function f() { do; while (test()); }", "function f() {\n\tdo;\n\twhile (test());\n}\n");
|
||||
test_minify("do ; while (true)", "do;while(true);");
|
||||
test_minify("function f() { do; while (test()); }", "function f(){do;while(test())}");
|
||||
test_minify("do break; while (true)", "do break;while(true);");
|
||||
test_minify("do continue; while (true)", "do continue;while(true);");
|
||||
test_minify("do debugger; while (true)", "do debugger;while(true);");
|
||||
|
||||
@@ -639,8 +639,8 @@ function printDoWhileStatement(node: ESTree.DoWhileStatement, state: State): voi
|
||||
printBlockStatement(body, state);
|
||||
write(state, " ", CAT_OTHER);
|
||||
} else if (body.type === "EmptyStatement") {
|
||||
printIndent(state);
|
||||
writeWithMap(state, ";\n", CAT_OTHER, body.start, body.end, body);
|
||||
printIndent(state);
|
||||
} else {
|
||||
write(state, "\n", CAT_OTHER);
|
||||
state.indentLevel++;
|
||||
|
||||
+6
@@ -11,6 +11,12 @@ do {} while (false);
|
||||
do; while (false);
|
||||
do debugger; while (false);
|
||||
|
||||
function f1() {
|
||||
do {} while (false);
|
||||
do; while (false);
|
||||
do debugger; while (false);
|
||||
}
|
||||
|
||||
switch (value) {}
|
||||
switch (value) {
|
||||
case true:
|
||||
|
||||
Reference in new issue
Block a user