minor
authorMihai Bazon <mihai@bazon.net>
Wed, 12 Sep 2012 13:29:20 +0000 (16:29 +0300)
committerMihai Bazon <mihai@bazon.net>
Wed, 12 Sep 2012 13:29:20 +0000 (16:29 +0300)
lib/compress.js
test/compress/conditionals.js

index 02b9e24..efdc6d8 100644 (file)
@@ -833,17 +833,17 @@ function Compressor(options, false_by_default) {
             && index < block.length - 1) {
             if (compressor.parent() instanceof AST_Lambda) {
                 var rest = tighten_body(block.slice(index + 1), compressor);
-                var cond = negated_is_best ? negated : self.condition.negate(compressor);
+                var cond = self.condition;
                 while (rest[0] instanceof AST_If && rest[0].body instanceof AST_Return && !rest[0].alternative) {
                     cond = make_node(AST_Binary, rest[0], {
-                        operator: "&&",
+                        operator: "||",
                         left: cond,
-                        right: rest[0].condition.negate(compressor)
+                        right: rest[0].condition
                     });
                     rest.shift();
                 }
                 return MAP.last(make_node(AST_If, self, {
-                    condition: cond,
+                    condition: cond.negate(compressor),
                     body: make_node(AST_BlockStatement, block[index + 1], {
                         body: rest
                     }).optimize(compressor)
index b9c348a..54c0751 100644 (file)
@@ -87,3 +87,38 @@ ifs_4: {
         x(foo)[10].bar.baz = (foo && bar) ? something() : something_else();
     }
 }
+
+ifs_5: {
+    options = {
+        conditionals: true
+    };
+    input: {
+        function f() {
+            if (foo) return;
+            bar();
+            baz();
+        }
+        function g() {
+            if (foo) return;
+            if (bar) return;
+            if (baz) return;
+            if (baa) return;
+            a();
+            b()
+        }
+    }
+    expect: {
+        function f() {
+            if (!foo) {
+                bar();
+                baz();
+            }
+        }
+        function g() {
+            if (!(foo || bar || baz || baa)) {
+                a();
+                b()
+            }
+        }
+    }
+}