Skip to content

Commit

Permalink
improve code reuse (#3718)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Feb 13, 2020
1 parent 83a4271 commit c01ff76
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/compress.js
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c01ff76

Please sign in to comment.