Merge a01b55a782 into 95cfce68ea
This commit is contained in:
commit
772b56c524
|
|
@ -613,6 +613,10 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||
|
||||
- `dead_code` (default: `true`) -- remove unreachable code
|
||||
|
||||
- `defaults` (default: `true`) -- Pass `false` to disable most default
|
||||
enabled `compress` transforms. Useful when you only want to enable a few
|
||||
`compress` options while disabling the rest.
|
||||
|
||||
- `drop_console` (default: `false`) -- Pass `true` to discard calls to
|
||||
`console.*` functions. If you wish to drop a specific function call
|
||||
such as `console.info` and/or retain side effects from function arguments
|
||||
|
|
|
|||
|
|
@ -47,12 +47,14 @@ function Compressor(options, false_by_default) {
|
|||
if (!(this instanceof Compressor))
|
||||
return new Compressor(options, false_by_default);
|
||||
TreeTransformer.call(this, this.before, this.after);
|
||||
if (options.defaults !== undefined && !options.defaults) false_by_default = true;
|
||||
this.options = defaults(options, {
|
||||
booleans : !false_by_default,
|
||||
collapse_vars : !false_by_default,
|
||||
comparisons : !false_by_default,
|
||||
conditionals : !false_by_default,
|
||||
dead_code : !false_by_default,
|
||||
defaults : true,
|
||||
drop_console : false,
|
||||
drop_debugger : !false_by_default,
|
||||
evaluate : !false_by_default,
|
||||
|
|
|
|||
96
test/compress/defaults.js
Normal file
96
test/compress/defaults.js
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
defaults_undefined: {
|
||||
options = {
|
||||
defaults: undefined,
|
||||
}
|
||||
input: {
|
||||
if (true) {
|
||||
console.log(1 + 2);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
if (true)
|
||||
console.log(1 + 2);
|
||||
}
|
||||
expect_stdout: "3"
|
||||
}
|
||||
|
||||
defaults_false: {
|
||||
options = {
|
||||
defaults: false,
|
||||
}
|
||||
input: {
|
||||
if (true) {
|
||||
console.log(1 + 2);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
if (true)
|
||||
console.log(1 + 2);
|
||||
}
|
||||
expect_stdout: "3"
|
||||
}
|
||||
|
||||
defaults_false_evaluate_true: {
|
||||
options = {
|
||||
defaults: false,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
if (true) {
|
||||
console.log(1 + 2);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
if (true)
|
||||
console.log(3);
|
||||
}
|
||||
expect_stdout: "3"
|
||||
}
|
||||
|
||||
defaults_true: {
|
||||
options = {
|
||||
defaults: true,
|
||||
}
|
||||
input: {
|
||||
if (true) {
|
||||
console.log(1 + 2);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
console.log(3);
|
||||
}
|
||||
expect_stdout: "3"
|
||||
}
|
||||
|
||||
defaults_true_conditionals_false: {
|
||||
options = {
|
||||
defaults: true,
|
||||
conditionals: false,
|
||||
}
|
||||
input: {
|
||||
if (true) {
|
||||
console.log(1 + 2);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
if (1)
|
||||
console.log(3);
|
||||
}
|
||||
expect_stdout: "3"
|
||||
}
|
||||
|
||||
defaults_true_evaluate_false: {
|
||||
options = {
|
||||
defaults: true,
|
||||
evaluate: false,
|
||||
}
|
||||
input: {
|
||||
if (true) {
|
||||
console.log(1 + 2);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
1 && console.log(1 + 2);
|
||||
}
|
||||
expect_stdout: "3"
|
||||
}
|
||||
3
test/input/defaults/input.js
Normal file
3
test/input/defaults/input.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if (true) {
|
||||
console.log(1 + 2);
|
||||
}
|
||||
|
|
@ -682,4 +682,12 @@ describe("bin/uglifyjs", function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
it("Should work with -c defaults=false,conditionals", function(done) {
|
||||
var command = uglifyjscmd + " test/input/defaults/input.js -c defaults=false,conditionals";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, 'true&&console.log(1+2);\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -387,4 +387,25 @@ describe("minify", function() {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should work with compress defaults disabled", function() {
|
||||
var code = 'if (true) { console.log(1 + 2); }';
|
||||
var options = {
|
||||
compress: {
|
||||
defaults: false,
|
||||
}
|
||||
};
|
||||
assert.strictEqual(Uglify.minify(code, options).code, 'if(true)console.log(1+2);');
|
||||
});
|
||||
|
||||
it("should work with compress defaults disabled and evaluate enabled", function() {
|
||||
var code = 'if (true) { console.log(1 + 2); }';
|
||||
var options = {
|
||||
compress: {
|
||||
defaults: false,
|
||||
evaluate: true,
|
||||
}
|
||||
};
|
||||
assert.strictEqual(Uglify.minify(code, options).code, 'if(true)console.log(3);');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ function run_compress_tests() {
|
|||
input.figure_out_scope(test.mangle);
|
||||
input.expand_names(test.mangle);
|
||||
}
|
||||
var cmp = new U.Compressor(options, true);
|
||||
var cmp = new U.Compressor(options, options.defaults === undefined ? true : !options.defaults);
|
||||
var output = cmp.compress(input);
|
||||
output.figure_out_scope(test.mangle);
|
||||
if (test.mangle) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user