minor
authorMihai Bazon <mihai@bazon.net>
Sat, 8 Sep 2012 14:03:09 +0000 (17:03 +0300)
committerMihai Bazon <mihai@bazon.net>
Sat, 8 Sep 2012 19:51:59 +0000 (22:51 +0300)
lib/compress.js

index 953fd90..3ce0629 100644 (file)
@@ -166,6 +166,7 @@ function Compressor(options, false_by_default) {
     };
 
     function extract_declarations_from_unreachable_code(compressor, stat, target) {
+        warn_dead_code(stat);
         stat.walk(new TreeWalker(function(node){
             if (node instanceof AST_Definitions || node instanceof AST_Defun) {
                 compressor.warn("Declarations in unreachable code! [{line},{col}]", node.start);
@@ -579,11 +580,12 @@ function Compressor(options, false_by_default) {
                 });
             } else if (self instanceof AST_While) {
                 if (compressor.option("dead_code")) {
-                    warn_dead_code(self);
                     var a = [];
                     extract_declarations_from_unreachable_code(compressor, self.body, a);
                     return make_node(AST_BlockStatement, self, { body: a });
                 }
+            } else {
+                return self.body;
             }
         }
         return self;
@@ -605,20 +607,20 @@ function Compressor(options, false_by_default) {
             this.condition = cond[0];
         }
         if (!compressor.option("loops")) return this;
-        if (this.condition) {
-            var cond = this.condition.evaluate(compressor);
+        if (cond) {
             if (cond.length == 2 && !cond[1]) {
                 if (compressor.option("dead_code")) {
-                    warn_dead_code(this.body);
                     var a = [];
-                    if (this.init instanceof AST_Statement) a.push(this.init);
-                    else if (this.init) a.push(make_node(AST_SimpleStatement, this.init, {
-                        body: this.init
-                    }));
+                    if (this.init instanceof AST_Statement) {
+                        a.push(this.init);
+                    }
+                    else if (this.init) {
+                        a.push(make_node(AST_SimpleStatement, this.init, {
+                            body: this.init
+                        }));
+                    }
                     extract_declarations_from_unreachable_code(compressor, this.body, a);
-                    return make_node(AST_BlockStatement, this, {
-                        body: a
-                    });
+                    return make_node(AST_BlockStatement, this, { body: a });
                 }
             }
         }
@@ -675,7 +677,6 @@ function Compressor(options, false_by_default) {
                 if (compressor.option("dead_code")) {
                     var a = [];
                     if (self.alternative) {
-                        warn_dead_code(self.alternative);
                         extract_declarations_from_unreachable_code(compressor, self.alternative, a);
                     }
                     a.push(self.body);
@@ -684,7 +685,6 @@ function Compressor(options, false_by_default) {
             } else {
                 AST_Node.warn("Condition always false [{line},{col}]", self.condition.start);
                 if (compressor.option("dead_code")) {
-                    warn_dead_code(self.body);
                     var a = [];
                     extract_declarations_from_unreachable_code(compressor, self.body, a);
                     if (self.alternative) a.push(self.alternative);