Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

逗号表达式处理 else for 语法时候取不到body bug #1

Open
lee003 opened this issue Apr 9, 2022 · 3 comments
Open

逗号表达式处理 else for 语法时候取不到body bug #1

lee003 opened this issue Apr 9, 2022 · 3 comments

Comments

@lee003
Copy link

lee003 commented Apr 9, 2022

_body.splice(_body.indexOf(_node), 0, seqs[ids])

这段代码在处理逗号表达式的时候,如果碰到 else for 这种写法 由于else 的内容没有用大括号包裹, 会导致在拿for的父对象的body 插 AssignmentExpression 的时候 取不到 body 导致报错, 感觉应该对所有的 else 都先对 alternate 检查 如果 不是 BlockStatement
都加上一个BlockStatement 包裹住
下面为测试代码
if (void 0 !== e[r(n(1163, 1110))]) { u = r(""); } else for (var f = [r("ESEAPx0Y"), r(n(1230, 1247)), r("Czc"), r("CQ")], v = 0; v < f[r(n(1346, 1251))]; v++) { if (void 0 !== e[f[v] + r("Li0GMBEC")]) { u = f[v]; break; } }

@sml2h3
Copy link
Owner

sml2h3 commented Apr 11, 2022

好的,这个我会检查一下,因为在这之前应该有个修复if else的block的模块,可以将没有被block包裹的部分用block包裹起来,你可以尝试在执行[VariableDeclaratorFix之前先行执行一下IfWithExpressFix

@lee003
Copy link
Author

lee003 commented Apr 11, 2022

IfWithExpressFix 做了两种类型的判断 isExpressionStatement isReturnStatement 不晓得这里是否有特殊情况 我直接改成了

if (types.isIfStatement(node)){
        if (node.consequent != null && !types.isBlockStatement(node.consequent)){
            path.node.consequent = types.blockStatement([node.consequent])
        }
        else if(node.consequent === null){
            path.node.consequent = types.blockStatement([])
        }
        
        if (node.alternate != null && !types.isBlockStatement(node.alternate)){
            path.node.alternate = types.blockStatement([node.alternate])
        }
    }

在我处理的代码里面 可以运行。

@sml2h3
Copy link
Owner

sml2h3 commented Apr 13, 2022

好的,我看看

IfWithExpressFix 做了两种类型的判断 isExpressionStatement isReturnStatement 不晓得这里是否有特殊情况 我直接改成了

if (types.isIfStatement(node)){
        if (node.consequent != null && !types.isBlockStatement(node.consequent)){
            path.node.consequent = types.blockStatement([node.consequent])
        }
        else if(node.consequent === null){
            path.node.consequent = types.blockStatement([])
        }
        
        if (node.alternate != null && !types.isBlockStatement(node.alternate)){
            path.node.alternate = types.blockStatement([node.alternate])
        }
    }

在我处理的代码里面 可以运行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants