diff --git a/lib/compress.js b/lib/compress.js index a84014c344..ce8e23283e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -12114,7 +12114,7 @@ Compressor.prototype.compress = function(node) { var parent = compressor.parent(); if (compressor.option("booleans")) { var lhs = extract_lhs(self.left, compressor); - if (lazy_op[self.operator] && !lhs.has_side_effects(compressor)) { + if (lazy_op[self.operator] && repeatable(compressor, lhs)) { // a || a ---> a // (a = x) && a --> a = x if (lhs.equals(self.right)) { diff --git a/test/compress/booleans.js b/test/compress/booleans.js index ae69fd0f15..f005b635a2 100644 --- a/test/compress/booleans.js +++ b/test/compress/booleans.js @@ -99,6 +99,53 @@ de_morgan_1d: { expect_stdout: "false false" } +de_morgan_1e: { + options = { + booleans: true, + } + input: { + function f(a) { + return a.p || a.p; + } + console.log(f({ p: null }), f({ p: 42 })); + } + expect: { + function f(a) { + return a.p; + } + console.log(f({ p: null }), f({ p: 42 })); + } + expect_stdout: "null 42" +} + +de_morgan_1f: { + options = { + booleans: true, + inline: true, + pure_getters: "strict", + reduce_vars: true, + toplevel: true, + } + input: { + function f(a, b) { + return a.p + b.q; + } + console.log(f({ p: null }, { q: false }) || f({ p: null }, { q: false })); + console.log(f({ p: "foo" }, { q: 42 }) && f({ p: "foo" }, { q: 42 })); + } + expect: { + function f(a, b) { + return a.p + b.q; + } + console.log(f({ p: null }, { q: !1 })); + console.log(f({ p: "foo" }, { q: 42 })); + } + expect_stdout: [ + "0", + "foo42", + ] +} + de_morgan_2a: { options = { booleans: true,