fix corner case in dead_code

fixes #3552
This commit is contained in:
alexlamsl 2019-10-30 13:23:29 +08:00
parent f1eb03f2c0
commit f1b863d46c
2 changed files with 33 additions and 9 deletions

View File

@ -6433,6 +6433,7 @@ merge(Compressor.prototype, {
OPT(AST_Assign, function(self, compressor) { OPT(AST_Assign, function(self, compressor) {
if (compressor.option("dead_code")) { if (compressor.option("dead_code")) {
if (self.left instanceof AST_PropAccess) { if (self.left instanceof AST_PropAccess) {
if (self.operator == "=") {
var exp = self.left.expression; var exp = self.left.expression;
if (exp instanceof AST_Lambda if (exp instanceof AST_Lambda
|| !compressor.has_directive("use strict") || !compressor.has_directive("use strict")
@ -6443,6 +6444,7 @@ merge(Compressor.prototype, {
self.right self.right
]).optimize(compressor); ]).optimize(compressor);
} }
}
} else if (self.left instanceof AST_SymbolRef) { } else if (self.left instanceof AST_SymbolRef) {
var def = self.left.definition(); var def = self.left.definition();
if (def.scope === compressor.find_parent(AST_Lambda)) { if (def.scope === compressor.find_parent(AST_Lambda)) {

View File

@ -1042,3 +1042,25 @@ function_assign: {
} }
expect_stdout: "PASS" 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"
}