diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-12 18:24:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-13 02:24:18 +0800 |
commit | af9762991222f5a4577aef1631d039b129e683d9 (patch) | |
tree | b9964b819e1a36f425a3c22c679bedf8782eceaa | |
parent | 8c000033d3604dcad50faf31b2dbecc4f0fb98b6 (diff) | |
download | tracifyjs-af9762991222f5a4577aef1631d039b129e683d9.tar.gz tracifyjs-af9762991222f5a4577aef1631d039b129e683d9.zip |
fix corner case in `dead_code` (#4373)
fixes #4372
-rw-r--r-- | lib/compress.js | 16 | ||||
-rw-r--r-- | test/compress/destructured.js | 38 |
2 files changed, 48 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js index 96589686..db91155c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -9293,12 +9293,16 @@ merge(Compressor.prototype, { node = parent; parent = compressor.parent(level++); if (parent instanceof AST_Assign) { - if (parent.left instanceof AST_PropAccess) break; - if (!(parent.left instanceof AST_SymbolRef)) continue; - if (parent.left.definition() !== def) continue; - if (in_try(level, parent)) break; - def.fixed = false; - return strip_assignment(); + var found = false; + if (parent.left.match_symbol(function(node) { + if (node instanceof AST_PropAccess) return true; + if (!found && node instanceof AST_SymbolRef && node.definition() === def) { + if (in_try(level, parent)) return true; + def.fixed = false; + found = true; + } + })) break; + if (found) return strip_assignment(); } else if (parent instanceof AST_Exit) { if (!local) break; if (in_try(level, parent)) break; diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 82d02172..086790f0 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1806,3 +1806,41 @@ issue_4355: { expect_stdout: "2" node_version: ">=6" } + +issue_4372_1: { + options = { + dead_code: true, + } + input: { + var a = "FAIL"; + a += { + [console.log(a)]: a, + } = a = "PASS"; + } + expect: { + var a = "FAIL"; + a += { + [console.log(a)]: a, + } = a = "PASS"; + } + expect_stdout: "PASS" + node_version: ">=6" +} + +issue_4372_2: { + options = { + dead_code: true, + } + input: { + var a; + [ a ] = a = [ "PASS", "FAIL" ]; + console.log(a); + } + expect: { + var a; + [ a ] = [ "PASS", "FAIL" ]; + console.log(a); + } + expect_stdout: "PASS" + node_version: ">=6" +} |