From 905b6011784ca60d41919ac1a499962b7c1d4b02 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Wed, 22 Jul 2015 16:53:25 +0300 Subject: Don't attempt to negate non-boolean AST_Binary Fix #751 --- lib/compress.js | 2 +- test/compress/issue-751.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/compress/issue-751.js 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(); + } +} -- cgit v1.2.3