aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-02-13 05:16:10 +0000
committerGitHub <noreply@github.com>2020-02-13 05:16:10 +0000
commitc01ff7628868a14338aa1193da2ada011c7ad832 (patch)
treea0b6710ff2054441bfba111a6baac3da04972487
parent83a42716c37eb644c490454d7f2119b1fe8158b1 (diff)
downloadtracifyjs-c01ff7628868a14338aa1193da2ada011c7ad832.tar.gz
tracifyjs-c01ff7628868a14338aa1193da2ada011c7ad832.zip
improve code reuse (#3718)
-rw-r--r--lib/compress.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8a33b474..666f4c4c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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;
}