aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-05 04:27:01 +0800
committerGitHub <noreply@github.com>2017-11-05 04:27:01 +0800
commita8aa28a7a6c0cb415965d055119956d4333de8fa (patch)
tree7961dfe4da68bf9407d14bcf6cd418d5b58c2b09 /lib
parentfe5a68f9d5a93557d44c48cd0a8ee533e2bd1a47 (diff)
downloadtracifyjs-a8aa28a7a6c0cb415965d055119956d4333de8fa.tar.gz
tracifyjs-a8aa28a7a6c0cb415965d055119956d4333de8fa.zip
consolidate single-use `function` reduction (#2427)
fixes #2423
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 1b4a1f77..ba90f000 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -315,12 +315,18 @@ merge(Compressor.prototype, {
d.fixed = false;
} else if (d.fixed) {
var value = node.fixed_value();
- if (unused) {
- d.single_use = value
- && d.references.length == 1
- && loop_ids[d.id] === in_loop
- && d.scope === node.scope
- && value.is_constant_expression();
+ if (unused && value && d.references.length == 1) {
+ if (value instanceof AST_Lambda) {
+ d.single_use = d.scope === node.scope
+ && !(d.orig[0] instanceof AST_SymbolFunarg)
+ || value.is_constant_expression();
+ } else {
+ d.single_use = d.scope === node.scope
+ && loop_ids[d.id] === in_loop
+ && value.is_constant_expression();
+ }
+ } else {
+ d.single_use = false;
}
if (is_modified(node, value, 0, is_immutable(value))) {
if (d.single_use) {
@@ -377,6 +383,10 @@ merge(Compressor.prototype, {
} else {
d.fixed = node;
mark(d, true);
+ if (unused && d.references.length == 1) {
+ d.single_use = d.scope === d.references[0].scope
+ || node.is_constant_expression();
+ }
}
var save_ids = safe_ids;
safe_ids = Object.create(null);
@@ -527,6 +537,7 @@ merge(Compressor.prototype, {
}
return true;
}
+ return def.fixed instanceof AST_Defun;
}
function safe_to_assign(def, value) {
@@ -2165,7 +2176,7 @@ merge(Compressor.prototype, {
}
def(AST_Node, return_false);
def(AST_Constant, return_true);
- def(AST_Function, function(){
+ def(AST_Lambda, function(){
var self = this;
var result = true;
self.walk(new TreeWalker(function(node) {
@@ -4221,10 +4232,7 @@ merge(Compressor.prototype, {
if (compressor.option("unused")
&& fixed
&& d.references.length == 1
- && (d.single_use || fixed instanceof AST_Function
- && !(d.scope.uses_arguments && d.orig[0] instanceof AST_SymbolFunarg)
- && !d.scope.uses_eval
- && compressor.find_parent(AST_Scope) === fixed.parent_scope)) {
+ && d.single_use) {
var value = fixed.optimize(compressor);
return value === fixed ? fixed.clone(true) : value;
}