还原出现作用域异常的解决方案

文章介绍了如何使用JavaScript脚本来处理验证码时遇到的作用域异常问题,通过在三层路径上修改变量名以避免错误,建议在三层转一层前应用。作者提供了相关代码并在其公众号“秋裤的学习笔记”中分享更多内容。
摘要由CSDN通过智能技术生成

最近某验证码要上线了。有几个小伙伴在还原的时候会出现作用域异常的情况,导致代码无法运行。那么可以用下面这个脚本试一下,建议在三层转一层之前跑。有兴趣的可以关注我的微信公众号“秋裤的学习笔记”。

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));        
            };
        } 
       });

    }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值