1. while ===号
while (1) { _$LT = _$65[4][_$VT++]; if (_$LT < 4) { if (_$LT === 1) { _$VT += 1; } else if (_$LT === 4) { _$1S(_$Ql); } else if (_$LT === 0) { _$GA = String["prototype"]["indexOf"]["call"](_$Ql, "a=candidate:") === 0; } else if (_$LT === 2) { "return"; } else { _$VT += -4; } } else { if (_$LT === 5) { _$1S(_$Ql); } else { if (!_$GA) _$VT += 1; } } } ////////////////////////////////////////////// while (1) { _$LT = _$65[4][_$VT++]; switch (_$LT) { case 0: _$GA = String["prototype"]["indexOf"]["call"](_$Ql, "a=candidate:") === 0; break; case 1: _$VT += 1; break; case 2: "return"; break; case 3: if (!_$GA) _$VT += 1; break; case 4: _$1S(_$Ql); break; case 5: _$1S(_$Ql); break; } } ///////////////////////////////////////////////////////////// let _path = "" function collectSwitchCase(WhilePath, name) { // if处理 let ifNodes = []; WhilePath.traverse({ "IfStatement"(path) {//遍历所有的ifStatement; // console.log(path.get("consequent").toString()); // console.log("1111111111111111111111111111111") let {test, consequent, alternate} = path.node; //获取子节点 let {left, operator, right} = test; // 必定是BinaryExpression if (!types.isIdentifier(left, {name: name}) || operator != '===' || !types.isNumericLiteral(right)) {//条件过滤 _path = path; return; } ifNodes[right.value] = consequent.body; //保存整个body,记得生成switchCase节点的时候加上break节点。 if (!types.isIfStatement(alternate)) { if (_path.node.test.right.value < ifNodes.length) { ifNodes[_path.node.test.right.value -1] = alternate.body; //最后一个else,其实就是上一个else-if 的 test.right的值 } else { ifNodes[ifNodes.length] = alternate.body; //最后一个else,其实就是上一个else-if 的 test.right的值 } } }, }) return ifNodes; } const visitor1 = { // if处理 "WhileStatement"(path) { let {test, body} = path.node; if (!types.isNumericLiteral(test, {value: 1}) || body.body.length != 2) { return; } let blockBody = body.body; if (!types.isExpressionStatement(blockBody[0])) {//条件过滤 return; } let name = blockBody[1].test.left.name; //变量名 let ifNodes = collectSwitchCase(path, name); //收集case if (ifNodes.length == 0) return; //无case,直接返回。 let len = ifNodes.length; for (let i = 0; i < len; i++) { ifNodes[i].push(types.BreakStatement()); ifNodes[i] = types.SwitchCase(test = types.valueToNode(i), consequent = ifNodes[i]); //生成SwitchCase节点 } let switchNode = types.SwitchStatement(blockBody[1].test.left, ifNodes); //生成SwitchCase节点 path.node.body.body[1] = switchNode; }, } traverse(ast, visitor1);
标签:body,ifNodes,ast,代码,else,let,还原,test,path From: https://www.cnblogs.com/yoyo1216/p/17648847.html