fix corner cases in ie8 (#3485)

fixes #3484
This commit is contained in:
Alex Lam S.L
2019-10-16 06:37:40 +08:00
committed by GitHub
parent 91cae51d8f
commit 8ff9a3c8fb
3 changed files with 172 additions and 3 deletions

View File

@@ -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);
}