Don't attempt to negate non-boolean AST_Binary

Fix #751
This commit is contained in:
Mihai Bazon
2015-07-22 16:53:25 +03:00
parent 63fb2d5a44
commit 905b601178
2 changed files with 30 additions and 1 deletions

View File

@@ -2183,7 +2183,7 @@ merge(Compressor.prototype, {
}
break;
}
if (compressor.option("comparisons")) {
if (compressor.option("comparisons") && self.is_boolean()) {
if (!(compressor.parent() instanceof AST_Binary)
|| compressor.parent() instanceof AST_Assign) {
var negated = make_node(AST_UnaryPrefix, self, {

View File

@@ -0,0 +1,29 @@
negate_booleans_1: {
options = {
comparisons: true
};
input: {
var a = !a || !b || !c || !d || !e || !f;
}
expect: {
var a = !(a && b && c && d && e && f);
}
}
negate_booleans_2: {
options = {
comparisons: true
};
input: {
var match = !x && // should not touch this one
(!z || c) &&
(!k || d) &&
the_stuff();
}
expect: {
var match = !x &&
(!z || c) &&
(!k || d) &&
the_stuff();
}
}