insertGatedFunctionDeclaration() — react Function Reference
Architecture documentation for the insertGatedFunctionDeclaration() function in Gating.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9["insertGatedFunctionDeclaration()"] 3acb56d9_57da_7e65_c06b_21b238146737["Gating.ts"] 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 -->|defined in| 3acb56d9_57da_7e65_c06b_21b238146737 11c511ca_2971_a23f_cfd6_2897f2fe1b13["applyCompiledFunctions()"] 11c511ca_2971_a23f_cfd6_2897f2fe1b13 -->|calls| 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 dd08b3af_83bb_70f8_8837_798eff915e39["addImportSpecifier()"] 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 -->|calls| dd08b3af_83bb_70f8_8837_798eff915e39 041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"] 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e 7fdb3fec_c4d5_7678_ad85_e8976e3417ad["insertAdditionalFunctionDeclaration()"] 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 -->|calls| 7fdb3fec_c4d5_7678_ad85_e8976e3417ad 24718483_4b77_f6d6_eca3_ca709b5684ec["buildFunctionExpression()"] 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 -->|calls| 24718483_4b77_f6d6_eca3_ca709b5684ec style 77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Gating.ts lines 127–195
export function insertGatedFunctionDeclaration(
fnPath: NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>,
compiled:
| t.FunctionDeclaration
| t.ArrowFunctionExpression
| t.FunctionExpression,
programContext: ProgramContext,
gating: ExternalFunction,
referencedBeforeDeclaration: boolean,
): void {
const gatingImportedName = programContext.addImportSpecifier(gating).name;
if (referencedBeforeDeclaration && fnPath.isFunctionDeclaration()) {
CompilerError.invariant(compiled.type === 'FunctionDeclaration', {
reason: 'Expected compiled node type to match input type',
description: `Got ${compiled.type} but expected FunctionDeclaration`,
loc: fnPath.node.loc ?? GeneratedSource,
});
insertAdditionalFunctionDeclaration(
fnPath,
compiled,
programContext,
gatingImportedName,
);
} else {
const gatingExpression = t.conditionalExpression(
t.callExpression(t.identifier(gatingImportedName), []),
buildFunctionExpression(compiled),
buildFunctionExpression(fnPath.node),
);
/*
* Convert function declarations to named variables *unless* this is an
* `export default function ...` since `export default const ...` is
* not supported. For that case we fall through to replacing w the raw
* conditional expression
*/
if (
fnPath.parentPath.node.type !== 'ExportDefaultDeclaration' &&
fnPath.node.type === 'FunctionDeclaration' &&
fnPath.node.id != null
) {
fnPath.replaceWith(
t.variableDeclaration('const', [
t.variableDeclarator(fnPath.node.id, gatingExpression),
]),
);
} else if (
fnPath.parentPath.node.type === 'ExportDefaultDeclaration' &&
fnPath.node.type !== 'ArrowFunctionExpression' &&
fnPath.node.id != null
) {
fnPath.insertAfter(
t.exportDefaultDeclaration(t.identifier(fnPath.node.id.name)),
);
fnPath.parentPath.replaceWith(
t.variableDeclaration('const', [
t.variableDeclarator(
t.identifier(fnPath.node.id.name),
gatingExpression,
),
]),
);
} else {
fnPath.replaceWith(gatingExpression);
}
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does insertGatedFunctionDeclaration() do?
insertGatedFunctionDeclaration() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Gating.ts.
Where is insertGatedFunctionDeclaration() defined?
insertGatedFunctionDeclaration() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Gating.ts at line 127.
What does insertGatedFunctionDeclaration() call?
insertGatedFunctionDeclaration() calls 4 function(s): addImportSpecifier, buildFunctionExpression, insertAdditionalFunctionDeclaration, invariant.
What calls insertGatedFunctionDeclaration()?
insertGatedFunctionDeclaration() is called by 1 function(s): applyCompiledFunctions.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free