improve code reuse (#3718)
This commit is contained in:
@@ -3071,8 +3071,13 @@ merge(Compressor.prototype, {
|
||||
// If the node has been successfully reduced to a constant,
|
||||
// then its value is returned; otherwise the element itself
|
||||
// is returned.
|
||||
//
|
||||
// They can be distinguished as constant value is never a
|
||||
// descendant of AST_Node.
|
||||
//
|
||||
// When `ignore_side_effects` is `true`, inspect the constant value
|
||||
// produced without worrying about any side effects caused by said
|
||||
// expression.
|
||||
AST_Node.DEFMETHOD("evaluate", function(compressor, ignore_side_effects) {
|
||||
if (!compressor.option("evaluate")) return this;
|
||||
var cached = [];
|
||||
@@ -4766,21 +4771,17 @@ merge(Compressor.prototype, {
|
||||
return exprs && make_sequence(this, exprs);
|
||||
}
|
||||
if (exp instanceof AST_Function && (!exp.name || !exp.name.definition().references.length)) {
|
||||
var node = this.clone();
|
||||
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, {
|
||||
body: value
|
||||
}) : make_node(AST_EmptyStatement, node);
|
||||
});
|
||||
exp.walk(new TreeWalker(function(node) {
|
||||
if (node instanceof AST_Return && node.value) {
|
||||
node.value = node.value.drop_side_effect_free(compressor);
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Scope && node !== exp) return true;
|
||||
}));
|
||||
return node;
|
||||
scan_local_returns(exp, function(node) {
|
||||
if (node.value) node.value = node.value.drop_side_effect_free(compressor);
|
||||
});
|
||||
// always shallow clone to ensure stripping of negated IIFEs
|
||||
return this.clone();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user