@@ -8283,7 +8283,9 @@ merge(Compressor.prototype, {
|
|||||||
if (is_empty(self.alternative)) self.alternative = null;
|
if (is_empty(self.alternative)) self.alternative = null;
|
||||||
|
|
||||||
if (!compressor.option("conditionals")) return self;
|
if (!compressor.option("conditionals")) return self;
|
||||||
if (compressor.option("booleans")) mark_duplicate_condition(compressor, self.condition);
|
if (compressor.option("booleans") && !self.condition.has_side_effects(compressor)) {
|
||||||
|
mark_duplicate_condition(compressor, self.condition);
|
||||||
|
}
|
||||||
// if condition can be statically determined, warn and drop
|
// if condition can be statically determined, warn and drop
|
||||||
// one of the blocks. note, statically determined implies
|
// one of the blocks. note, statically determined implies
|
||||||
// “has no side effects”; also it doesn't work for cases like
|
// “has no side effects”; also it doesn't work for cases like
|
||||||
@@ -11335,8 +11337,11 @@ merge(Compressor.prototype, {
|
|||||||
return make_sequence(self, expressions);
|
return make_sequence(self, expressions);
|
||||||
}
|
}
|
||||||
if (!compressor.option("conditionals")) return self;
|
if (!compressor.option("conditionals")) return self;
|
||||||
if (compressor.option("booleans")) mark_duplicate_condition(compressor, self.condition);
|
var condition = self.condition;
|
||||||
var condition = fuzzy_eval(compressor, self.condition);
|
if (compressor.option("booleans") && !condition.has_side_effects(compressor)) {
|
||||||
|
mark_duplicate_condition(compressor, condition);
|
||||||
|
}
|
||||||
|
condition = fuzzy_eval(compressor, condition);
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
AST_Node.warn("Condition always false [{file}:{line},{col}]", self.start);
|
AST_Node.warn("Condition always false [{file}:{line},{col}]", self.start);
|
||||||
return make_sequence(self, [ self.condition, self.alternative ]).optimize(compressor);
|
return make_sequence(self, [ self.condition, self.alternative ]).optimize(compressor);
|
||||||
|
|||||||
@@ -558,3 +558,79 @@ issue_4374: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "0"
|
expect_stdout: "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5028_1: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
console.log(function() {
|
||||||
|
return a-- ? a-- ? "FAIL 1" : "PASS" : "FAIL 2";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
console.log(function() {
|
||||||
|
return a-- ? a-- ? "FAIL 1" : "PASS" : "FAIL 2";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5028_2: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
(function() {
|
||||||
|
if (a--)
|
||||||
|
if (a--)
|
||||||
|
a = "FAIL";
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
(function() {
|
||||||
|
a-- && a-- && (a = "FAIL");
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5028_3: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
(function() {
|
||||||
|
if (a--)
|
||||||
|
if (a--)
|
||||||
|
a = "FAIL";
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
(function() {
|
||||||
|
a-- && a-- && (a = "FAIL");
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "-1"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user