diff --git a/lib/compress.js b/lib/compress.js index 7d6dd704..9d83fc09 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7415,9 +7415,7 @@ merge(Compressor.prototype, { } if (left.has_side_effects(compressor)) return this; var right = this.right; - if (lazy_op[this.operator.slice(0, -1)]) { - this.write_only = !right.has_side_effects(compressor); - } else { + if (!lazy_op[this.operator.slice(0, -1)]) { this.write_only = true; if (root_expr(left).is_constant_expression(compressor.find_parent(AST_Scope))) { return right.drop_side_effect_free(compressor); diff --git a/test/compress/assignments.js b/test/compress/assignments.js index fba763d3..84cc5d67 100644 --- a/test/compress/assignments.js +++ b/test/compress/assignments.js @@ -701,3 +701,48 @@ issue_4876: { expect_stdout: "PASS" node_version: ">=15" } + +issue_4924_1: { + options = { + collapse_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a, b; + console.log("PASS"); + a = function() {}; + b = function() {}(b ||= a); + } + expect: { + var b; + console.log("PASS"); + b = void (b ||= function() {}); + } + expect_stdout: "PASS" + node_version: ">=15" +} + +issue_4924_2: { + options = { + collapse_vars: true, + dead_code: true, + passes: 2, + sequences: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a, b; + console.log("PASS"); + a = function() {}; + b = function() {}(b ||= a); + } + expect: { + console.log("PASS"); + } + expect_stdout: "PASS" + node_version: ">=15" +}