From: Mihai Bazon Date: Wed, 22 Jul 2015 13:53:25 +0000 (+0300) Subject: Don't attempt to negate non-boolean AST_Binary X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=905b6011784ca60d41919ac1a499962b7c1d4b02;p=UglifyJS.git Don't attempt to negate non-boolean AST_Binary Fix #751 --- 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(); + } +}