-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
don't remove impure reachable parts of logical expressions #160
Conversation
path.replaceWith(node.left); | ||
} | ||
} else if (node.operator === "||") { | ||
if (left.evaluateTruthy() === false && left.isPure()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops, that's not right :P
I think I fixed my logic mistakes. I'm not entirely sure if all the branches I put in are necessary or if |
expect(transform(source)).toBe(source); | ||
|
||
source = unpad(` | ||
alert(func() || true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we remove true
from the RHS here since it has no side effects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a = foo() || true
. a
should be true
if foo()
is truthy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if func()
is falsy, func() || true
would still evaluate to true
, so the RHS is significant for the final value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, of course. Missed it.
An attempt at dealing with #159.
Impure statements like function calls were removed from the right-hand side of
&&
expressions if they were inferred to return a falsy value (e.g. when using thevoid
operator).This patch checks if the thing to be removed is pure. There's a lot more manual checking involved but it also simplifies more stuff.