Skip to content

Commit

Permalink
fix corner case in dead_code (#3579)
Browse files Browse the repository at this point in the history
fixes #3578
  • Loading branch information
alexlamsl committed Nov 11, 2019
1 parent 765a063 commit 5b20bad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/compress.js
Expand Up @@ -6545,20 +6545,22 @@ merge(Compressor.prototype, {
} else if (self.left instanceof AST_SymbolRef) {
if (self.left.is_immutable()) return strip_assignment();
var def = self.left.definition();
var local = def.scope.resolve() === compressor.find_parent(AST_Lambda);
var scope = def.scope.resolve();
var local = scope === compressor.find_parent(AST_Lambda);
var level = 0, node, parent = self;
do {
node = parent;
parent = compressor.parent(level++);
if (parent instanceof AST_Assign) {
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();
} else if (parent instanceof AST_Exit) {
if (!local) break;
if (in_try(level, parent)) break;
if (is_reachable(def.scope, [ def ])) break;
if (is_reachable(scope, [ def ])) break;
def.fixed = false;
return strip_assignment();
}
Expand Down Expand Up @@ -6604,9 +6606,9 @@ merge(Compressor.prototype, {
self.right = make_node(AST_Null, right);
var may_throw = node.may_throw(compressor);
self.right = right;
var scope = self.left.definition().scope.resolve();
var parent;
while ((parent = compressor.parent(level++)) !== scope) {
while (parent = compressor.parent(level++)) {
if (parent === scope) return false;
if (parent instanceof AST_Try) {
if (parent.bfinally) return true;
if (may_throw && parent.bcatch) return true;
Expand Down
27 changes: 27 additions & 0 deletions test/compress/dead-code.js
Expand Up @@ -1102,3 +1102,30 @@ catch_return_assign: {
}
expect_stdout: "PASS"
}

issue_3578: {
options = {
dead_code: true,
}
input: {
var a = "FAIL", b, c;
try {
b = c.p = b = 0;
} catch (e) {
b += 42;
b && (a = "PASS");
}
console.log(a);
}
expect: {
var a = "FAIL", b, c;
try {
b = c.p = b = 0;
} catch (e) {
b += 42;
b && (a = "PASS");
}
console.log(a);
}
expect_stdout: "PASS"
}

0 comments on commit 5b20bad

Please sign in to comment.