Home / Function/ findContextIdentifiers() — react Function Reference

findContextIdentifiers() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  a6cfd201_2bfc_7a25_c3dd_0460f1930354["findContextIdentifiers()"]
  a8683125_42ac_e9cd_3e85_739b8a5c0c4c["FindContextIdentifiers.ts"]
  a6cfd201_2bfc_7a25_c3dd_0460f1930354 -->|defined in| a8683125_42ac_e9cd_3e85_739b8a5c0c4c
  9e9f9b6d_740c_69bf_979d_bba888d70105["run()"]
  9e9f9b6d_740c_69bf_979d_bba888d70105 -->|calls| a6cfd201_2bfc_7a25_c3dd_0460f1930354
  fa714f50_9834_58a4_a05d_7f849864a528["handleAssignment()"]
  a6cfd201_2bfc_7a25_c3dd_0460f1930354 -->|calls| fa714f50_9834_58a4_a05d_7f849864a528
  cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64["throwTodo()"]
  a6cfd201_2bfc_7a25_c3dd_0460f1930354 -->|calls| cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64
  76f29041_9a55_7ccb_80b4_ff4b4446b54e["handleIdentifier()"]
  a6cfd201_2bfc_7a25_c3dd_0460f1930354 -->|calls| 76f29041_9a55_7ccb_80b4_ff4b4446b54e
  style a6cfd201_2bfc_7a25_c3dd_0460f1930354 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts lines 47–113

export function findContextIdentifiers(
  func: NodePath<t.Function>,
): Set<t.Identifier> {
  const state: FindContextIdentifierState = {
    currentFn: [],
    identifiers: new Map(),
  };

  func.traverse<FindContextIdentifierState>(
    {
      FunctionDeclaration: withFunctionScope,
      FunctionExpression: withFunctionScope,
      ArrowFunctionExpression: withFunctionScope,
      ObjectMethod: withFunctionScope,
      AssignmentExpression(
        path: NodePath<t.AssignmentExpression>,
        state: FindContextIdentifierState,
      ): void {
        const left = path.get('left');
        if (left.isLVal()) {
          const currentFn = state.currentFn.at(-1) ?? null;
          handleAssignment(currentFn, state.identifiers, left);
        } else {
          /**
           * OptionalMemberExpressions as the left side of an AssignmentExpression are Stage 1 and
           * not supported by React Compiler yet.
           */
          CompilerError.throwTodo({
            reason: `Unsupported syntax on the left side of an AssignmentExpression`,
            description: `Expected an LVal, got: ${left.type}`,
            loc: left.node.loc ?? null,
          });
        }
      },
      UpdateExpression(
        path: NodePath<t.UpdateExpression>,
        state: FindContextIdentifierState,
      ): void {
        const argument = path.get('argument');
        const currentFn = state.currentFn.at(-1) ?? null;
        if (argument.isLVal()) {
          handleAssignment(currentFn, state.identifiers, argument);
        }
      },
      Identifier(
        path: NodePath<t.Identifier>,
        state: FindContextIdentifierState,
      ): void {
        const currentFn = state.currentFn.at(-1) ?? null;
        if (path.isReferencedIdentifier()) {
          handleIdentifier(currentFn, state.identifiers, path);
        }
      },
    },
    state,
  );

  const result = new Set<t.Identifier>();
  for (const [id, info] of state.identifiers.entries()) {
    if (info.reassignedByInnerFn) {
      result.add(id);
    } else if (info.reassigned && info.referencedByInnerFn) {
      result.add(id);
    }
  }
  return result;
}

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free