Skip to content

Commit

Permalink
fix corner case in dead_code (#4984)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed May 30, 2021
1 parent b9d5bba commit 7e88d52
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -11085,9 +11085,7 @@ merge(Compressor.prototype, {
]).optimize(compressor);
}
}
} else if (self.left instanceof AST_SymbolRef && all(self.left.definition().orig, function(sym) {
return !(sym instanceof AST_SymbolConst);
})) {
} else if (self.left instanceof AST_SymbolRef && can_drop_symbol(self.left, compressor)) {
var parent;
if (self.operator == "=" && self.left.equivalent_to(self.right)
&& !((parent = compressor.parent()) instanceof AST_UnaryPrefix && parent.operator == "delete")) {
Expand Down
34 changes: 34 additions & 0 deletions test/compress/let.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ retain_block: {
node_version: ">=4"
}

retain_assignment: {
options = {
dead_code: true,
reduce_vars: true,
}
input: {
"use strict";
function f() {
return a = 0;
let a;
}
try {
f();
} catch (e) {
console.log("PASS");
}
}
expect: {
"use strict";
function f() {
return a = 0;
let a;
}
try {
f();
} catch (e) {
console.log("PASS");
}
}
expect_stdout: "PASS"
node_version: ">=4"
}

retain_catch: {
options = {
dead_code: true,
Expand Down Expand Up @@ -897,6 +930,7 @@ issue_4210: {
issue_4212_1: {
options = {
dead_code: true,
reduce_vars: true,
}
input: {
"use strict";
Expand Down

0 comments on commit 7e88d52

Please sign in to comment.