From 11863d6f9a48d6c7194ad65f9cc140292aedc948 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Wed, 3 Oct 2012 15:52:01 +0300 Subject: [PATCH] more cleanup (dropped AST_SwitchBlock) --- lib/ast.js | 6 +----- lib/compress.js | 2 +- lib/output.js | 3 --- lib/parse.js | 13 ++++--------- lib/scope.js | 2 +- lib/transform.js | 2 +- 6 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index d80d7152..2b2467cf 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -332,15 +332,11 @@ var AST_Switch = DEFNODE("Switch", "body expression", { _walk: function(visitor) { return visitor._visit(this, function(){ this.expression._walk(visitor); - this.body._walk(visitor); + walk_body(this, visitor); }); } }, AST_Statement); -var AST_SwitchBlock = DEFNODE("SwitchBlock", null, { - $documentation: "The switch block is somewhat special, hence a special node for it", -}, AST_Block); - var AST_SwitchBranch = DEFNODE("SwitchBranch", null, { $documentation: "Base class for `switch` branches", }, AST_Block); diff --git a/lib/compress.js b/lib/compress.js index 1319d798..10c1d222 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1181,7 +1181,7 @@ merge(Compressor.prototype, { }); OPT(AST_Switch, function(self, compressor){ - var last_branch = self.body.body[self.body.body.length - 1]; + var last_branch = self.body[self.body.length - 1]; if (last_branch) { var stat = last_branch.body[last_branch.body.length - 1]; // last statement if (stat instanceof AST_Break && !stat.label) diff --git a/lib/output.js b/lib/output.js index dc6d777f..84452d34 100644 --- a/lib/output.js +++ b/lib/output.js @@ -718,9 +718,6 @@ function OutputStream(options) { self.expression.print(output); }); output.space(); - self.body.print(output); - }); - DEFPRINT(AST_SwitchBlock, function(self, output){ if (self.body.length > 0) output.with_block(function(){ self.body.forEach(function(stmt, i){ if (i) output.newline(); diff --git a/lib/parse.js b/lib/parse.js index b342ca4e..3bf8d29d 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -867,7 +867,7 @@ function parse($TEXT, options) { case "switch": return new AST_Switch({ expression : parenthesised(), - body : switch_block_() + body : switch_body_() }); case "throw": @@ -1034,7 +1034,7 @@ function parse($TEXT, options) { return a; }; - var switch_block_ = embed_tokens(curry(in_loop, function(){ + var switch_body_ = curry(in_loop, function(){ expect("{"); var a = [], cur = null, branch = null, start = S.token; while (!is("punc", "}")) { @@ -1065,14 +1065,9 @@ function parse($TEXT, options) { } } if (branch) branch.end = prev(); - var end = S.token; next(); - return new AST_SwitchBlock({ - start : start, - body : a, - end : end - }); - })); + return a; + }); function try_() { var body = block_(), bcatch = null, bfinally = null; diff --git a/lib/scope.js b/lib/scope.js index db581fce..54839c4d 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -127,7 +127,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){ if (p instanceof AST_For || p instanceof AST_ForIn || p instanceof AST_DWLoop - || p instanceof AST_Switch) { + || p instanceof AST_SwitchBranch) { node.loopcontrol_target = p.body; break; } diff --git a/lib/transform.js b/lib/transform.js index d85262be..db228beb 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -140,7 +140,7 @@ TreeTransformer.prototype = new TreeWalker; _(AST_Switch, function(self, tw){ self.expression = self.expression.transform(tw); - self.body = self.body.transform(tw); + self.body = do_list(self.body, tw); }); _(AST_Case, function(self, tw){ -- 2.34.1