From f4e2fb9864a8c5dd6fb24870c4c09761b5914f75 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 19 Nov 2017 19:29:51 +0800 Subject: expand symbol space to improve compression (#2460) - give globally distinct names to distinct variables - improve ability to compress cross-scoped - introduce `options.rename` to `minify()` - default `true` if both `compress` & `mangle` --- lib/minify.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/minify.js') diff --git a/lib/minify.js b/lib/minify.js index f9d726bf..806c3aeb 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -55,6 +55,7 @@ function minify(files, options) { nameCache: null, output: {}, parse: {}, + rename: undefined, sourceMap: false, timings: false, toplevel: false, @@ -64,6 +65,9 @@ function minify(files, options) { var timings = options.timings && { start: Date.now() }; + if (options.rename === undefined) { + options.rename = options.compress && options.mangle; + } set_shorthand("ie8", options, [ "compress", "mangle", "output" ]); set_shorthand("keep_fnames", options, [ "compress", "mangle" ]); set_shorthand("toplevel", options, [ "compress", "mangle" ]); @@ -137,6 +141,11 @@ function minify(files, options) { if (options.wrap) { toplevel = toplevel.wrap_commonjs(options.wrap); } + if (timings) timings.rename = Date.now(); + if (options.rename) { + toplevel.figure_out_scope(options.mangle); + toplevel.expand_names(options.mangle); + } if (timings) timings.compress = Date.now(); if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel); if (timings) timings.scope = Date.now(); @@ -197,7 +206,8 @@ function minify(files, options) { if (timings) { timings.end = Date.now(); result.timings = { - parse: 1e-3 * (timings.compress - timings.parse), + parse: 1e-3 * (timings.rename - timings.parse), + rename: 1e-3 * (timings.compress - timings.rename), compress: 1e-3 * (timings.scope - timings.compress), scope: 1e-3 * (timings.mangle - timings.scope), mangle: 1e-3 * (timings.properties - timings.mangle), -- cgit v1.2.3