最近某验证码要上线了。有几个小伙伴在还原的时候会出现作用域异常的情况,导致代码无法运行。那么可以用下面这个脚本试一下,建议在三层转一层之前跑。有兴趣的可以关注我的微信公众号“秋裤的学习笔记”。
index = 0
const myUnaryExpressionVar = {
UnaryExpression(path){
if(!path.parentPath || !path.parentPath.parentPath.isSwitchCase()) return;
if(path.node.operator != "!" ||
!types.isCallExpression(path.node.argument) ||
!types.isFunctionExpression(path.node.argument.callee) ) return;
index+=1;
path.get("argument.callee.body").traverse({
VariableDeclaration(path_){
if(path_.parentPath.isForStatement()) return;
for(let vartor of path_.get("declarations")){
if(vartor.node.id.name.indexOf("_277777")!=-1) continue;
const binding = path_.scope.getBinding(vartor.node.id.name);
if(!binding) continue;
new_name = "_277777"+index+"_"+vartor.node.id.name;
let referPaths = binding.referencePaths;
for(let referPath of referPaths){
referPath.replaceInline(types.Identifier(new_name));
};
console.log(vartor.node.id.name,"=====>>",new_name);
vartor.get("id").replaceInline(types.Identifier(new_name));
};
}
});
}
};