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,
|
// If the node has been successfully reduced to a constant,
|
||||||
// then its value is returned; otherwise the element itself
|
// then its value is returned; otherwise the element itself
|
||||||
// is returned.
|
// is returned.
|
||||||
|
//
|
||||||
// They can be distinguished as constant value is never a
|
// They can be distinguished as constant value is never a
|
||||||
// descendant of AST_Node.
|
// 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) {
|
AST_Node.DEFMETHOD("evaluate", function(compressor, ignore_side_effects) {
|
||||||
if (!compressor.option("evaluate")) return this;
|
if (!compressor.option("evaluate")) return this;
|
||||||
var cached = [];
|
var cached = [];
|
||||||
@@ -4766,21 +4771,17 @@ merge(Compressor.prototype, {
|
|||||||
return exprs && make_sequence(this, exprs);
|
return exprs && make_sequence(this, exprs);
|
||||||
}
|
}
|
||||||
if (exp instanceof AST_Function && (!exp.name || !exp.name.definition().references.length)) {
|
if (exp instanceof AST_Function && (!exp.name || !exp.name.definition().references.length)) {
|
||||||
var node = this.clone();
|
|
||||||
exp.process_expression(false, function(node) {
|
exp.process_expression(false, function(node) {
|
||||||
var value = node.value && node.value.drop_side_effect_free(compressor, true);
|
var value = node.value && node.value.drop_side_effect_free(compressor, true);
|
||||||
return value ? make_node(AST_SimpleStatement, node, {
|
return value ? make_node(AST_SimpleStatement, node, {
|
||||||
body: value
|
body: value
|
||||||
}) : make_node(AST_EmptyStatement, node);
|
}) : make_node(AST_EmptyStatement, node);
|
||||||
});
|
});
|
||||||
exp.walk(new TreeWalker(function(node) {
|
scan_local_returns(exp, function(node) {
|
||||||
if (node instanceof AST_Return && node.value) {
|
if (node.value) node.value = node.value.drop_side_effect_free(compressor);
|
||||||
node.value = node.value.drop_side_effect_free(compressor);
|
});
|
||||||
return true;
|
// always shallow clone to ensure stripping of negated IIFEs
|
||||||
}
|
return this.clone();
|
||||||
if (node instanceof AST_Scope && node !== exp) return true;
|
|
||||||
}));
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user