Skip to content

Commit

Permalink
Updates UglifyJs to 2.8.x to accept additional compress options
Browse files Browse the repository at this point in the history
Bumps the minimum version of UglifyJs and substitutes `.compress()` for
`.transform()` as recommended. In addition to a new test covering
`compress` options this commit also contains updates to make existing
tests pass with the update.
  • Loading branch information
ornj committed Mar 5, 2017
1 parent d0908fe commit 87702a2
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 147 deletions.
1 change: 1 addition & 0 deletions input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid javascript
2 changes: 1 addition & 1 deletion lib/optimize/UglifyJsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class UglifyJsPlugin {
const compress = uglify.Compressor(options.compress || {
warnings: false
}); // eslint-disable-line new-cap
ast = ast.transform(compress);
ast = compress.compress(ast);
}
if(options.mangle !== false) {
ast.figure_out_scope(options.mangle || {});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"source-map": "^0.5.3",
"supports-color": "^3.1.0",
"tapable": "~0.2.5",
"uglify-js": "^2.7.5",
"uglify-js": "^2.8.5",
"watchpack": "^1.2.0",
"webpack-sources": "^0.1.4",
"yargs": "^6.0.0"
Expand Down
2 changes: 1 addition & 1 deletion test/UglifyJsPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("UglifyJsPlugin", function() {
}], function() {
compilation.errors.length.should.be.exactly(1);
compilation.errors[0].should.be.an.Error;
compilation.errors[0].message.should.have.containEql("SyntaxError");
compilation.errors[0].message.should.have.containEql("Unexpected token");
compilation.errors[0].message.should.have.containEql("[test2.js:1,8]");
});
});
Expand Down
14 changes: 14 additions & 0 deletions test/configCases/plugins/uglifyjs-plugin/compress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function f() {
var a = 1, b = 2, c = 3;
if (a) {
b = c;
} else {
c = b;
}
console.log(a + b);
console.log(b + c);
console.log(a + c);
console.log(a + b + c);
}

module.exports = f;
7 changes: 7 additions & 0 deletions test/configCases/plugins/uglifyjs-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ it("should remove extracted comments and insert a banner", function() {
source.should.containEql("/*! For license information please see extract.js.LICENSE */");
});

it("should pass compress options", function() {
var fs = require("fs"),
path = require("path");
var source = fs.readFileSync(path.join(__dirname, "compress.js"), "utf-8");
source.should.containEql("function e(){var n=2;n=3,console.log(1+n),console.log(n+3),console.log(4),console.log(1+n+3)}");
});

require.include("./test.js");
13 changes: 12 additions & 1 deletion test/configCases/plugins/uglifyjs-plugin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
bundle0: ["./index.js"],
vendors: ["./vendors.js"],
ie8: ["./ie8.js"],
extract: ["./extract.js"]
extract: ["./extract.js"],
compress: ["./compress.js"]
},
output: {
filename: "[name].js"
Expand All @@ -28,5 +29,15 @@ module.exports = {
screw_ie8: false
}
}),
new webpack.optimize.UglifyJsPlugin({
include: ["compress.js"],
compress: {
conditionals: true,
evaluate: true,
passes: 2,
reduce_vars: true,
unused: true
}
}),
]
};
4 changes: 2 additions & 2 deletions test/statsCases/warnings-uglifyjs/expected.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hash: 4beee256fa6b8f69eae8
Time: Xms
Asset Size Chunks Chunk Names
bundle.js 2.3 kB 0 [emitted] main
Asset Size Chunks Chunk Names
bundle.js 2.24 kB 0 [emitted] main
chunk {0} bundle.js (main) 1.04 kB [entry] [rendered]
[0] (webpack)/buildin/module.js 495 bytes {0} [built]
[1] (webpack)/test/statsCases/warnings-uglifyjs/a.js 249 bytes {0} [built]
Expand Down
Loading

0 comments on commit 87702a2

Please sign in to comment.