more cleanup (dropped AST_SwitchBlock)
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
13
lib/parse.js
13
lib/parse.js
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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){
|
||||||
|
|||||||
Reference in New Issue
Block a user