aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2015-07-22 16:53:25 +0300
committerMihai Bazon <mihai.bazon@gmail.com>2015-07-22 16:55:55 +0300
commit905b6011784ca60d41919ac1a499962b7c1d4b02 (patch)
treeda15abdd808cefbb9ef794385dd0c5c397f51683
parent63fb2d5a44db3d583b1927c8daa244bf9f4d8dd2 (diff)
downloadtracifyjs-905b6011784ca60d41919ac1a499962b7c1d4b02.tar.gz
tracifyjs-905b6011784ca60d41919ac1a499962b7c1d4b02.zip
Don't attempt to negate non-boolean AST_Binary
Fix #751
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/issue-751.js29
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 54873f0d..4c4cf977 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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, {
diff --git a/test/compress/issue-751.js b/test/compress/issue-751.js
new file mode 100644
index 00000000..829b7ca5
--- /dev/null
+++ b/test/compress/issue-751.js
@@ -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();
+ }
+}