implement --line-length
This commit is contained in:
parent
aa2a9fbedb
commit
8788eebd70
|
|
@ -118,6 +118,7 @@ a double dash to prevent input files being used as option arguments:
|
||||||
--keep-fargs Do not mangle/drop function arguments.
|
--keep-fargs Do not mangle/drop function arguments.
|
||||||
--keep-fnames Do not mangle/drop function names. Useful for
|
--keep-fnames Do not mangle/drop function names. Useful for
|
||||||
code relying on Function.prototype.name.
|
code relying on Function.prototype.name.
|
||||||
|
-l, --line-length <value> Maximum line length for output code.
|
||||||
--module Process input as ES module (implies --toplevel)
|
--module Process input as ES module (implies --toplevel)
|
||||||
--name-cache <file> File to hold mangled name mappings.
|
--name-cache <file> File to hold mangled name mappings.
|
||||||
--self Build UglifyJS as a library (implies --wrap UglifyJS)
|
--self Build UglifyJS as a library (implies --wrap UglifyJS)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ var short_forms = {
|
||||||
d: "define",
|
d: "define",
|
||||||
e: "enclose",
|
e: "enclose",
|
||||||
h: "help",
|
h: "help",
|
||||||
|
l: "line-length",
|
||||||
m: "mangle",
|
m: "mangle",
|
||||||
o: "output",
|
o: "output",
|
||||||
O: "output-opts",
|
O: "output-opts",
|
||||||
|
|
@ -107,6 +108,7 @@ function process_option(name, no_value) {
|
||||||
" --ie Support non-standard Internet Explorer.",
|
" --ie Support non-standard Internet Explorer.",
|
||||||
" --keep-fargs Do not mangle/drop function arguments.",
|
" --keep-fargs Do not mangle/drop function arguments.",
|
||||||
" --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
|
" --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
|
||||||
|
" -l, --line-length <value> Maximum line length for output code.",
|
||||||
" --module Process input as ES module (implies --toplevel)",
|
" --module Process input as ES module (implies --toplevel)",
|
||||||
" --name-cache <file> File to hold mangled name mappings.",
|
" --name-cache <file> File to hold mangled name mappings.",
|
||||||
" --rename Force symbol expansion.",
|
" --rename Force symbol expansion.",
|
||||||
|
|
@ -153,6 +155,9 @@ function process_option(name, no_value) {
|
||||||
case "annotations":
|
case "annotations":
|
||||||
case "ie":
|
case "ie":
|
||||||
case "ie8":
|
case "ie8":
|
||||||
|
case "line-length":
|
||||||
|
options.max_line_len = read_value(true);
|
||||||
|
break;
|
||||||
case "module":
|
case "module":
|
||||||
case "timings":
|
case "timings":
|
||||||
case "toplevel":
|
case "toplevel":
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ function minify(files, options) {
|
||||||
ie8: false,
|
ie8: false,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
keep_fnames: false,
|
keep_fnames: false,
|
||||||
|
max_line_len: undefined,
|
||||||
mangle: {},
|
mangle: {},
|
||||||
module: false,
|
module: false,
|
||||||
nameCache: null,
|
nameCache: null,
|
||||||
|
|
@ -214,6 +215,7 @@ function minify(files, options) {
|
||||||
var output = defaults(options.output, {
|
var output = defaults(options.output, {
|
||||||
ast: false,
|
ast: false,
|
||||||
code: true,
|
code: true,
|
||||||
|
max_line_len: options.max_line_len,
|
||||||
});
|
});
|
||||||
if (output.ast) result.ast = toplevel;
|
if (output.ast) result.ast = toplevel;
|
||||||
if (output.code) {
|
if (output.code) {
|
||||||
|
|
|
||||||
|
|
@ -964,4 +964,20 @@ describe("bin/uglifyjs", function() {
|
||||||
done();
|
done();
|
||||||
}).stdin.end(code);
|
}).stdin.end(code);
|
||||||
});
|
});
|
||||||
|
it("Should fail with empty --line-length", function(done) {
|
||||||
|
exec(uglifyjscmd + " -l", function(err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
assert.strictEqual(stdout, "");
|
||||||
|
assert.strictEqual(stderr, "ERROR: missing option argument for --line-length\n");
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
it("Should work with --line-length", function(done) {
|
||||||
|
exec(uglifyjscmd + " --line-length 20 test/input/reduce/label.js", function(err, stdout, stderr) {
|
||||||
|
if (err) throw err
|
||||||
|
assert.strictEqual(stdout, "UNUSED:{console.log(\n0-.1-.1-.1)}\n");
|
||||||
|
assert.strictEqual(stderr, "");
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user