Home / Function/ extractManualMemoizationArgs() — react Function Reference

extractManualMemoizationArgs() — react Function Reference

Architecture documentation for the extractManualMemoizationArgs() function in DropManualMemoization.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  39c5a476_7a02_eb77_deeb_828d88fc0da0["extractManualMemoizationArgs()"]
  4b3f307b_2e5b_6c5a_0729_065bd25db103["DropManualMemoization.ts"]
  39c5a476_7a02_eb77_deeb_828d88fc0da0 -->|defined in| 4b3f307b_2e5b_6c5a_0729_065bd25db103
  dad92af5_71c7_94b3_8cce_ac3af87f3e61["dropManualMemoization()"]
  dad92af5_71c7_94b3_8cce_ac3af87f3e61 -->|calls| 39c5a476_7a02_eb77_deeb_828d88fc0da0
  02303def_636f_c5b3_a751_1cf138fcea69["pushDiagnostic()"]
  39c5a476_7a02_eb77_deeb_828d88fc0da0 -->|calls| 02303def_636f_c5b3_a751_1cf138fcea69
  ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"]
  39c5a476_7a02_eb77_deeb_828d88fc0da0 -->|calls| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf
  1a2b7047_24c8_62d6_b328_5f07307d27ab["withDetails()"]
  39c5a476_7a02_eb77_deeb_828d88fc0da0 -->|calls| 1a2b7047_24c8_62d6_b328_5f07307d27ab
  53244187_914c_cc90_5880_7bfc1fc9c0bb["push()"]
  39c5a476_7a02_eb77_deeb_828d88fc0da0 -->|calls| 53244187_914c_cc90_5880_7bfc1fc9c0bb
  style 39c5a476_7a02_eb77_deeb_828d88fc0da0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts lines 290–376

function extractManualMemoizationArgs(
  instr: TInstruction<CallExpression> | TInstruction<MethodCall>,
  kind: 'useCallback' | 'useMemo',
  sidemap: IdentifierSidemap,
  errors: CompilerError,
): {
  fnPlace: Place;
  depsList: Array<ManualMemoDependency> | null;
  depsLoc: SourceLocation | null;
} | null {
  const [fnPlace, depsListPlace] = instr.value.args as Array<
    Place | SpreadPattern | undefined
  >;
  if (fnPlace == null || fnPlace.kind !== 'Identifier') {
    errors.pushDiagnostic(
      CompilerDiagnostic.create({
        category: ErrorCategory.UseMemo,
        reason: `Expected a callback function to be passed to ${kind}`,
        description:
          kind === 'useCallback'
            ? 'The first argument to useCallback() must be a function to cache'
            : 'The first argument to useMemo() must be a function that calculates a result to cache',
        suggestions: null,
      }).withDetails({
        kind: 'error',
        loc: instr.value.loc,
        message:
          kind === 'useCallback'
            ? `Expected a callback function`
            : `Expected a memoization function`,
      }),
    );
    return null;
  }
  if (depsListPlace == null) {
    return {
      fnPlace,
      depsList: null,
      depsLoc: null,
    };
  }
  const maybeDepsList =
    depsListPlace.kind === 'Identifier'
      ? sidemap.maybeDepsLists.get(depsListPlace.identifier.id)
      : null;
  if (maybeDepsList == null) {
    errors.pushDiagnostic(
      CompilerDiagnostic.create({
        category: ErrorCategory.UseMemo,
        reason: `Expected the dependency list for ${kind} to be an array literal`,
        description: `Expected the dependency list for ${kind} to be an array literal`,
        suggestions: null,
      }).withDetails({
        kind: 'error',
        loc:
          depsListPlace?.kind === 'Identifier' ? depsListPlace.loc : instr.loc,
        message: `Expected the dependency list for ${kind} to be an array literal`,
      }),
    );
    return null;
  }
  const depsList: Array<ManualMemoDependency> = [];
  for (const dep of maybeDepsList.deps) {
    const maybeDep = sidemap.maybeDeps.get(dep.identifier.id);
    if (maybeDep == null) {
      errors.pushDiagnostic(
        CompilerDiagnostic.create({
          category: ErrorCategory.UseMemo,
          reason: `Expected the dependency list to be an array of simple expressions (e.g. \`x\`, \`x.y.z\`, \`x?.y?.z\`)`,
          description: `Expected the dependency list to be an array of simple expressions (e.g. \`x\`, \`x.y.z\`, \`x?.y?.z\`)`,
          suggestions: null,
        }).withDetails({
          kind: 'error',
          loc: dep.loc,
          message: `Expected the dependency list to be an array of simple expressions (e.g. \`x\`, \`x.y.z\`, \`x?.y?.z\`)`,
        }),
      );
    } else {
      depsList.push(maybeDep);
    }
  }

Domain

Subdomains

Frequently Asked Questions

What does extractManualMemoizationArgs() do?
extractManualMemoizationArgs() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts.
Where is extractManualMemoizationArgs() defined?
extractManualMemoizationArgs() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts at line 290.
What does extractManualMemoizationArgs() call?
extractManualMemoizationArgs() calls 4 function(s): create, push, pushDiagnostic, withDetails.
What calls extractManualMemoizationArgs()?
extractManualMemoizationArgs() is called by 1 function(s): dropManualMemoization.

Analyze Your Own Codebase

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

Try Supermodel Free