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
Do not hoist jsx referencing a mutable binding #10529
Conversation
@@ -32,6 +32,15 @@ const referenceVisitor = { | |||
const binding = path.scope.getBinding(path.node.name); | |||
if (!binding) return; | |||
|
|||
// we can handle reassignments only if they happen in the same scope as the declaration | |||
for (const violation of binding.constantViolations) { | |||
if (violation.scope !== binding.path.scope) { |
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.
Can't we still hoist to the level of the violation?
let foo = 'hello';
export const Component = () => {
foo = 'goodbye';
return <span>{array.map(() => <inner>{foo}</inner>}</span>;
};
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.
No, we can't. Consider this example:
let foo = 0;
export const Component = () => {
foo++;
return Promise.resolve().then(() => <span>{foo}</span>);
};
Component();
Component();
Here both the components should use 2
, but if we hoist it the first one will use 1
.
Related tests: