-
Notifications
You must be signed in to change notification settings - Fork 620
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
Unexpected behavior in constant-folding-plugin when using dev=false #208
Comments
cc/ @mjesun I think you fixed this one, but the fix may not be available on metro 0.38.x If that's the case, can you check if it's easy to cherry pick? |
That's a tricky one, and you're right, the removal of the I've created an issue in Babel (babel/babel#8411), although it's not the first one I've already opened in regards to wrong evaluations (see babel/babel#8017). |
Thanks for the update @mjesun |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When I declare (using
var
) a variable inside of a block, then check its 'truthy'-ness in a conditional outside that block, some code paths are removed.Simplified example:
The constant-folding-plugin transforms this into:
If I move the
doesExist
declaration to be outside of the if statement, then the plugin outputs what I'd expect.Updated input:
Transformed output:
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can
yarn install
andyarn test
.What is the expected behavior?
Variables declared with
var
should be treated initially as undefined within a function scope, even when initialization occurs on the same line. Maybe this would only have to be true when a variable is declared and initialized within a function's inner-block. Given the above input, I would expect the output to look something like:Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
Using metro 0.38.3 with react-native 0.56.0. yarn version 1.7.0, npm version 6.2.0, node version 8.11.2.
The text was updated successfully, but these errors were encountered: