diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-06-12 01:00:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-12 08:00:19 +0800 |
commit | a82ca62b66c7c7e1083d9f2195870fbdb1d22361 (patch) | |
tree | 90a118e0437082e98bcaecb6e6bf5882de03408d | |
parent | e9465717abb77fed206455881a983f313d2b894c (diff) | |
download | tracifyjs-a82ca62b66c7c7e1083d9f2195870fbdb1d22361.tar.gz tracifyjs-a82ca62b66c7c7e1083d9f2195870fbdb1d22361.zip |
fix corner case in `dead_code` (#3991)
-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, |