diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-09-03 12:11:44 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-09-03 12:11:44 +0300 |
commit | 6d0db4ce14fd67681bdda1d1861517763eff4c6e (patch) | |
tree | eae00c1f5d5408888e9dfd3b61798b040f0d091a | |
parent | d7c1dc6c0578b55eefc3bc94556146dce6e1a8cb (diff) | |
download | tracifyjs-6d0db4ce14fd67681bdda1d1861517763eff4c6e.tar.gz tracifyjs-6d0db4ce14fd67681bdda1d1861517763eff4c6e.zip |
an AST_If is too a StatementWithBody
-rw-r--r-- | lib/ast.js | 6 | ||||
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | lib/output.js | 28 | ||||
-rw-r--r-- | lib/parse.js | 2 |
4 files changed, 21 insertions, 17 deletions
@@ -286,16 +286,16 @@ var AST_Continue = DEFNODE("Continue", null, { /* -----[ IF ]----- */ -var AST_If = DEFNODE("If", "condition consequent alternative", { +var AST_If = DEFNODE("If", "condition alternative", { $documentation: "A `if` statement", _walk: function(visitor) { return visitor._visit(this, function(){ this.condition._walk(visitor); - this.consequent._walk(visitor); + this.body._walk(visitor); if (this.alternative) this.alternative._walk(visitor); }); } -}); +}, AST_StatementWithBody); /* -----[ SWITCH ]----- */ diff --git a/lib/compress.js b/lib/compress.js index 04d5720b..c290a02e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -276,7 +276,7 @@ function Compressor(options, false_by_default) { SQUEEZE(AST_If, function(self, compressor){ self = self.clone(); self.condition = self.condition.squeeze(compressor); - self.consequent = self.consequent.squeeze(compressor); + self.body = self.body.squeeze(compressor); if (self.alternative) self.alternative = self.alternative.squeeze(compressor); return self; diff --git a/lib/output.js b/lib/output.js index 810a66a1..c321d46d 100644 --- a/lib/output.js +++ b/lib/output.js @@ -447,6 +447,10 @@ function OutputStream(options) { }); }; + AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output){ + force_statement(this.body, output); + }); + DEFPRINT(AST_Statement, function(self, output){ self.body.print(output); output.semicolon(); @@ -476,7 +480,7 @@ function OutputStream(options) { DEFPRINT(AST_Do, function(self, output){ output.print("do"); output.space(); - force_statement(self.body, output); + self._do_print_body(output); output.space(); output.print("while"); output.space(); @@ -492,7 +496,7 @@ function OutputStream(options) { self.condition.print(output); }); output.space(); - force_statement(self.body, output); + self._do_print_body(output); }); DEFPRINT(AST_For, function(self, output){ output.print("for"); @@ -517,7 +521,7 @@ function OutputStream(options) { } }); output.space(); - force_statement(self.body, output); + self._do_print_body(output); }); DEFPRINT(AST_ForIn, function(self, output){ output.print("for"); @@ -530,7 +534,7 @@ function OutputStream(options) { self.object.print(output); }); output.space(); - force_statement(self.body, output); + self._do_print_body(output); }); DEFPRINT(AST_With, function(self, output){ output.print("with"); @@ -539,7 +543,7 @@ function OutputStream(options) { self.expression.print(output); }); output.space(); - force_statement(self.body, output); + self._do_print_body(output); }); /* -----[ functions ]----- */ @@ -606,22 +610,22 @@ function OutputStream(options) { // IF *without* an ELSE block (then the outer ELSE would refer // to the inner IF). This function checks for this case and // adds the block brackets if needed. - if (!self.consequent) + if (!self.body) return output.semicolon(); - if (self.consequent instanceof AST_Do + if (self.body instanceof AST_Do && output.option("ie_proof")) { // https://github.com/mishoo/UglifyJS/issues/#issue/57 IE // croaks with "syntax error" on code like this: if (foo) // do ... while(cond); else ... we need block brackets // around do/while - make_block(self.consequent, output); + make_block(self.body, output); return; } - var b = self.consequent; + var b = self.body; while (true) { if (b instanceof AST_If) { if (!b.alternative) { - make_block(self.consequent, output); + make_block(self.body, output); return; } b = b.alternative; @@ -631,7 +635,7 @@ function OutputStream(options) { } else break; } - self.consequent.print(output); + self.body.print(output); }; DEFPRINT(AST_If, function(self, output){ output.print("if"); @@ -647,7 +651,7 @@ function OutputStream(options) { output.space(); self.alternative.print(output); } else { - force_statement(self.consequent, output); + self._do_print_body(output); } }); diff --git a/lib/parse.js b/lib/parse.js index 9c3f3fb1..2eec3356 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -999,7 +999,7 @@ function parse($TEXT, exigent_mode) { } return new AST_If({ condition : cond, - consequent : body, + body : body, alternative : belse }); }; |