Home / Function/ validateNoContextVariableAssignment() — react Function Reference

validateNoContextVariableAssignment() — react Function Reference

Architecture documentation for the validateNoContextVariableAssignment() function in ValidateUseMemo.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  078e94bc_d3da_1437_368b_2db5a97fcbdb["validateNoContextVariableAssignment()"]
  50f9142a_be38_a654_5f39_5cea59a5336d["ValidateUseMemo.ts"]
  078e94bc_d3da_1437_368b_2db5a97fcbdb -->|defined in| 50f9142a_be38_a654_5f39_5cea59a5336d
  67b24411_23d5_6f16_8d4e_dbebeb847123["validateUseMemo()"]
  67b24411_23d5_6f16_8d4e_dbebeb847123 -->|calls| 078e94bc_d3da_1437_368b_2db5a97fcbdb
  02303def_636f_c5b3_a751_1cf138fcea69["pushDiagnostic()"]
  078e94bc_d3da_1437_368b_2db5a97fcbdb -->|calls| 02303def_636f_c5b3_a751_1cf138fcea69
  ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"]
  078e94bc_d3da_1437_368b_2db5a97fcbdb -->|calls| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf
  1a2b7047_24c8_62d6_b328_5f07307d27ab["withDetails()"]
  078e94bc_d3da_1437_368b_2db5a97fcbdb -->|calls| 1a2b7047_24c8_62d6_b328_5f07307d27ab
  8e8b7ee8_d3c2_f98d_17e1_c5ff5fff1940["map()"]
  078e94bc_d3da_1437_368b_2db5a97fcbdb -->|calls| 8e8b7ee8_d3c2_f98d_17e1_c5ff5fff1940
  style 078e94bc_d3da_1437_368b_2db5a97fcbdb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts lines 183–214

function validateNoContextVariableAssignment(
  fn: HIRFunction,
  errors: CompilerError,
): void {
  const context = new Set(fn.context.map(place => place.identifier.id));
  for (const block of fn.body.blocks.values()) {
    for (const instr of block.instructions) {
      const value = instr.value;
      switch (value.kind) {
        case 'StoreContext': {
          if (context.has(value.lvalue.place.identifier.id)) {
            errors.pushDiagnostic(
              CompilerDiagnostic.create({
                category: ErrorCategory.UseMemo,
                reason:
                  'useMemo() callbacks may not reassign variables declared outside of the callback',
                description:
                  'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
                suggestions: null,
              }).withDetails({
                kind: 'error',
                loc: value.lvalue.place.loc,
                message: 'Cannot reassign variable',
              }),
            );
          }
          break;
        }
      }
    }
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does validateNoContextVariableAssignment() do?
validateNoContextVariableAssignment() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts.
Where is validateNoContextVariableAssignment() defined?
validateNoContextVariableAssignment() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts at line 183.
What does validateNoContextVariableAssignment() call?
validateNoContextVariableAssignment() calls 4 function(s): create, map, pushDiagnostic, withDetails.
What calls validateNoContextVariableAssignment()?
validateNoContextVariableAssignment() is called by 1 function(s): validateUseMemo.

Analyze Your Own Codebase

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

Try Supermodel Free