From 1c8ba35844f4032fd9f12961a0feee1a78153aa3 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Sat, 8 Sep 2012 17:03:09 +0300 Subject: [PATCH] minor --- lib/compress.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 953fd901..3ce06298 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); -- 2.34.1