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
Never hoist JSX elts referencing vars from the current scope #14536
Conversation
nicolo-ribaudo
commented
May 6, 2022
•
edited by gitpod-io
bot
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | Fixes #14363 |
Patch: Bug Fix? | |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | Yes |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
@@ -0,0 +1,10 @@ | |||
function RoutesComponent() { |
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.
The old output was
var _Component;
function RoutesComponent() {
return (
<Routes>
{(c) => {
{
const Component = c;
return _Component || (_Component = <Component />);
}
}}
</Routes>
);
}
@@ -212,7 +212,19 @@ export default declare((api, options: Options) => { | |||
HOISTED.set(path.node, targetScope); | |||
|
|||
// Only hoist if it would give us an advantage. | |||
if (targetScope === jsxScope) return; | |||
for (let currentScope = jsxScope; ; ) { |
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.
This is now more complex, because in cases like
function f() {
let Component;
{
return <Component />;
}
}
jsxScope
is the block statement while targetScope
is the function: we still do not want to hoist the element, because it's unnecessary (there are already 2-3 tests covering this).
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51873/ |