Home / Function/ handleAssignment() — react Function Reference

handleAssignment() — react Function Reference

Architecture documentation for the handleAssignment() function in FindContextIdentifiers.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  fa714f50_9834_58a4_a05d_7f849864a528["handleAssignment()"]
  a8683125_42ac_e9cd_3e85_739b8a5c0c4c["FindContextIdentifiers.ts"]
  fa714f50_9834_58a4_a05d_7f849864a528 -->|defined in| a8683125_42ac_e9cd_3e85_739b8a5c0c4c
  a6cfd201_2bfc_7a25_c3dd_0460f1930354["findContextIdentifiers()"]
  a6cfd201_2bfc_7a25_c3dd_0460f1930354 -->|calls| fa714f50_9834_58a4_a05d_7f849864a528
  14f2e51a_d755_814e_2f56_72d3ed119459["getOrInsertDefault()"]
  fa714f50_9834_58a4_a05d_7f849864a528 -->|calls| 14f2e51a_d755_814e_2f56_72d3ed119459
  82ebbfd2_1072_cfb6_94ab_f823c0fb2dd0["nonNull()"]
  fa714f50_9834_58a4_a05d_7f849864a528 -->|calls| 82ebbfd2_1072_cfb6_94ab_f823c0fb2dd0
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  fa714f50_9834_58a4_a05d_7f849864a528 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64["throwTodo()"]
  fa714f50_9834_58a4_a05d_7f849864a528 -->|calls| cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64
  style fa714f50_9834_58a4_a05d_7f849864a528 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts lines 138–223

function handleAssignment(
  currentFn: BabelFunction | null,
  identifiers: Map<t.Identifier, IdentifierInfo>,
  lvalPath: NodePath<t.LVal>,
): void {
  /*
   * Find all reassignments to identifiers declared outside of currentFn
   * This closely follows destructuring assignment assumptions and logic in BuildHIR
   */
  const lvalNode = lvalPath.node;
  switch (lvalNode.type) {
    case 'Identifier': {
      const path = lvalPath as NodePath<t.Identifier>;
      const name = path.node.name;
      const binding = path.scope.getBinding(name);
      if (binding == null) {
        break;
      }
      const state = getOrInsertDefault(identifiers, binding.identifier, {
        ...DEFAULT_IDENTIFIER_INFO,
      });
      state.reassigned = true;

      if (currentFn != null) {
        const bindingAboveLambdaScope = currentFn.scope.parent.getBinding(name);

        if (binding === bindingAboveLambdaScope) {
          state.reassignedByInnerFn = true;
        }
      }
      break;
    }
    case 'ArrayPattern': {
      const path = lvalPath as NodePath<t.ArrayPattern>;
      for (const element of path.get('elements')) {
        if (nonNull(element)) {
          handleAssignment(currentFn, identifiers, element);
        }
      }
      break;
    }
    case 'ObjectPattern': {
      const path = lvalPath as NodePath<t.ObjectPattern>;
      for (const property of path.get('properties')) {
        if (property.isObjectProperty()) {
          const valuePath = property.get('value');
          CompilerError.invariant(valuePath.isLVal(), {
            reason: `[FindContextIdentifiers] Expected object property value to be an LVal, got: ${valuePath.type}`,
            loc: valuePath.node.loc ?? GeneratedSource,
          });
          handleAssignment(currentFn, identifiers, valuePath);
        } else {
          CompilerError.invariant(property.isRestElement(), {
            reason: `[FindContextIdentifiers] Invalid assumptions for babel types.`,
            loc: property.node.loc ?? GeneratedSource,
          });
          handleAssignment(currentFn, identifiers, property);
        }
      }
      break;
    }
    case 'AssignmentPattern': {
      const path = lvalPath as NodePath<t.AssignmentPattern>;
      const left = path.get('left');
      handleAssignment(currentFn, identifiers, left);
      break;
    }
    case 'RestElement': {
      const path = lvalPath as NodePath<t.RestElement>;
      handleAssignment(currentFn, identifiers, path.get('argument'));
      break;
    }
    case 'MemberExpression': {
      // Interior mutability (not a reassign)
      break;
    }
    default: {
      CompilerError.throwTodo({
        reason: `[FindContextIdentifiers] Cannot handle Object destructuring assignment target ${lvalNode.type}`,
        description: null,
        loc: lvalNode.loc ?? GeneratedSource,

Subdomains

Frequently Asked Questions

What does handleAssignment() do?
handleAssignment() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts.
Where is handleAssignment() defined?
handleAssignment() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts at line 138.
What does handleAssignment() call?
handleAssignment() calls 4 function(s): getOrInsertDefault, invariant, nonNull, throwTodo.
What calls handleAssignment()?
handleAssignment() is called by 1 function(s): findContextIdentifiers.

Analyze Your Own Codebase

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

Try Supermodel Free