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
Components get hoisted outside of valid scope #8310
Comments
Hey @raulpineda! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
I wonder if this comment is wrong: the babel hoister makes a mistake when hoisting it. If the used prop is already |
I can confirm this still happens on Babel 7 too. Here's a minimal reproducible example using just @babel/preset-react and @babel/plugin-transform-react-constant-elements:
Output:
For me, it's happening whenever there is a closure, and the element only references variables declared outside of the function. |
It looks like this might be fixed by #10529? |
Yup, thanks! |
Bug Report
Current Behavior
Using plugin-transform-react-constant-elements, when trying to render a component inside a map, the ref gets hoisted outside of the valid scope if said component doesn't include the current identity or tries to access a property of an object directly
Input Code
gets transformed into
Expected behavior/code
I would expect both cases to create the reference inside the
if(isLoaded) {}
block, sinceproblematicProp
is only declared thereBabel Configuration (.babelrc, package.json, cli command)
Environment
loader
The text was updated successfully, but these errors were encountered: