improve --beautify bracketize
reduce whitespaces from if-else statements fixes #1482 closes #1483
This commit is contained in:
@@ -938,6 +938,9 @@ function OutputStream(options) {
|
|||||||
output.space();
|
output.space();
|
||||||
output.print("else");
|
output.print("else");
|
||||||
output.space();
|
output.space();
|
||||||
|
if (self.alternative instanceof AST_If)
|
||||||
|
self.alternative.print(output);
|
||||||
|
else
|
||||||
force_statement(self.alternative, output);
|
force_statement(self.alternative, output);
|
||||||
} else {
|
} else {
|
||||||
self._do_print_body(output);
|
self._do_print_body(output);
|
||||||
|
|||||||
73
test/input/issue-1482/bracketize.js
Normal file
73
test/input/issue-1482/bracketize.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
} else {
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
} else if (y) {
|
||||||
|
bar();
|
||||||
|
} else {
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
if (y) {
|
||||||
|
foo();
|
||||||
|
} else {
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
} else if (y) {
|
||||||
|
bar();
|
||||||
|
} else if (z) {
|
||||||
|
baz();
|
||||||
|
} else {
|
||||||
|
moo();
|
||||||
|
}
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
} else {
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
} else if (y) {
|
||||||
|
bar();
|
||||||
|
} else {
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
if (x) {
|
||||||
|
if (y) {
|
||||||
|
foo();
|
||||||
|
} else {
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
if (x) {
|
||||||
|
foo();
|
||||||
|
} else if (y) {
|
||||||
|
bar();
|
||||||
|
} else if (z) {
|
||||||
|
baz();
|
||||||
|
} else {
|
||||||
|
moo();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
test/input/issue-1482/default.js
Normal file
17
test/input/issue-1482/default.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
if (x) foo();
|
||||||
|
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
if (x) foo();
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
}
|
||||||
12
test/input/issue-1482/input.js
Normal file
12
test/input/issue-1482/input.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
if (x) foo();
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
function f() {
|
||||||
|
if (x) foo();
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var exec = require("child_process").exec;
|
var exec = require("child_process").exec;
|
||||||
|
var readFileSync = require("fs").readFileSync;
|
||||||
|
|
||||||
describe("bin/uglifyjs", function () {
|
describe("bin/uglifyjs", function () {
|
||||||
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
|
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
|
||||||
@@ -130,4 +131,24 @@ describe("bin/uglifyjs", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("Should work with `--beautify`", function (done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/issue-1482/input.js -b';
|
||||||
|
|
||||||
|
exec(command, function (err, stdout) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
assert.strictEqual(stdout, readFileSync("test/input/issue-1482/default.js", "utf8"));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should work with `--beautify bracketize`", function (done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/issue-1482/input.js -b bracketize';
|
||||||
|
|
||||||
|
exec(command, function (err, stdout) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
assert.strictEqual(stdout, readFileSync("test/input/issue-1482/bracketize.js", "utf8"));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user