diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index 249b551a..ffdd5ccc 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4179,7 +4179,7 @@ merge(Compressor.prototype, { }); } var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie8") ? function(def) { - return !compressor.exposed(def) && !def.references.length; + return !compressor.exposed(def) && def.references.length == def.replaced; } : function(def) { // any declarations with same name will overshadow // name of this anonymous function and can therefore @@ -4733,7 +4733,7 @@ merge(Compressor.prototype, { } function all_bool(def, bool_returns, compressor) { - return def.bool_fn + (bool_returns[def.id] || 0) === def.references.length + return def.bool_fn + (bool_returns[def.id] || 0) === def.references.length - def.replaced && !compressor.exposed(def); } @@ -4919,7 +4919,7 @@ merge(Compressor.prototype, { if (def.assignments != count) return; if (def.direct_access) return; if (def.escaped.depth == 1) return; - if (def.references.length == count) return; + if (def.references.length - def.replaced == count) return; if (def.single_use) return; if (top_retain(def)) return; if (sym.fixed_value() !== right) return; @@ -5009,7 +5009,11 @@ merge(Compressor.prototype, { exprs = trim(exprs, compressor, first_in_statement); return exprs && make_sequence(this, exprs); } - if (exp instanceof AST_Function && (!exp.name || !exp.name.definition().references.length)) { + if (exp instanceof AST_Function) { + if (exp.name) { + var def = exp.name.definition(); + if (def.references.length > def.replaced) return this; + } exp.process_expression(false, function(node) { var value = node.value && node.value.drop_side_effect_free(compressor, true); return value ? make_node(AST_SimpleStatement, node, { @@ -6177,7 +6181,7 @@ merge(Compressor.prototype, { if (best_of(compressor, self, node) === node) return node; } var scope, in_loop, level = -1; - if ((exp === fn || compressor.option("unused") && exp.definition().references.length == 1) + if ((exp === fn || compressor.option("unused") && def.references.length - def.replaced == 1) && can_inject_symbols()) { fn._squeezed = true; if (exp !== fn) fn.parent_scope = exp.scope; @@ -6261,7 +6265,7 @@ merge(Compressor.prototype, { if (var_assigned) return; if (compressor.option("inline") < 2 && fn.argnames.length) return; if (!fn.variables.all(function(def) { - return def.references.length < 2 && def.orig[0] instanceof AST_SymbolFunarg; + return def.references.length - def.replaced < 2 && def.orig[0] instanceof AST_SymbolFunarg; })) return; var abort = false; var begin; @@ -7515,7 +7519,8 @@ merge(Compressor.prototype, { } var name_length = def.name.length; if (compressor.option("unused") && !compressor.exposed(def)) { - name_length += (name_length + 2 + value_length) / (def.references.length - def.assignments); + var referenced = def.references.length - def.replaced; + name_length += (name_length + 2 + value_length) / (referenced - def.assignments); } var delta = value_length - Math.floor(name_length); def.should_replace = delta < compressor.eval_threshold ? fn : false; |