tweak beautify output (#5044)

This commit is contained in:
Alex Lam S.L
2021-07-03 16:10:39 +01:00
committed by GitHub
parent 1b745494ce
commit 668f96623c
2 changed files with 9 additions and 12 deletions

View File

@@ -980,7 +980,6 @@ function OutputStream(options) {
DEFPRINT(AST_Do, function(output) { DEFPRINT(AST_Do, function(output) {
var self = this; var self = this;
output.print("do"); output.print("do");
output.space();
make_block(self.body, output); make_block(self.body, output);
output.space(); output.space();
output.print("while"); output.print("while");
@@ -997,7 +996,6 @@ function OutputStream(options) {
output.with_parens(function() { output.with_parens(function() {
self.condition.print(output); self.condition.print(output);
}); });
output.space();
force_statement(self.body, output); force_statement(self.body, output);
}); });
DEFPRINT(AST_For, function(output) { DEFPRINT(AST_For, function(output) {
@@ -1027,7 +1025,6 @@ function OutputStream(options) {
self.step.print(output); self.step.print(output);
} }
}); });
output.space();
force_statement(self.body, output); force_statement(self.body, output);
}); });
function print_for_enum(prefix, infix) { function print_for_enum(prefix, infix) {
@@ -1042,7 +1039,6 @@ function OutputStream(options) {
output.space(); output.space();
self.object.print(output); self.object.print(output);
}); });
output.space();
force_statement(self.body, output); force_statement(self.body, output);
}; };
} }
@@ -1056,7 +1052,6 @@ function OutputStream(options) {
output.with_parens(function() { output.with_parens(function() {
self.expression.print(output); self.expression.print(output);
}); });
output.space();
force_statement(self.body, output); force_statement(self.body, output);
}); });
DEFPRINT(AST_ExportDeclaration, function(output) { DEFPRINT(AST_ExportDeclaration, function(output) {
@@ -1325,16 +1320,16 @@ function OutputStream(options) {
output.with_parens(function() { output.with_parens(function() {
self.condition.print(output); self.condition.print(output);
}); });
output.space();
if (self.alternative) { if (self.alternative) {
make_then(self, output); make_then(self, output);
output.space(); output.space();
output.print("else"); output.print("else");
output.space(); if (self.alternative instanceof AST_If) {
if (self.alternative instanceof AST_If) output.space();
self.alternative.print(output); self.alternative.print(output);
else } else {
force_statement(self.alternative, output); force_statement(self.alternative, output);
}
} else { } else {
force_statement(self.body, output); force_statement(self.body, output);
} }
@@ -1836,6 +1831,7 @@ function OutputStream(options) {
} else if (stat instanceof AST_EmptyStatement) { } else if (stat instanceof AST_EmptyStatement) {
output.force_semicolon(); output.force_semicolon();
} else { } else {
output.space();
stat.print(output); stat.print(output);
} }
} }
@@ -1884,6 +1880,7 @@ function OutputStream(options) {
} }
function make_block(stmt, output) { function make_block(stmt, output) {
output.space();
if (stmt instanceof AST_EmptyStatement) { if (stmt instanceof AST_EmptyStatement) {
print_braced_empty(stmt, output); print_braced_empty(stmt, output);
} else if (stmt instanceof AST_BlockStatement) { } else if (stmt instanceof AST_BlockStatement) {

View File

@@ -795,9 +795,9 @@ issue_1656: {
beautify: true, beautify: true,
} }
input: { input: {
for(var a=0;;); for (var a=0;;);
} }
expect_exact: "for (;;) ;" expect_exact: "for (;;);"
} }
issue_1709: { issue_1709: {
@@ -1110,7 +1110,7 @@ issue_1838: {
} }
expect_exact: [ expect_exact: [
"function f() {", "function f() {",
" for (a; c; ) ;", " for (a; c; );",
"}", "}",
] ]
} }