Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 58dfe43

Browse files
committedJul 5, 2022
implement --line-length
1 parent aa2a9fb commit 58dfe43

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ a double dash to prevent input files being used as option arguments:
118118
--keep-fargs Do not mangle/drop function arguments.
119119
--keep-fnames Do not mangle/drop function names. Useful for
120120
code relying on Function.prototype.name.
121+
-l, --line-length <value> Maximum line length for output code.
121122
--module Process input as ES module (implies --toplevel)
122123
--name-cache <file> File to hold mangled name mappings.
123124
--self Build UglifyJS as a library (implies --wrap UglifyJS)

‎bin/uglifyjs

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var short_forms = {
2121
d: "define",
2222
e: "enclose",
2323
h: "help",
24+
l: "line-length",
2425
m: "mangle",
2526
o: "output",
2627
O: "output-opts",
@@ -107,6 +108,7 @@ function process_option(name, no_value) {
107108
" --ie Support non-standard Internet Explorer.",
108109
" --keep-fargs Do not mangle/drop function arguments.",
109110
" --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
111+
" -l, --line-length <value> Maximum line length for output code.",
110112
" --module Process input as ES module (implies --toplevel)",
111113
" --name-cache <file> File to hold mangled name mappings.",
112114
" --rename Force symbol expansion.",
@@ -153,6 +155,9 @@ function process_option(name, no_value) {
153155
case "annotations":
154156
case "ie":
155157
case "ie8":
158+
case "line-length":
159+
options.max_line_len = read_value(true);
160+
break;
156161
case "module":
157162
case "timings":
158163
case "toplevel":

‎lib/minify.js

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function minify(files, options) {
8080
ie8: false,
8181
keep_fargs: false,
8282
keep_fnames: false,
83+
max_line_len: undefined,
8384
mangle: {},
8485
module: false,
8586
nameCache: null,
@@ -214,6 +215,7 @@ function minify(files, options) {
214215
var output = defaults(options.output, {
215216
ast: false,
216217
code: true,
218+
max_line_len: options.max_line_len,
217219
});
218220
if (output.ast) result.ast = toplevel;
219221
if (output.code) {

‎test/mocha/cli.js

+15
Original file line numberDiff line numberDiff line change
@@ -964,4 +964,19 @@ describe("bin/uglifyjs", function() {
964964
done();
965965
}).stdin.end(code);
966966
});
967+
it("Should fail with empty --line-length", function(done) {
968+
exec(uglifyjscmd + " -l", function(err, stdout, stderr) {
969+
assert.ok(err);
970+
assert.strictEqual(stdout, "");
971+
assert.strictEqual(stderr, "ERROR: missing option argument for --line-length\n");
972+
done();
973+
})
974+
});
975+
it("Should work with --line-length", function(done) {
976+
exec(uglifyjscmd + " --line-length 20 test/input/reduce/label.js", function(err, stdout, stderr) {
977+
assert.strictEqual(stdout, "UNUSED:{console.log(\n0-.1-.1-.1)}\n");
978+
assert.strictEqual(stderr, "");
979+
done();
980+
})
981+
});
967982
});

0 commit comments

Comments
 (0)
Please sign in to comment.