/*
先遍历节点,记录所有index, map的key是when的index, 值是这个when对应的要执行的代码对应的index
map = {
0: [1, 2, 3],
4: [5, 6],
7: [8],
9: [10, 11]
}
*/
var map = {};
var whenIndexList = [] // 记录所有when的index
var curWhenIndex = 0;
for (var i = 0; i < statements.length; i++) {
map[curWhenIndex] = [];
如果没有匹配到when, map[curWhenIndex].push(i);
如果匹配到when,curWhenIndex = i;
}
// 遍历map来拼接
var whens = Object.keys(map);
var str = '';
for (var i = 0; i < whens.length; i++) {
var notWhen = map[whens[i]];
for (var j = 0; j < notWhen.length; j++) {
str += statements[notWhen[j]];
}
}