Home / Function/ collectTemporariesSidemapImpl() — react Function Reference

collectTemporariesSidemapImpl() — react Function Reference

Architecture documentation for the collectTemporariesSidemapImpl() function in PropagateScopeDependenciesHIR.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  bd383390_a354_8863_d439_cafcd9e7a730["collectTemporariesSidemapImpl()"]
  76832af2_c0a7_f31c_e448_af5664da4b88["PropagateScopeDependenciesHIR.ts"]
  bd383390_a354_8863_d439_cafcd9e7a730 -->|defined in| 76832af2_c0a7_f31c_e448_af5664da4b88
  5c398df4_9a90_b7aa_6be6_ddff9be0b519["collectTemporariesSidemap()"]
  5c398df4_9a90_b7aa_6be6_ddff9be0b519 -->|calls| bd383390_a354_8863_d439_cafcd9e7a730
  db4024a2_9da3_3c5b_55ec_ad3da742fbea["getProperty()"]
  bd383390_a354_8863_d439_cafcd9e7a730 -->|calls| db4024a2_9da3_3c5b_55ec_ad3da742fbea
  9383934c_0b46_008d_a075_fa264ddb243d["isLoadContextMutable()"]
  bd383390_a354_8863_d439_cafcd9e7a730 -->|calls| 9383934c_0b46_008d_a075_fa264ddb243d
  style bd383390_a354_8863_d439_cafcd9e7a730 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts lines 272–336

function collectTemporariesSidemapImpl(
  fn: HIRFunction,
  usedOutsideDeclaringScope: ReadonlySet<DeclarationId>,
  temporaries: Map<IdentifierId, ReactiveScopeDependency>,
  innerFnContext: {instrId: InstructionId} | null,
): void {
  for (const [_, block] of fn.body.blocks) {
    for (const {value, lvalue, id: origInstrId} of block.instructions) {
      const instrId =
        innerFnContext != null ? innerFnContext.instrId : origInstrId;
      const usedOutside = usedOutsideDeclaringScope.has(
        lvalue.identifier.declarationId,
      );

      if (value.kind === 'PropertyLoad' && !usedOutside) {
        if (
          innerFnContext == null ||
          temporaries.has(value.object.identifier.id)
        ) {
          /**
           * All dependencies of a inner / nested function must have a base
           * identifier from the outermost component / hook. This is because the
           * compiler cannot break an inner function into multiple granular
           * scopes.
           */
          const property = getProperty(
            value.object,
            value.property,
            false,
            temporaries,
          );
          temporaries.set(lvalue.identifier.id, property);
        }
      } else if (
        (value.kind === 'LoadLocal' || isLoadContextMutable(value, instrId)) &&
        lvalue.identifier.name == null &&
        value.place.identifier.name !== null &&
        !usedOutside
      ) {
        if (
          innerFnContext == null ||
          fn.context.some(
            context => context.identifier.id === value.place.identifier.id,
          )
        ) {
          temporaries.set(lvalue.identifier.id, {
            identifier: value.place.identifier,
            reactive: value.place.reactive,
            path: [],
          });
        }
      } else if (
        value.kind === 'FunctionExpression' ||
        value.kind === 'ObjectMethod'
      ) {
        collectTemporariesSidemapImpl(
          value.loweredFunc.func,
          usedOutsideDeclaringScope,
          temporaries,
          innerFnContext ?? {instrId},
        );
      }
    }
  }
}

Subdomains

Frequently Asked Questions

What does collectTemporariesSidemapImpl() do?
collectTemporariesSidemapImpl() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts.
Where is collectTemporariesSidemapImpl() defined?
collectTemporariesSidemapImpl() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts at line 272.
What does collectTemporariesSidemapImpl() call?
collectTemporariesSidemapImpl() calls 2 function(s): getProperty, isLoadContextMutable.
What calls collectTemporariesSidemapImpl()?
collectTemporariesSidemapImpl() is called by 1 function(s): collectTemporariesSidemap.

Analyze Your Own Codebase

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

Try Supermodel Free