Home / Function/ resolveBinding() — react Function Reference

resolveBinding() — react Function Reference

Architecture documentation for the resolveBinding() function in HIRBuilder.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  cf4d0005_5527_42f1_2412_741dbace1899["resolveBinding()"]
  d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845["HIRBuilder"]
  cf4d0005_5527_42f1_2412_741dbace1899 -->|defined in| d1b85268_f4cd_bc3c_7ba0_ee15dcc8a845
  f214c28b_2f6d_b5a3_71e1_9a69d9b50455["lower()"]
  f214c28b_2f6d_b5a3_71e1_9a69d9b50455 -->|calls| cf4d0005_5527_42f1_2412_741dbace1899
  c753d1dc_3d72_6c26_43d1_a3614937be80["resolveIdentifier()"]
  c753d1dc_3d72_6c26_43d1_a3614937be80 -->|calls| cf4d0005_5527_42f1_2412_741dbace1899
  eaa25847_803a_a160_25ce_fa2699f69d1c["throwDiagnostic()"]
  cf4d0005_5527_42f1_2412_741dbace1899 -->|calls| eaa25847_803a_a160_25ce_fa2699f69d1c
  9994dc80_69bc_44aa_ef8c_97977d75801a["makeDeclarationId()"]
  cf4d0005_5527_42f1_2412_741dbace1899 -->|calls| 9994dc80_69bc_44aa_ef8c_97977d75801a
  dcb26d23_8970_206b_e5d8_91b588c501b5["makeIdentifierName()"]
  cf4d0005_5527_42f1_2412_741dbace1899 -->|calls| dcb26d23_8970_206b_e5d8_91b588c501b5
  d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"]
  cf4d0005_5527_42f1_2412_741dbace1899 -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2
  style cf4d0005_5527_42f1_2412_741dbace1899 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts lines 309–368

  resolveBinding(node: t.Identifier): Identifier {
    if (node.name === 'fbt') {
      CompilerError.throwDiagnostic({
        category: ErrorCategory.Todo,
        reason: 'Support local variables named `fbt`',
        description:
          'Local variables named `fbt` may conflict with the fbt plugin and are not yet supported',
        details: [
          {
            kind: 'error',
            message: 'Rename to avoid conflict with fbt plugin',
            loc: node.loc ?? GeneratedSource,
          },
        ],
      });
    }
    if (node.name === 'this') {
      CompilerError.throwDiagnostic({
        category: ErrorCategory.UnsupportedSyntax,
        reason: '`this` is not supported syntax',
        description:
          'React Compiler does not support compiling functions that use `this`',
        details: [
          {
            kind: 'error',
            message: '`this` was used here',
            loc: node.loc ?? GeneratedSource,
          },
        ],
      });
    }
    const originalName = node.name;
    let name = originalName;
    let index = 0;
    while (true) {
      const mapping = this.#bindings.get(name);
      if (mapping === undefined) {
        const id = this.nextIdentifierId;
        const identifier: Identifier = {
          id,
          declarationId: makeDeclarationId(id),
          name: makeIdentifierName(name),
          mutableRange: {
            start: makeInstructionId(0),
            end: makeInstructionId(0),
          },
          scope: null,
          type: makeType(),
          loc: node.loc ?? GeneratedSource,
        };
        this.#env.programContext.addNewReference(name);
        this.#bindings.set(name, {node, identifier});
        return identifier;
      } else if (mapping.node === node) {
        return mapping.identifier;
      } else {
        name = `${originalName}_${index++}`;
      }
    }
  }

Subdomains

Frequently Asked Questions

What does resolveBinding() do?
resolveBinding() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts.
Where is resolveBinding() defined?
resolveBinding() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts at line 309.
What does resolveBinding() call?
resolveBinding() calls 4 function(s): makeDeclarationId, makeIdentifierName, makeInstructionId, throwDiagnostic.
What calls resolveBinding()?
resolveBinding() is called by 2 function(s): lower, resolveIdentifier.

Analyze Your Own Codebase

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

Try Supermodel Free