fix corner case in unused (#4457)

fixes #4456
This commit is contained in:
Alex Lam S.L
2020-12-25 12:10:58 +00:00
committed by GitHub
parent f345175bc2
commit a1b2735dd8
2 changed files with 39 additions and 8 deletions

View File

@@ -5568,13 +5568,11 @@ merge(Compressor.prototype, {
if (def.value) def.value = def.value.transform(tt); if (def.value) def.value = def.value.transform(tt);
if (def.name instanceof AST_Destructured) { if (def.name instanceof AST_Destructured) {
var name = trim_destructured(def.name, def.value, function(node) { var name = trim_destructured(def.name, def.value, function(node) {
if (node instanceof AST_SymbolDeclaration) {
if (!drop_vars) return node; if (!drop_vars) return node;
if (node.definition().id in in_use_ids) return node; if (node.definition().id in in_use_ids) return node;
if (is_catch(node)) return node; if (is_catch(node)) return node;
if (is_var && !can_drop_symbol(node)) return node; if (is_var && !can_drop_symbol(node)) return node;
return null; return null;
}
}); });
if (name) { if (name) {
flush(); flush();
@@ -5747,7 +5745,7 @@ merge(Compressor.prototype, {
descend(node, tt); descend(node, tt);
if (node.left instanceof AST_Destructured) { if (node.left instanceof AST_Destructured) {
var lhs = trim_destructured(node.left, node.right, function(node) { var lhs = trim_destructured(node.left, node.right, function(node) {
if (node instanceof AST_SymbolRef) return node; return node;
}); });
if (!lhs) return node.right; if (!lhs) return node.right;
node.left = lhs; node.left = lhs;

View File

@@ -2164,3 +2164,36 @@ issue_4446: {
expect_stdout: "PASS" expect_stdout: "PASS"
node_version: ">=6" 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"
}