diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-10-16 06:37:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-16 06:37:40 +0800 |
commit | 8ff9a3c8fb89ac40fea0dd1cd249e8b94a690c2e (patch) | |
tree | 3df4e52f16431d13fc2a81f8c45ba5d7ac1820bd /lib/compress.js | |
parent | 91cae51d8f8a7f06e55dba7d100bbb663448875b (diff) | |
download | tracifyjs-8ff9a3c8fb89ac40fea0dd1cd249e8b94a690c2e.tar.gz tracifyjs-8ff9a3c8fb89ac40fea0dd1cd249e8b94a690c2e.zip |
fix corner cases in `ie8` (#3485)
fixes #3484
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); } |