Home / Function/ inferDependenciesInFn() — react Function Reference

inferDependenciesInFn() — react Function Reference

Architecture documentation for the inferDependenciesInFn() function in InferEffectDependencies.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  ad17cc28_c934_cf1a_ce40_409d2c34592d["inferDependenciesInFn()"]
  3393f920_76eb_7dd5_b95f_ab92de6cecce["InferEffectDependencies.ts"]
  ad17cc28_c934_cf1a_ce40_409d2c34592d -->|defined in| 3393f920_76eb_7dd5_b95f_ab92de6cecce
  f523a4df_e5a4_d8d8_dbd0_ef75659ea0a5["inferDependencies()"]
  f523a4df_e5a4_d8d8_dbd0_ef75659ea0a5 -->|calls| ad17cc28_c934_cf1a_ce40_409d2c34592d
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed["visitDependency()"]
  ad17cc28_c934_cf1a_ce40_409d2c34592d -->|calls| b1bdda46_c31a_9557_b610_d2ed7c3ceaed
  97736ed1_9768_bb5a_276e_d5b04a417908["declare()"]
  ad17cc28_c934_cf1a_ce40_409d2c34592d -->|calls| 97736ed1_9768_bb5a_276e_d5b04a417908
  dce98121_98e8_b5f8_3c93_a1b31e993439["enterInnerFn()"]
  ad17cc28_c934_cf1a_ce40_409d2c34592d -->|calls| dce98121_98e8_b5f8_3c93_a1b31e993439
  fe7b2dbb_34c7_f07a_c558_c479a9c5eb1e["handleInstruction()"]
  ad17cc28_c934_cf1a_ce40_409d2c34592d -->|calls| fe7b2dbb_34c7_f07a_c558_c479a9c5eb1e
  style ad17cc28_c934_cf1a_ce40_409d2c34592d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts lines 639–675

function inferDependenciesInFn(
  fn: HIRFunction,
  context: DependencyCollectionContext,
  temporaries: ReadonlyMap<IdentifierId, ReactiveScopeDependency>,
): void {
  for (const [, block] of fn.body.blocks) {
    // 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
         */
        const innerFn = instr.value.loweredFunc.func;
        context.enterInnerFn(instr as TInstruction<FunctionExpression>, () => {
          inferDependenciesInFn(innerFn, context, temporaries);
        });
      } else {
        handleInstruction(instr, context);
      }
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does inferDependenciesInFn() do?
inferDependenciesInFn() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts.
Where is inferDependenciesInFn() defined?
inferDependenciesInFn() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts at line 639.
What does inferDependenciesInFn() call?
inferDependenciesInFn() calls 4 function(s): declare, enterInnerFn, handleInstruction, visitDependency.
What calls inferDependenciesInFn()?
inferDependenciesInFn() is called by 1 function(s): inferDependencies.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free