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

resolveRedundantLogicalExpressions removes nodes with assignments #104

Open
jorants opened this issue Jan 11, 2024 · 1 comment
Open

resolveRedundantLogicalExpressions removes nodes with assignments #104

jorants opened this issue Jan 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@jorants
Copy link

jorants commented Jan 11, 2024

Consider the following minimal example:

var x = 2;
if((x = 3) && 0){
    console.log("Not here")
}
console.log(x)

resolveRedundantLogicalExpressions will test the right hand of the && and conclude that the left hand is redundant as the right hand is always zero.
The result is:

var x = 2;
console.log(2);

However, the assignment should still be ran.
In general, even if the right hand evaluates to False, the left might have effect.
For example:

function f(){
    console.log("Doing important stuff")
}
var x = 2;
if(f() && 0){
    console.log("Not here")
}
console.log(x)

A good solution would be to, when a constant right hand is found, add the left hand side as a statement just above the if. If it does not have any effect than other modules can optimize it away.
So:

function f(){
    console.log("Doing important stuff")
}
var x = 2;
f(x)
if(false){
    console.log("Not here")
}
console.log(x)

in the last example.

PS: as you might notice, I am struggling with some rather evil obfuscation. Sorry for the flood of issues.

@BenBaryoPX
Copy link
Collaborator

@jorants I really appreciate all the attention you're giving the project 🙏
This is definitely a bug, and the module should verify there are no assignments in the logical expression it looks to resolve.

@BenBaryoPX BenBaryoPX added the bug Something isn't working label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants