mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Enables support for assignment expressions in value blocks (which includes in loop init/test/update blocks). This was pretty straightforward, the main changes are: * During PropagateScopeDependencies, we currently record scope reassignments based on `Identifier` object identity. In the case where a variable is reassigned in multiple control-flow paths of a value block, however, there can be multiple object identities. So we now de-dupe reassignments based on identifier id. * MergeOverlappingScopes now treats value blocks as regular blocks, allowing it to correctly merge scopes from the value with other scopes from the outer block. Otherwise this is mostly just lots of tests. Note that there is an outstanding todo, which is that we currently error for ternaries and logicals whose value is unused (eg `cond ? (x = 1) : null`). I'll address that in a follow-up.
test262
@ 83a46bfe0e
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