diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-01-08 20:44:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-08 20:44:03 +0800 |
commit | 5d258259a492d1e04c952024d3d5662c65bb0ce6 (patch) | |
tree | 93bcf4fc17af21cef2ed4ec333a3e19444b4e5eb | |
parent | 14c35739ddb1c0b181d8c54566171f217014b563 (diff) | |
download | tracifyjs-5d258259a492d1e04c952024d3d5662c65bb0ce6.tar.gz tracifyjs-5d258259a492d1e04c952024d3d5662c65bb0ce6.zip |
introduce `--output-opts` CLI option (#3678)
closes #3675
-rw-r--r-- | README.md | 1 | ||||
-rwxr-xr-x | bin/uglifyjs | 5 | ||||
-rw-r--r-- | test/input/issue-1482/beautify.js | 17 | ||||
-rw-r--r-- | test/input/issue-1482/default.js | 18 | ||||
-rw-r--r-- | test/mocha/cli.js | 18 |
5 files changed, 41 insertions, 18 deletions
@@ -87,6 +87,7 @@ a double dash to prevent input files being used as option arguments: `wrap_iife` Wrap IIFEs in parenthesis. Note: you may want to disable `negate_iife` under compressor options. + -O, --output-opts [options] Specify output options (`beautify` disabled by default). -o, --output <file> Output file path (default STDOUT). Specify `ast` or `spidermonkey` to write UglifyJS or SpiderMonkey AST as JSON to STDOUT respectively. diff --git a/bin/uglifyjs b/bin/uglifyjs index dc9baf81..4528b877 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -36,6 +36,7 @@ program.option("-c, --compress [options]", "Enable compressor/specify compressor program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js()); program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js()); program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js()); +program.option("-O, --output-opts [options]", "Output options (beautify disabled).", parse_js()); program.option("-o, --output <file>", "Output file (default STDOUT)."); program.option("--comments [filter]", "Preserve copyright comments in the output."); program.option("--config-file <file>", "Read minify() options from JSON file."); @@ -93,6 +94,10 @@ if (program.beautify) { options.output.beautify = true; } } +if (program.outputOpts) { + if (program.beautify) fatal("--beautify cannot be used with --output-opts"); + options.output = typeof program.outputOpts == "object" ? program.outputOpts : {}; +} if (program.comments) { if (typeof options.output != "object") options.output = {}; options.output.comments = typeof program.comments == "string" ? program.comments : "some"; diff --git a/test/input/issue-1482/beautify.js b/test/input/issue-1482/beautify.js new file mode 100644 index 00000000..14054e98 --- /dev/null +++ b/test/input/issue-1482/beautify.js @@ -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(); +} diff --git a/test/input/issue-1482/default.js b/test/input/issue-1482/default.js index 14054e98..505b30cc 100644 --- a/test/input/issue-1482/default.js +++ b/test/input/issue-1482/default.js @@ -1,17 +1 @@ -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(); -} +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()} diff --git a/test/mocha/cli.js b/test/mocha/cli.js index dd181769..be7e9d23 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -176,7 +176,7 @@ describe("bin/uglifyjs", function() { var command = uglifyjscmd + ' test/input/issue-1482/input.js -b'; exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, read("test/input/issue-1482/default.js")); + assert.strictEqual(stdout, read("test/input/issue-1482/beautify.js")); done(); }); }); @@ -188,6 +188,22 @@ describe("bin/uglifyjs", function() { done(); }); }); + it("Should work with `--output-opts`", function(done) { + var command = uglifyjscmd + ' test/input/issue-1482/input.js -O'; + exec(command, function(err, stdout) { + if (err) throw err; + assert.strictEqual(stdout, read("test/input/issue-1482/default.js")); + done(); + }); + }); + it("Should fail when both --beautify & --output-opts are specified", function(done) { + var command = uglifyjscmd + " test/input/issue-520/input.js -bO"; + exec(command, function(err, stdout, stderr) { + assert.ok(err); + assert.strictEqual(stderr, "ERROR: --beautify cannot be used with --output-opts\n"); + done(); + }); + }); it("Should process inline source map", function(done) { var command = [ uglifyjscmd, |