_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);
});
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)
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();
case "switch":
return new AST_Switch({
expression : parenthesised(),
- body : switch_block_()
+ body : switch_body_()
});
case "throw":
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", "}")) {
}
}
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;
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;
}
_(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){