more cleanup (dropped AST_SwitchBlock)
authorMihai Bazon <mihai@bazon.net>
Wed, 3 Oct 2012 12:52:01 +0000 (15:52 +0300)
committerMihai Bazon <mihai@bazon.net>
Wed, 3 Oct 2012 12:52:31 +0000 (15:52 +0300)
lib/ast.js
lib/compress.js
lib/output.js
lib/parse.js
lib/scope.js
lib/transform.js

index d80d715..2b2467c 100644 (file)
@@ -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);
index 1319d79..10c1d22 100644 (file)
@@ -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)
index dc6d777..84452d3 100644 (file)
@@ -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();
index b342ca4..3bf8d29 100644 (file)
@@ -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;
index db581fc..54839c4 100644 (file)
@@ -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;
                     }
index d85262b..db228be 100644 (file)
@@ -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){