mapStatements(stmts, nodeStmts);
return stmts;
}
private JsSwitch mapSwitchStatement(Node switchNode) throws JsParserException {
JsSwitch toSwitch = new JsSwitch();
// The switch expression.
//
Node fromSwitchExpr = switchNode.getFirstChild();
toSwitch.setExpr(mapExpression(fromSwitchExpr));
// The members.
//
Node fromMember = fromSwitchExpr.getNext();
while (fromMember != null) {
if (fromMember.getType() == TokenStream.CASE) {
JsCase toCase = new JsCase();
// Set the case expression. In JS, this can be any expression.
//
Node fromCaseExpr = fromMember.getFirstChild();
toCase.setCaseExpr(mapExpression(fromCaseExpr));
// Set the case statements.
//
Node fromCaseBlock = fromCaseExpr.getNext();
mapStatements(toCase.getStmts(), fromCaseBlock);
// Attach the case to the switch.
//
toSwitch.getCases().add(toCase);
} else {
// This should be the only default statement.
// If more than one is present, we keep the last one.
//
assert (fromMember.getType() == TokenStream.DEFAULT);
JsDefault toDefault = new JsDefault();
// Set the default statements.
//
Node fromDefaultBlock = fromMember.getFirstChild();
mapStatements(toDefault.getStmts(), fromDefaultBlock);
// Attach the default to the switch.
//
toSwitch.getCases().add(toDefault);
}
fromMember = fromMember.getNext();
}
return toSwitch;