Home / Function/ unify() — react Function Reference

unify() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  1c006d07_fe01_836d_2c9c_015b0c23187c["unify()"]
  e91596b5_bd35_ace7_a141_7dbab722b96d["Unifier"]
  1c006d07_fe01_836d_2c9c_015b0c23187c -->|defined in| e91596b5_bd35_ace7_a141_7dbab722b96d
  fafa4e35_d1bd_5163_9aea_72cb4d1742f3["inferTypes()"]
  fafa4e35_d1bd_5163_9aea_72cb4d1742f3 -->|calls| 1c006d07_fe01_836d_2c9c_015b0c23187c
  b282c6e8_cb4e_aa17_9bb5_f36ea62991f4["generateInstructionTypes()"]
  b282c6e8_cb4e_aa17_9bb5_f36ea62991f4 -->|calls| 1c006d07_fe01_836d_2c9c_015b0c23187c
  6938eece_f870_22b1_d136_01eb0a26f7b9["bindVariableTo()"]
  6938eece_f870_22b1_d136_01eb0a26f7b9 -->|calls| 1c006d07_fe01_836d_2c9c_015b0c23187c
  f0603215_bdb0_88a0_8649_8c18b423f04f["get()"]
  1c006d07_fe01_836d_2c9c_015b0c23187c -->|calls| f0603215_bdb0_88a0_8649_8c18b423f04f
  6938eece_f870_22b1_d136_01eb0a26f7b9["bindVariableTo()"]
  1c006d07_fe01_836d_2c9c_015b0c23187c -->|calls| 6938eece_f870_22b1_d136_01eb0a26f7b9
  7e1f1a9c_1489_c62f_c887_7cfa00c72f53["isRefLikeName()"]
  1c006d07_fe01_836d_2c9c_015b0c23187c -->|calls| 7e1f1a9c_1489_c62f_c887_7cfa00c72f53
  style 1c006d07_fe01_836d_2c9c_015b0c23187c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts lines 586–642

  unify(tA: Type, tB: Type): void {
    if (tB.kind === 'Property') {
      if (
        this.env.config.enableTreatRefLikeIdentifiersAsRefs &&
        isRefLikeName(tB)
      ) {
        this.unify(tB.objectType, {
          kind: 'Object',
          shapeId: BuiltInUseRefId,
        });
        this.unify(tA, {
          kind: 'Object',
          shapeId: BuiltInRefValueId,
        });
        return;
      }
      const objectType = this.get(tB.objectType);
      const propertyType =
        tB.propertyName.kind === 'literal'
          ? this.env.getPropertyType(objectType, tB.propertyName.value)
          : this.env.getFallthroughPropertyType(
              objectType,
              tB.propertyName.value,
            );
      if (propertyType !== null) {
        this.unify(tA, propertyType);
      }
      /*
       * We do not error if tB is not a known object or function (even if it
       * is a primitive), since JS implicit conversion to objects
       */
      return;
    }

    if (typeEquals(tA, tB)) {
      return;
    }

    if (tA.kind === 'Type') {
      this.bindVariableTo(tA, tB);
      return;
    }

    if (tB.kind === 'Type') {
      this.bindVariableTo(tB, tA);
      return;
    }

    if (
      tB.kind === 'Function' &&
      tA.kind === 'Function' &&
      tA.isConstructor === tB.isConstructor
    ) {
      this.unify(tA.return, tB.return);
      return;
    }
  }

Subdomains

Frequently Asked Questions

What does unify() do?
unify() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts.
Where is unify() defined?
unify() is defined in compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts at line 586.
What does unify() call?
unify() calls 3 function(s): bindVariableTo, get, isRefLikeName.
What calls unify()?
unify() is called by 3 function(s): bindVariableTo, generateInstructionTypes, inferTypes.

Analyze Your Own Codebase

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

Try Supermodel Free