Home / Function/ bindVariableTo() — react Function Reference

bindVariableTo() — react Function Reference

Architecture documentation for the bindVariableTo() function in InferTypes.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  6938eece_f870_22b1_d136_01eb0a26f7b9["bindVariableTo()"]
  e91596b5_bd35_ace7_a141_7dbab722b96d["Unifier"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|defined in| e91596b5_bd35_ace7_a141_7dbab722b96d
  1c006d07_fe01_836d_2c9c_015b0c23187c["unify()"]
  1c006d07_fe01_836d_2c9c_015b0c23187c -->|calls| 6938eece_f870_22b1_d136_01eb0a26f7b9
  1c006d07_fe01_836d_2c9c_015b0c23187c["unify()"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|calls| 1c006d07_fe01_836d_2c9c_015b0c23187c
  f0603215_bdb0_88a0_8649_8c18b423f04f["get()"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|calls| f0603215_bdb0_88a0_8649_8c18b423f04f
  aa93304b_656c_028f_c640_ad8396517027["occursCheck()"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|calls| aa93304b_656c_028f_c640_ad8396517027
  3586dd2f_f748_328e_8e11_2899a16d4f45["tryResolveType()"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|calls| 3586dd2f_f748_328e_8e11_2899a16d4f45
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  e60369e7_778a_215c_2939_89cf588096ef["tryUnionTypes()"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|calls| e60369e7_778a_215c_2939_89cf588096ef
  style 6938eece_f870_22b1_d136_01eb0a26f7b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts lines 644–698

  bindVariableTo(v: TypeVar, type: Type): void {
    if (type.kind === 'Poly') {
      //  Ignore PolyType, since we don't support polymorphic types correctly.
      return;
    }

    if (this.substitutions.has(v.id)) {
      this.unify(this.substitutions.get(v.id)!, type);
      return;
    }

    if (type.kind === 'Type' && this.substitutions.has(type.id)) {
      this.unify(v, this.substitutions.get(type.id)!);
      return;
    }

    if (type.kind === 'Phi') {
      CompilerError.invariant(type.operands.length > 0, {
        reason: 'there should be at least one operand',
        loc: GeneratedSource,
      });

      let candidateType: Type | null = null;
      for (const operand of type.operands) {
        const resolved = this.get(operand);
        if (candidateType === null) {
          candidateType = resolved;
        } else if (!typeEquals(resolved, candidateType)) {
          const unionType = tryUnionTypes(resolved, candidateType);
          if (unionType === null) {
            candidateType = null;
            break;
          } else {
            candidateType = unionType;
          }
        } // else same type, continue
      }

      if (candidateType !== null) {
        this.unify(v, candidateType);
        return;
      }
    }

    if (this.occursCheck(v, type)) {
      const resolvedType = this.tryResolveType(v, type);
      if (resolvedType !== null) {
        this.substitutions.set(v.id, resolvedType);
        return;
      }
      throw new Error('cycle detected');
    }

    this.substitutions.set(v.id, type);
  }

Subdomains

Called By

Frequently Asked Questions

What does bindVariableTo() do?
bindVariableTo() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts.
Where is bindVariableTo() defined?
bindVariableTo() is defined in compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts at line 644.
What does bindVariableTo() call?
bindVariableTo() calls 6 function(s): get, invariant, occursCheck, tryResolveType, tryUnionTypes, unify.
What calls bindVariableTo()?
bindVariableTo() is called by 1 function(s): unify.

Analyze Your Own Codebase

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

Try Supermodel Free