aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-05 22:14:11 +0800
committerGitHub <noreply@github.com>2017-11-05 22:14:11 +0800
commit2c2fd89e343626f8d7dc83812a6476b0ab99b784 (patch)
tree6a42beb30791bb9c35c98c6643e6e45a2e6bcc79 /lib
parentf46281e2b75a0cae0fbc591ba23c000d4106a07a (diff)
downloadtracifyjs-2c2fd89e343626f8d7dc83812a6476b0ab99b784.tar.gz
tracifyjs-2c2fd89e343626f8d7dc83812a6476b0ab99b784.zip
inline single-use functions that are not constant expressions (#2434)
fixes #2428
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js20
-rw-r--r--lib/minify.js10
2 files changed, 7 insertions, 23 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 454c1666..ba7c10f4 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -150,7 +150,9 @@ merge(Compressor.prototype, {
}
var passes = +this.options.passes || 1;
var last_count = 1 / 0;
+ var mangle = { ie8: this.option("ie8") };
for (var pass = 0; pass < passes; pass++) {
+ node.figure_out_scope(mangle);
if (pass > 0 || this.option("reduce_vars"))
node.reset_opt_flags(this);
node = node.transform(this);
@@ -3528,6 +3530,7 @@ merge(Compressor.prototype, {
&& !exp.uses_arguments
&& !exp.uses_eval
&& exp.body.length == 1
+ && !exp.contains_this()
&& all(exp.argnames, function(arg) {
return arg.__unused;
})
@@ -3542,23 +3545,6 @@ merge(Compressor.prototype, {
});
}
if (value) {
- var tw = new TreeWalker(function(node) {
- if (!value) return true;
- if (node instanceof AST_SymbolRef) {
- var ref = node.scope.find_variable(node);
- if (ref && ref.scope.parent_scope === fn.parent_scope) {
- value = null;
- return true;
- }
- }
- if (node instanceof AST_This && !tw.find_parent(AST_Scope)) {
- value = null;
- return true;
- }
- });
- value.walk(tw);
- }
- if (value) {
var args = self.args.concat(value);
return make_sequence(self, args).optimize(compressor);
}
diff --git a/lib/minify.js b/lib/minify.js
index 773e953a..f9d726bf 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -137,11 +137,9 @@ function minify(files, options) {
if (options.wrap) {
toplevel = toplevel.wrap_commonjs(options.wrap);
}
- if (timings) timings.scope1 = Date.now();
- if (options.compress) toplevel.figure_out_scope(options.mangle);
if (timings) timings.compress = Date.now();
if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
- if (timings) timings.scope2 = Date.now();
+ if (timings) timings.scope = Date.now();
if (options.mangle) toplevel.figure_out_scope(options.mangle);
if (timings) timings.mangle = Date.now();
if (options.mangle) {
@@ -199,9 +197,9 @@ function minify(files, options) {
if (timings) {
timings.end = Date.now();
result.timings = {
- parse: 1e-3 * (timings.scope1 - timings.parse),
- scope: 1e-3 * (timings.compress - timings.scope1 + timings.mangle - timings.scope2),
- compress: 1e-3 * (timings.scope2 - timings.compress),
+ parse: 1e-3 * (timings.compress - timings.parse),
+ compress: 1e-3 * (timings.scope - timings.compress),
+ scope: 1e-3 * (timings.mangle - timings.scope),
mangle: 1e-3 * (timings.properties - timings.mangle),
properties: 1e-3 * (timings.output - timings.properties),
output: 1e-3 * (timings.end - timings.output),