-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 branch follows the wrong if statement #3716
Comments
This is a tricky one. The best I could think of is: |
Or just add braces to the parent IfStatement's consequent in that case. Back in the day for buble braces were added to all blockless if/else/loops to avoid similar problems. It's not worth the hassle to special case every blockless scenario. |
Would someone mind explaining briefly what the bug is? I've looked at it, but I can't say for sure I understand how and why Rollup is modifying the code here. Is it because the |
Simplified runnable example:
Expected:
Actual incorrect result:
After the side-effect-free
But when braces are introduced in blockless
|
Another bug variant involving an Given:
Expected:
Actual incorrect result:
I think that the buble blockless body heuristic would be a low-risk fix for these types of bugs. |
Ok I see, and thanks for the additional examples. So solutions I see and understand so far that are easy enough to implement:
I think the last would cause the least noise. |
(1) is easiest to implement and has fewer potential points of failure. |
(1) and (3) would also be my favourite option but it is technical very difficult as the parent would need to change its rendering because of a condition on a remote child, that is tricky to get right. I have now a version of (3) that works quite nicely, I'll put it up shortly. |
See #3725 |
Whatever works I guess. Minifiers will drop the empty else clause in any event. |
I got this bug after upgrade to history v5 (cc @mjackson). Pop state cannot be called in production because rollup breaks else branch here https://github.com/ReactTraining/history/blob/master/packages/history/index.ts#L427-L459
Expected Behavior
warning() should be fired according to outer condition not the inner one
Actual Behavior
Else branch follows the wrong if statement
The text was updated successfully, but these errors were encountered: