mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
5f2833bd5c
Refactors Codegen to extract the core "visit IR as a tree" logic separately from the code to emit JS: * `HIRTreeVisitor` is a new helper that visits the HIR as a tree. You call `visitTree(ir, yourVisitor)` and it drives visiting of the IR, tracking blocks and scopes and calling methods as appropriate. * `Codegen` is now implemented as a Visitor implementation. For example `enterBlock()` creates an empty `Array<t.Statement>`, `leaveBlock()` wraps that in a `t.BlockStatement`, etc. * `printHIRTree()` is a new IR printer (implemented as a visitor) that prints the HIR in tree form, so it retains the original shape of the code but with each block replaced with its IR equivalent.
test262
@ 60e41ed3cb
React Forget
React Forget is an experimental Babel plugin to automatically memoize React Hooks and Components.
Development
# tsc --watch
$ yarn dev
# in another terminal window
$ yarn test --watch
Notes
An overview of the implementation can be found in the Architecture Overview.
This transform
- needs plugin-syntax-jsx as a dependency to inherit the syntax from.
- should be run before plugin-transform-react-jsx
- assume the enforcement of rules of hooks, i.e.
- only call hooks from React functions
- only call hooks at the top level
- https://www.npmjs.com/package/eslint-plugin-react-hooks
Scaffolding
- https://github.com/facebook/flow/tree/master/packages/babel-plugin-transform-flow-enums
- https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-jsx/src/create-plugin.ts
Reference