diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-25 12:10:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-25 20:10:58 +0800 |
commit | a1b2735dd8f7f89b7dd57ee7098f1720df28838f (patch) | |
tree | afefaf120f2785e847ee1f65dd54685ceef71643 | |
parent | f345175bc2aef3cb9d3ceb6ec241cf191dd70eb7 (diff) | |
download | tracifyjs-a1b2735dd8f7f89b7dd57ee7098f1720df28838f.tar.gz tracifyjs-a1b2735dd8f7f89b7dd57ee7098f1720df28838f.zip |
fix corner case in `unused` (#4457)
fixes #4456
-rw-r--r-- | lib/compress.js | 14 | ||||
-rw-r--r-- | test/compress/destructured.js | 33 |
2 files changed, 39 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js index 0718e5c7..1dc01f93 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5568,13 +5568,11 @@ merge(Compressor.prototype, { if (def.value) def.value = def.value.transform(tt); if (def.name instanceof AST_Destructured) { var name = trim_destructured(def.name, def.value, function(node) { - if (node instanceof AST_SymbolDeclaration) { - if (!drop_vars) return node; - if (node.definition().id in in_use_ids) return node; - if (is_catch(node)) return node; - if (is_var && !can_drop_symbol(node)) return node; - return null; - } + if (!drop_vars) return node; + if (node.definition().id in in_use_ids) return node; + if (is_catch(node)) return node; + if (is_var && !can_drop_symbol(node)) return node; + return null; }); if (name) { flush(); @@ -5747,7 +5745,7 @@ merge(Compressor.prototype, { descend(node, tt); if (node.left instanceof AST_Destructured) { var lhs = trim_destructured(node.left, node.right, function(node) { - if (node instanceof AST_SymbolRef) return node; + return node; }); if (!lhs) return node.right; node.left = lhs; diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 7fe2f0c8..98e84f48 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -2164,3 +2164,36 @@ issue_4446: { expect_stdout: "PASS" node_version: ">=6" } + +issue_4456: { + options = { + pure_getters: true, + unused: true, + } + input: { + var o = { + set p(v) { + console.log(v); + }, + }; + [ function() { + try { + return o; + } catch ({}) {} + }().p ] = [ "PASS" ]; + } + expect: { + var o = { + set p(v) { + console.log(v); + }, + }; + [ function() { + try { + return o; + } catch ({}) {} + }().p ] = [ "PASS" ]; + } + expect_stdout: "PASS" + node_version: ">=6" +} |