Home / Function/ assertValidEffectImportReference() — react Function Reference

assertValidEffectImportReference() — react Function Reference

Architecture documentation for the assertValidEffectImportReference() function in ValidateNoUntransformedReferences.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  6eae54a5_62d8_1643_47df_9a08317a25f0["assertValidEffectImportReference()"]
  93f3a2c7_a7ce_3c94_87fe_ee7d66d9b64b["ValidateNoUntransformedReferences.ts"]
  6eae54a5_62d8_1643_47df_9a08317a25f0 -->|defined in| 93f3a2c7_a7ce_3c94_87fe_ee7d66d9b64b
  13979066_5844_9e9b_3dd1_d031ec964de0["matchCompilerDiagnostic()"]
  6eae54a5_62d8_1643_47df_9a08317a25f0 -->|calls| 13979066_5844_9e9b_3dd1_d031ec964de0
  fd74cbf5_70fe_dfe3_61f3_388ace207e52["throwInvalidReact()"]
  6eae54a5_62d8_1643_47df_9a08317a25f0 -->|calls| fd74cbf5_70fe_dfe3_61f3_388ace207e52
  style 6eae54a5_62d8_1643_47df_9a08317a25f0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/ValidateNoUntransformedReferences.ts lines 66–114

function assertValidEffectImportReference(
  autodepsIndex: number,
  paths: Array<NodePath<t.Node>>,
  context: TraversalState,
): void {
  for (const path of paths) {
    const parent = path.parentPath;
    if (parent != null && parent.isCallExpression()) {
      const args = parent.get('arguments');
      const maybeCalleeLoc = path.node.loc;
      const hasInferredEffect =
        maybeCalleeLoc != null &&
        context.inferredEffectLocations.has(maybeCalleeLoc);
      /**
       * Error on effect calls that still have AUTODEPS in their args
       */
      const hasAutodepsArg = args.some(isAutodepsSigil);
      if (hasAutodepsArg && !hasInferredEffect) {
        const maybeErrorDiagnostic = matchCompilerDiagnostic(
          path,
          context.transformErrors,
        );
        /**
         * Note that we cannot easily check the type of the first argument here,
         * as it may have already been transformed by the compiler (and not
         * memoized).
         */
        throwInvalidReact(
          {
            category: ErrorCategory.AutomaticEffectDependencies,
            reason:
              'Cannot infer dependencies of this effect. This will break your build!',
            description:
              'To resolve, either pass a dependency array or fix reported compiler bailout diagnostics' +
              (maybeErrorDiagnostic ? ` ${maybeErrorDiagnostic}` : ''),
            details: [
              {
                kind: 'error',
                message: 'Cannot infer dependencies',
                loc: parent.node.loc ?? GeneratedSource,
              },
            ],
          },
          context,
        );
      }
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does assertValidEffectImportReference() do?
assertValidEffectImportReference() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/ValidateNoUntransformedReferences.ts.
Where is assertValidEffectImportReference() defined?
assertValidEffectImportReference() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/ValidateNoUntransformedReferences.ts at line 66.
What does assertValidEffectImportReference() call?
assertValidEffectImportReference() calls 2 function(s): matchCompilerDiagnostic, throwInvalidReact.

Analyze Your Own Codebase

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

Try Supermodel Free