* @param scope
* 语句子节点生存域
*/
public SwitchStatement(Node node, ScriptOrFnNode root, Scope scope) {
super(node);
Node child = node.getFirstChild();
target = addExpression(child, root, scope);
while ((child = child.getNext()) != null) {
CaseItem item = new CaseItem();
item.value = addExpression(child.getFirstChild(), root, scope);
items.add(item);
}
node = node.getNext();
for (CaseItem item : items) {
node = node.getNext().getNext();
item.statement = addStatement(node, root, scope);
}
if (items.size() > 0) {
CaseItem item = items.get(items.size() - 1);
if (item.statement instanceof BlockStatement) {
StatementList statements = ((BlockStatement) item.statement)
.getStatementList();
IStatement statement = statements.get(statements.size() - 1);
if (statement instanceof ControlStatement
&& ((ControlStatement) statement).getType() == Token.BREAK) {
statements.remove(statements.size() - 1);
}
}
}
Node nextNode = node.getNext().getNext();
if (nextNode != null) {
node = nextNode.getNext();
if (node.getType() == Token.TARGET && nextNode.getType() == Token.BLOCK) {
CaseItem item = new CaseItem();
item.statement = addStatement(nextNode, root, scope);
items.add(item);
nextNode = node.getNext();
}