Skip to content

Commit 15ba5bf

Browse files
committed
[compiler] transform fire calls
This is the diff with the meaningful changes. The approach is: 1. Collect fire callees and remove fire() calls, create a new binding for the useFire result 2. Update LoadLocals for captured callees to point to the useFire result 3. Update function context to reference useFire results 4. Insert useFire calls after getting to the component scope This approach aims to minimize the amount of new bindings we introduce for the function expressions to minimize bookkeeping for dependency arrays. We keep all of the LoadLocals leading up to function calls as they are and insert new instructions to load the originally captured function, call useFire, and store the result in a new promoted temporary. The lvalues that referenced the original callee are changed to point to the new useFire result. This is the minimal diff to implement the expected behavior (up to importing the useFire call, next diff) and further stacked diffs implement error handling. The rules for fire are: 1. If you use fire for a callee in the effect once you must use it for every time you call it in that effect 2. You can only use fire in a useEffect lambda/functions defined inside the useEffect lambda There is still more work to do here, like updating the effect dependency array and handling object methods --
1 parent e8faeb4 commit 15ba5bf

21 files changed

+1214
-0
lines changed

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import {validateNoJSXInTryStatement} from '../Validation/ValidateNoJSXInTryState
105105
import {propagateScopeDependenciesHIR} from '../HIR/PropagateScopeDependenciesHIR';
106106
import {outlineJSX} from '../Optimization/OutlineJsx';
107107
import {optimizePropsMethodCalls} from '../Optimization/OptimizePropsMethodCalls';
108+
import {transformFire} from '../Transform';
108109

109110
export type CompilerPipelineValue =
110111
| {kind: 'ast'; name: string; value: CodegenFunction}
@@ -198,6 +199,11 @@ function* runWithEnvironment(
198199
inferTypes(hir);
199200
yield log({kind: 'hir', name: 'InferTypes', value: hir});
200201

202+
if (env.config.enableFire) {
203+
transformFire(hir);
204+
yield log({kind: 'hir', name: 'TransformFire', value: hir});
205+
}
206+
201207
if (env.config.validateHooksUsage) {
202208
validateHooksUsage(hir);
203209
}

0 commit comments

Comments
 (0)