processFn() — react Function Reference
Architecture documentation for the processFn() function in Program.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD db0bec13_2016_3880_d2b9_adcd797cdf2c["processFn()"] 9aa4477d_960b_1ea1_b6d9_36076aaa70bd["Program.ts"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|defined in| 9aa4477d_960b_1ea1_b6d9_36076aaa70bd 1c9af54b_10e9_8985_e772_1f517e46c560["compileProgram()"] 1c9af54b_10e9_8985_e772_1f517e46c560 -->|calls| db0bec13_2016_3880_d2b9_adcd797cdf2c 931a40c4_9b75_45bd_9aff_f4c45e92c16d["tryFindDirectiveEnablingMemoization()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| 931a40c4_9b75_45bd_9aff_f4c45e92c16d 4f591349_3d90_e4e5_51a6_a3b7ad077584["handleError()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| 4f591349_3d90_e4e5_51a6_a3b7ad077584 bfe4a215_80e5_3bbc_bd03_14596ae8b8ab["findDirectiveDisablingMemoization()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| bfe4a215_80e5_3bbc_bd03_14596ae8b8ab b463b9d1_ce95_79dd_d7b2_7be04016ee66["tryCompileFunction()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| b463b9d1_ce95_79dd_d7b2_7be04016ee66 d3795732_d882_4f46_a959_cba0c8d5bcb9["logError()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| d3795732_d882_4f46_a959_cba0c8d5bcb9 b477b62a_df15_0fe0_3f9b_b80ce28b083b["retryCompileFunction()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| b477b62a_df15_0fe0_3f9b_b80ce28b083b 57b4d928_ecd2_92c9_b55b_ce5e00d0fba4["logEvent()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| 57b4d928_ecd2_92c9_b55b_ce5e00d0fba4 f0a04cba_f197_dc31_243c_26243c07a3a4["isErr()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| f0a04cba_f197_dc31_243c_26243c07a3a4 7dd8eefb_2237_6426_9d5d_a2c0267dc003["unwrapErr()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| 7dd8eefb_2237_6426_9d5d_a2c0267dc003 c0248f71_d55d_c77f_df47_00e95f877287["unwrapOr()"] db0bec13_2016_3880_d2b9_adcd797cdf2c -->|calls| c0248f71_d55d_c77f_df47_00e95f877287 style db0bec13_2016_3880_d2b9_adcd797cdf2c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts lines 584–704
function processFn(
fn: BabelFn,
fnType: ReactFunctionType,
programContext: ProgramContext,
outputMode: CompilerOutputMode,
): null | CodegenFunction {
let directives: {
optIn: t.Directive | null;
optOut: t.Directive | null;
};
if (fn.node.body.type !== 'BlockStatement') {
directives = {
optIn: null,
optOut: null,
};
} else {
const optIn = tryFindDirectiveEnablingMemoization(
fn.node.body.directives,
programContext.opts,
);
if (optIn.isErr()) {
/**
* If parsing opt-in directive fails, it's most likely that React Compiler
* was not tested or rolled out on this function. In that case, we handle
* the error and fall back to the safest option which is to not optimize
* the function.
*/
handleError(optIn.unwrapErr(), programContext, fn.node.loc ?? null);
return null;
}
directives = {
optIn: optIn.unwrapOr(null),
optOut: findDirectiveDisablingMemoization(
fn.node.body.directives,
programContext.opts,
),
};
}
let compiledFn: CodegenFunction;
const compileResult = tryCompileFunction(
fn,
fnType,
programContext,
outputMode,
);
if (compileResult.kind === 'error') {
if (directives.optOut != null) {
logError(compileResult.error, programContext, fn.node.loc ?? null);
} else {
handleError(compileResult.error, programContext, fn.node.loc ?? null);
}
if (outputMode === 'client') {
const retryResult = retryCompileFunction(fn, fnType, programContext);
if (retryResult == null) {
return null;
}
compiledFn = retryResult;
} else {
return null;
}
} else {
compiledFn = compileResult.compiledFn;
}
/**
* If 'use no forget/memo' is present and we still ran the code through the
* compiler for validation, log a skip event and don't mutate the babel AST.
* This allows us to flag if there is an unused 'use no forget/memo'
* directive.
*/
if (
programContext.opts.ignoreUseNoForget === false &&
directives.optOut != null
) {
programContext.logEvent({
kind: 'CompileSkip',
fnLoc: fn.node.body.loc ?? null,
reason: `Skipped due to '${directives.optOut.value}' directive.`,
loc: directives.optOut.loc ?? null,
});
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does processFn() do?
processFn() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts.
Where is processFn() defined?
processFn() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts at line 584.
What does processFn() call?
processFn() calls 10 function(s): findDirectiveDisablingMemoization, handleError, isErr, logError, logEvent, retryCompileFunction, tryCompileFunction, tryFindDirectiveEnablingMemoization, and 2 more.
What calls processFn()?
processFn() is called by 1 function(s): compileProgram.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free