diff options
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index be9e8dc8..c903d9af 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4167,6 +4167,15 @@ merge(Compressor.prototype, { } }); + function safe_to_drop(fn, compressor) { + if (!fn.name || !compressor.option("ie8")) return true; + var def = fn.name.definition(); + if (compressor.exposed(def)) return false; + return all(def.references, function(sym) { + return !(sym instanceof AST_SymbolRef); + }); + } + // drop_side_effect_free() // remove side-effect-free parts which only affects return value (function(def) { @@ -4284,7 +4293,7 @@ merge(Compressor.prototype, { return expr.drop_side_effect_free(compressor, first_in_statement); }); def(AST_Function, function(compressor) { - return this.name && compressor.option("ie8") ? this : null; + return safe_to_drop(this, compressor) ? null : this; }); def(AST_Object, function(compressor, first_in_statement) { var values = trim(this.properties, compressor, first_in_statement); @@ -5170,7 +5179,9 @@ merge(Compressor.prototype, { fn._squeezed = true; return make_sequence(self, flatten_fn()).optimize(compressor); } - if (compressor.option("side_effects") && all(fn.body, is_empty)) { + if (compressor.option("side_effects") + && all(fn.body, is_empty) + && (fn !== exp || safe_to_drop(fn, compressor))) { var args = self.args.concat(make_node(AST_Undefined, self)); return make_sequence(self, args).optimize(compressor); } |