more cleanup (dropped AST_SwitchBlock)

This commit is contained in:
Mihai Bazon
2012-10-03 15:52:01 +03:00
parent 3412498795
commit 11863d6f9a
6 changed files with 8 additions and 20 deletions

View File

@@ -332,15 +332,11 @@ var AST_Switch = DEFNODE("Switch", "body expression", {
_walk: function(visitor) { _walk: function(visitor) {
return visitor._visit(this, function(){ return visitor._visit(this, function(){
this.expression._walk(visitor); this.expression._walk(visitor);
this.body._walk(visitor); walk_body(this, visitor);
}); });
} }
}, AST_Statement); }, 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, { var AST_SwitchBranch = DEFNODE("SwitchBranch", null, {
$documentation: "Base class for `switch` branches", $documentation: "Base class for `switch` branches",
}, AST_Block); }, AST_Block);

View File

@@ -1181,7 +1181,7 @@ merge(Compressor.prototype, {
}); });
OPT(AST_Switch, function(self, compressor){ 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) { if (last_branch) {
var stat = last_branch.body[last_branch.body.length - 1]; // last statement var stat = last_branch.body[last_branch.body.length - 1]; // last statement
if (stat instanceof AST_Break && !stat.label) if (stat instanceof AST_Break && !stat.label)

View File

@@ -718,9 +718,6 @@ function OutputStream(options) {
self.expression.print(output); self.expression.print(output);
}); });
output.space(); output.space();
self.body.print(output);
});
DEFPRINT(AST_SwitchBlock, function(self, output){
if (self.body.length > 0) output.with_block(function(){ if (self.body.length > 0) output.with_block(function(){
self.body.forEach(function(stmt, i){ self.body.forEach(function(stmt, i){
if (i) output.newline(); if (i) output.newline();

View File

@@ -867,7 +867,7 @@ function parse($TEXT, options) {
case "switch": case "switch":
return new AST_Switch({ return new AST_Switch({
expression : parenthesised(), expression : parenthesised(),
body : switch_block_() body : switch_body_()
}); });
case "throw": case "throw":
@@ -1034,7 +1034,7 @@ function parse($TEXT, options) {
return a; return a;
}; };
var switch_block_ = embed_tokens(curry(in_loop, function(){ var switch_body_ = curry(in_loop, function(){
expect("{"); expect("{");
var a = [], cur = null, branch = null, start = S.token; var a = [], cur = null, branch = null, start = S.token;
while (!is("punc", "}")) { while (!is("punc", "}")) {
@@ -1065,14 +1065,9 @@ function parse($TEXT, options) {
} }
} }
if (branch) branch.end = prev(); if (branch) branch.end = prev();
var end = S.token;
next(); next();
return new AST_SwitchBlock({ return a;
start : start, });
body : a,
end : end
});
}));
function try_() { function try_() {
var body = block_(), bcatch = null, bfinally = null; var body = block_(), bcatch = null, bfinally = null;

View File

@@ -127,7 +127,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
if (p instanceof AST_For if (p instanceof AST_For
|| p instanceof AST_ForIn || p instanceof AST_ForIn
|| p instanceof AST_DWLoop || p instanceof AST_DWLoop
|| p instanceof AST_Switch) { || p instanceof AST_SwitchBranch) {
node.loopcontrol_target = p.body; node.loopcontrol_target = p.body;
break; break;
} }

View File

@@ -140,7 +140,7 @@ TreeTransformer.prototype = new TreeWalker;
_(AST_Switch, function(self, tw){ _(AST_Switch, function(self, tw){
self.expression = self.expression.transform(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){ _(AST_Case, function(self, tw){