diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-11-19 19:29:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-19 19:29:51 +0800 |
commit | f4e2fb9864a8c5dd6fb24870c4c09761b5914f75 (patch) | |
tree | 99c3b5be676fa17879db559319b084ce942df58f /lib/minify.js | |
parent | b80062c490178552f45fe66acfa04e6d9c3a6363 (diff) | |
download | tracifyjs-f4e2fb9864a8c5dd6fb24870c4c09761b5914f75.tar.gz tracifyjs-f4e2fb9864a8c5dd6fb24870c4c09761b5914f75.zip |
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`
Diffstat (limited to 'lib/minify.js')
-rw-r--r-- | lib/minify.js | 12 |
1 files changed, 11 insertions, 1 deletions
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), |