Home / Function/ joinRefAccessTypes() — react Function Reference

joinRefAccessTypes() — react Function Reference

Architecture documentation for the joinRefAccessTypes() function in ValidateNoRefAccessInRender.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  58faf1c6_d9e6_ba3c_c4bb_dc4fce641e52["joinRefAccessTypes()"]
  8dbbe52d_b145_88fe_e0da_33d06180b558["ValidateNoRefAccessInRender.ts"]
  58faf1c6_d9e6_ba3c_c4bb_dc4fce641e52 -->|defined in| 8dbbe52d_b145_88fe_e0da_33d06180b558
  648272d7_e6a6_0efe_25c4_d76434ffaafb["set()"]
  648272d7_e6a6_0efe_25c4_d76434ffaafb -->|calls| 58faf1c6_d9e6_ba3c_c4bb_dc4fce641e52
  b2292640_a950_f66a_1a21_4fa1d74f094d["validateNoRefAccessInRenderImpl()"]
  b2292640_a950_f66a_1a21_4fa1d74f094d -->|calls| 58faf1c6_d9e6_ba3c_c4bb_dc4fce641e52
  c06d5fe3_6fbc_47fb_7088_b334e439d5f0["nextRefId()"]
  58faf1c6_d9e6_ba3c_c4bb_dc4fce641e52 -->|calls| c06d5fe3_6fbc_47fb_7088_b334e439d5f0
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  58faf1c6_d9e6_ba3c_c4bb_dc4fce641e52 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  style 58faf1c6_d9e6_ba3c_c4bb_dc4fce641e52 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccessInRender.ts lines 229–310

function joinRefAccessTypes(...types: Array<RefAccessType>): RefAccessType {
  function joinRefAccessRefTypes(
    a: RefAccessRefType,
    b: RefAccessRefType,
  ): RefAccessRefType {
    if (a.kind === 'RefValue') {
      if (b.kind === 'RefValue' && a.refId === b.refId) {
        return a;
      }
      return {kind: 'RefValue'};
    } else if (b.kind === 'RefValue') {
      return b;
    } else if (a.kind === 'Ref' || b.kind === 'Ref') {
      if (a.kind === 'Ref' && b.kind === 'Ref' && a.refId === b.refId) {
        return a;
      }
      return {kind: 'Ref', refId: nextRefId()};
    } else {
      CompilerError.invariant(
        a.kind === 'Structure' && b.kind === 'Structure',
        {
          reason: 'Expected structure',
          loc: GeneratedSource,
        },
      );
      const fn =
        a.fn === null
          ? b.fn
          : b.fn === null
            ? a.fn
            : {
                readRefEffect: a.fn.readRefEffect || b.fn.readRefEffect,
                returnType: joinRefAccessTypes(
                  a.fn.returnType,
                  b.fn.returnType,
                ),
              };
      const value =
        a.value === null
          ? b.value
          : b.value === null
            ? a.value
            : joinRefAccessRefTypes(a.value, b.value);
      return {
        kind: 'Structure',
        fn,
        value,
      };
    }
  }

  return types.reduce(
    (a, b) => {
      if (a.kind === 'None') {
        return b;
      } else if (b.kind === 'None') {
        return a;
      } else if (a.kind === 'Guard') {
        if (b.kind === 'Guard' && a.refId === b.refId) {
          return a;
        } else if (b.kind === 'Nullable' || b.kind === 'Guard') {
          return {kind: 'None'};
        } else {
          return b;
        }
      } else if (b.kind === 'Guard') {
        if (a.kind === 'Nullable') {
          return {kind: 'None'};
        } else {
          return b;
        }
      } else if (a.kind === 'Nullable') {
        return b;
      } else if (b.kind === 'Nullable') {
        return a;
      } else {
        return joinRefAccessRefTypes(a, b);
      }
    },
    {kind: 'None'},
  );

Domain

Subdomains

Frequently Asked Questions

What does joinRefAccessTypes() do?
joinRefAccessTypes() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccessInRender.ts.
Where is joinRefAccessTypes() defined?
joinRefAccessTypes() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccessInRender.ts at line 229.
What does joinRefAccessTypes() call?
joinRefAccessTypes() calls 2 function(s): invariant, nextRefId.
What calls joinRefAccessTypes()?
joinRefAccessTypes() is called by 2 function(s): set, validateNoRefAccessInRenderImpl.

Analyze Your Own Codebase

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

Try Supermodel Free