aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js11
-rw-r--r--test/compress/side_effects.js31
2 files changed, 35 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index c3e315de..da30cee1 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5788,15 +5788,12 @@ merge(Compressor.prototype, {
if (!in_use || node.left === sym && indexOf_assign(def, node) < 0) {
value = get_rhs(node);
if (node.write_only === true) {
- value = value.drop_side_effect_free(compressor) || make_node(AST_Number, node, {
- value: 0
- });
+ value = value.drop_side_effect_free(compressor)
+ || make_node(AST_Number, node, { value: 0 });
}
}
} else if (!in_use || node.expression === sym && indexOf_assign(def, node) < 0) {
- value = make_node(AST_Number, node, {
- value: 0
- });
+ value = make_node(AST_Number, node, { value: 0 });
}
if (value) {
if (parent instanceof AST_Sequence && parent.tail_node() !== node) {
@@ -7168,7 +7165,7 @@ merge(Compressor.prototype, {
assign = assign.clone();
assign.right = cond;
expressions = expressions.slice(0, -2);
- expressions.push(assign);
+ expressions.push(assign.drop_side_effect_free(compressor, first_in_statement));
}
return expressions === this.expressions ? this : make_sequence(this, expressions);
});
diff --git a/test/compress/side_effects.js b/test/compress/side_effects.js
index 177cf503..994e884c 100644
--- a/test/compress/side_effects.js
+++ b/test/compress/side_effects.js
@@ -506,3 +506,34 @@ issue_4366_2: {
expect_stdout: "PASS"
node_version: ">=4"
}
+
+issue_4668: {
+ options = {
+ conditionals: true,
+ keep_fargs: false,
+ keep_fnames: true,
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b, c;
+ function g() {
+ return a = 0 + a, !d || (a = 0);
+ }
+ c = g();
+ }
+ console.log(f());
+ var d = 0;
+ }
+ expect: {
+ console.log(function f() {
+ (function g() {
+ 0;
+ })();
+ }());
+ }
+ expect_stdout: "undefined"
+}