enhance compress on arrow and async functions (#4616)
This commit is contained in:
@@ -1843,7 +1843,7 @@ merge(Compressor.prototype, {
|
||||
if (node instanceof AST_Call) {
|
||||
if (!(lhs instanceof AST_PropAccess)) return false;
|
||||
if (!lhs.equivalent_to(node.expression)) return false;
|
||||
return !(rvalue instanceof AST_Function && !rvalue.contains_this());
|
||||
return !(is_function(rvalue) && !rvalue.contains_this());
|
||||
}
|
||||
if (node instanceof AST_Debugger) return true;
|
||||
if (node instanceof AST_Defun) return funarg && lhs.name === node.name.name;
|
||||
@@ -2482,7 +2482,7 @@ merge(Compressor.prototype, {
|
||||
if (modify_toplevel) return;
|
||||
var exp = node.expression;
|
||||
if (exp instanceof AST_PropAccess) return;
|
||||
if (exp instanceof AST_Function && !exp.contains_this()) return;
|
||||
if (is_function(exp) && !exp.contains_this()) return;
|
||||
modify_toplevel = true;
|
||||
} else if (node instanceof AST_PropAccess && may_be_global(node.expression)) {
|
||||
if (node === lhs && !(expr instanceof AST_Unary)) {
|
||||
@@ -4060,7 +4060,7 @@ merge(Compressor.prototype, {
|
||||
key = key._eval(compressor, ignore_side_effects, cached, depth);
|
||||
if (key === prop.key) return this;
|
||||
}
|
||||
if (prop.value instanceof AST_Function && typeof Object.prototype[key] == "function") return this;
|
||||
if (key == "toString" || key == "valueOf") return this;
|
||||
val[key] = prop.value._eval(compressor, ignore_side_effects, cached, depth);
|
||||
if (val[key] === prop.value) return this;
|
||||
}
|
||||
@@ -5850,10 +5850,10 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
} else if (compressor.option("functions")
|
||||
&& !compressor.option("ie8")
|
||||
&& !(node instanceof AST_Const || node instanceof AST_Let)
|
||||
&& node instanceof AST_Var
|
||||
&& var_defs[sym.id] == 1
|
||||
&& sym.assignments == 0
|
||||
&& value instanceof AST_Function
|
||||
&& (value instanceof AST_AsyncFunction || value instanceof AST_Function)
|
||||
&& (sym.references.length ? all(sym.references, function(ref) {
|
||||
return value === ref.fixed_value();
|
||||
}) : value === def.name.fixed_value())
|
||||
@@ -5864,7 +5864,7 @@ merge(Compressor.prototype, {
|
||||
&& can_declare_defun()
|
||||
&& can_rename(value, def.name.name)) {
|
||||
AST_Node.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name));
|
||||
var defun = make_node(AST_Defun, def, value);
|
||||
var defun = make_node(value instanceof AST_Function ? AST_Defun : AST_AsyncDefun, def, value);
|
||||
defun.name = make_node(AST_SymbolDefun, def.name, def.name);
|
||||
var name_def = def.name.scope.resolve().def_function(defun.name);
|
||||
if (old_def) old_def.forEach(function(node) {
|
||||
@@ -6902,7 +6902,7 @@ merge(Compressor.prototype, {
|
||||
return exprs && make_sequence(self, exprs.map(convert_spread));
|
||||
}
|
||||
var def;
|
||||
if (exp instanceof AST_Function
|
||||
if ((is_arrow(exp) && !exp.value || exp instanceof AST_AsyncFunction || exp instanceof AST_Function)
|
||||
&& !(exp.name && (def = exp.name.definition()).references.length > def.replaced)) {
|
||||
exp.process_expression(false, function(node) {
|
||||
var value = node.value && node.value.drop_side_effect_free(compressor, true);
|
||||
|
||||
Reference in New Issue
Block a user