collectDependencies() — react Function Reference
Architecture documentation for the collectDependencies() function in PropagateScopeDependenciesHIR.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 5b709ffb_65e9_2125_d608_a351c667cd6c["collectDependencies()"] 76832af2_c0a7_f31c_e448_af5664da4b88["PropagateScopeDependenciesHIR.ts"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|defined in| 76832af2_c0a7_f31c_e448_af5664da4b88 55f3fce3_0db5_e260_b549_d5a721561462["propagateScopeDependenciesHIR()"] 55f3fce3_0db5_e260_b549_d5a721561462 -->|calls| 5b709ffb_65e9_2125_d608_a351c667cd6c 97736ed1_9768_bb5a_276e_d5b04a417908["declare()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| 97736ed1_9768_bb5a_276e_d5b04a417908 d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2 462d4884_0290_ceb1_b76b_bfb25c49a3cc["empty()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| 462d4884_0290_ceb1_b76b_bfb25c49a3cc e905b26b_28fa_658a_742c_b1836921c75b["recordScopes()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| e905b26b_28fa_658a_742c_b1836921c75b ad463e10_0394_9f8b_1e38_c1e95a00ff97["enterScope()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| ad463e10_0394_9f8b_1e38_c1e95a00ff97 fa34629f_c89e_a9bf_4c20_ec6a2b54a55c["exitScope()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| fa34629f_c89e_a9bf_4c20_ec6a2b54a55c b1bdda46_c31a_9557_b610_d2ed7c3ceaed["visitDependency()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| b1bdda46_c31a_9557_b610_d2ed7c3ceaed dce98121_98e8_b5f8_3c93_a1b31e993439["enterInnerFn()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| dce98121_98e8_b5f8_3c93_a1b31e993439 fe7b2dbb_34c7_f07a_c558_c479a9c5eb1e["handleInstruction()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| fe7b2dbb_34c7_f07a_c558_c479a9c5eb1e fda4793f_ce94_c900_cd2a_6dbe1a730c02["isDeferredDependency()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| fda4793f_ce94_c900_cd2a_6dbe1a730c02 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| 41232a25_deb6_6e83_05a8_ae9f961656f7 b9659720_c932_ebd9_335f_682c49188a34["visitOperand()"] 5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| b9659720_c932_ebd9_335f_682c49188a34 style 5b709ffb_65e9_2125_d608_a351c667cd6c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts lines 747–834
function collectDependencies(
fn: HIRFunction,
usedOutsideDeclaringScope: ReadonlySet<DeclarationId>,
temporaries: ReadonlyMap<IdentifierId, ReactiveScopeDependency>,
processedInstrsInOptional: ReadonlySet<Instruction | Terminal>,
): Map<ReactiveScope, Array<ReactiveScopeDependency>> {
const context = new DependencyCollectionContext(
usedOutsideDeclaringScope,
temporaries,
processedInstrsInOptional,
);
for (const param of fn.params) {
if (param.kind === 'Identifier') {
context.declare(param.identifier, {
id: makeInstructionId(0),
scope: empty(),
});
} else {
context.declare(param.place.identifier, {
id: makeInstructionId(0),
scope: empty(),
});
}
}
const scopeTraversal = new ScopeBlockTraversal();
const handleFunction = (fn: HIRFunction): void => {
for (const [blockId, block] of fn.body.blocks) {
scopeTraversal.recordScopes(block);
const scopeBlockInfo = scopeTraversal.blockInfos.get(blockId);
if (scopeBlockInfo?.kind === 'begin') {
context.enterScope(scopeBlockInfo.scope);
} else if (scopeBlockInfo?.kind === 'end') {
context.exitScope(scopeBlockInfo.scope, scopeBlockInfo.pruned);
}
// Record referenced optional chains in phis
for (const phi of block.phis) {
for (const operand of phi.operands) {
const maybeOptionalChain = temporaries.get(operand[1].identifier.id);
if (maybeOptionalChain) {
context.visitDependency(maybeOptionalChain);
}
}
}
for (const instr of block.instructions) {
if (
instr.value.kind === 'FunctionExpression' ||
instr.value.kind === 'ObjectMethod'
) {
context.declare(instr.lvalue.identifier, {
id: instr.id,
scope: context.currentScope,
});
/**
* Recursively visit the inner function to extract dependencies there
*/
const innerFn = instr.value.loweredFunc.func;
context.enterInnerFn(
instr as
| TInstruction<FunctionExpression>
| TInstruction<ObjectMethod>,
() => {
handleFunction(innerFn);
},
);
} else {
handleInstruction(instr, context);
}
}
if (
!context.isDeferredDependency({
kind: HIRValue.Terminal,
value: block.terminal,
})
) {
for (const place of eachTerminalOperand(block.terminal)) {
context.visitOperand(place);
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does collectDependencies() do?
collectDependencies() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts.
Where is collectDependencies() defined?
collectDependencies() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts at line 747.
What does collectDependencies() call?
collectDependencies() calls 12 function(s): declare, eachTerminalOperand, empty, enterInnerFn, enterScope, exitScope, handleInstruction, isDeferredDependency, and 4 more.
What calls collectDependencies()?
collectDependencies() is called by 1 function(s): propagateScopeDependenciesHIR.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free