diff options
-rw-r--r-- | lib/compress.js | 15 | ||||
-rw-r--r-- | test/compress/dead-code.js | 25 |
2 files changed, 29 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js index 2a1399d5..a3a4a63d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7865,12 +7865,10 @@ merge(Compressor.prototype, { if (self.left instanceof AST_PropAccess) { if (self.operator == "=") { if (self.__drop) { - var props = []; - flatten(self.left, props); - flatten(self.right, props); - return props.length == 0 ? make_node(AST_Number, self, { - value: 0 - }) : make_sequence(self, props).optimize(compressor); + var exprs = [ self.left.expression ]; + if (self.left instanceof AST_Sub) exprs.push(self.left.property); + exprs.push(self.right); + return make_sequence(self, exprs).optimize(compressor); } if (self.left.equivalent_to(self.right) && !self.left.has_side_effects(compressor)) { return self.right; @@ -7962,11 +7960,6 @@ merge(Compressor.prototype, { } return try_evaluate(compressor, self); - function flatten(node, props) { - if (!(node.expression instanceof AST_SymbolRef)) props.push(node.expression); - if (node instanceof AST_Sub) props.push(node.property); - } - function in_try(level, node) { var right = self.right; self.right = make_node(AST_Null, right); diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index a2ebf37a..4f731875 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -1290,12 +1290,37 @@ self_assignments_5: { } expect: { var i = 0, l = [ "FAIL", "PASS" ]; + l[0]; + l[0]; l[0] = l[1]; console.log(l[0], 2); } expect_stdout: "PASS 2" } +self_assignments_6: { + options = { + dead_code: true, + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var o = { + p: "PASS", + }; + console.log(o.p = o.p); + } + expect: { + var o = { + p: "PASS", + }; + console.log(o.p); + } + expect_stdout: "PASS" +} + issue_3967: { options = { dead_code: true, |