Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hoisting support for ref components
Summary: This adds hoisting logic to components with refs. This is needed since the `ref` transform adds a `const ... = React.forwardRef(...);`. This inserted variable declaration has different hoisting semantics vs a function declaration of a component. So this change finds any references and hoists the statement above the first reference. e.g. ``` Bar; unrelated; Bar; component Bar(foo: string, ref: Ref) {} ``` Transforms into: ``` const Bar = React.forwardRef(Bar_withRef); Bar; unrelated; Bar; function Bar_withRef({ foo }: $ReadOnly<{...}>, ref: Ref): React.Node {}" ``` The way this works is when a component statement is found with a `ref` param we walk from the first statement to the component traversing the full tree, if a component reference is found we abort walking and return the position. Then inject the forwardRef statement before that position. Reviewed By: mvitousek, jbrown215 Differential Revision: D48247491 fbshipit-source-id: 77714765f04bba0cb369389e364b0981a9075419
- Loading branch information