Skip to content

Commit

Permalink
fix corner case in dead_code (#3553)
Browse files Browse the repository at this point in the history
fixes #3552
  • Loading branch information
alexlamsl authored Oct 30, 2019
1 parent f1eb03f commit ec7f071
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6433,15 +6433,17 @@ merge(Compressor.prototype, {
OPT(AST_Assign, function(self, compressor) {
if (compressor.option("dead_code")) {
if (self.left instanceof AST_PropAccess) {
var exp = self.left.expression;
if (exp instanceof AST_Lambda
|| !compressor.has_directive("use strict")
&& exp instanceof AST_Constant
&& !exp.may_throw_on_access(compressor)) {
return self.left instanceof AST_Dot ? self.right : make_sequence(self, [
self.left.property,
self.right
]).optimize(compressor);
if (self.operator == "=") {
var exp = self.left.expression;
if (exp instanceof AST_Lambda
|| !compressor.has_directive("use strict")
&& exp instanceof AST_Constant
&& !exp.may_throw_on_access(compressor)) {
return self.left instanceof AST_Dot ? self.right : make_sequence(self, [
self.left.property,
self.right
]).optimize(compressor);
}
}
} else if (self.left instanceof AST_SymbolRef) {
var def = self.left.definition();
Expand Down
22 changes: 22 additions & 0 deletions test/compress/dead-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,3 +1042,25 @@ function_assign: {
}
expect_stdout: "PASS"
}

issue_3552: {
options = {
dead_code: true,
pure_getters: "strict",
}
input: {
var a = "PASS";
(function() {
(1..p += 42) && (a = "FAIL");
})();
console.log(a);
}
expect: {
var a = "PASS";
(function() {
(1..p += 42) && (a = "FAIL");
})();
console.log(a);
}
expect_stdout: "PASS"
}

0 comments on commit ec7f071

Please sign in to comment.