diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-05-11 13:50:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 20:50:58 +0800 |
commit | ae51f76ba7568e01b185cb4b6c6e16dee0bf5300 (patch) | |
tree | c8d15de0ee555d0136de79b7f535ed6489ab2d2a | |
parent | 7eef86ed058345d91a3a46c8bd82e26d0c815873 (diff) | |
download | tracifyjs-ae51f76ba7568e01b185cb4b6c6e16dee0bf5300.tar.gz tracifyjs-ae51f76ba7568e01b185cb4b6c6e16dee0bf5300.zip |
fix corner case in `unused` (#4925)
fixes #4924
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | test/compress/assignments.js | 45 |
2 files changed, 46 insertions, 3 deletions
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" +} |