Home / Function/ codegenValue() — react Function Reference

codegenValue() — react Function Reference

Architecture documentation for the codegenValue() function in CodegenReactiveFunction.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  2ac8d08a_6c80_ae3f_d4aa_e140740ac030["codegenValue()"]
  dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"]
  2ac8d08a_6c80_ae3f_d4aa_e140740ac030 -->|defined in| dc7f10c2_c914_a162_d02b_a10a15c64a5f
  d8edf87e_ea78_c9d0_b5c9_13d68891efec["codegenInstructionValue()"]
  d8edf87e_ea78_c9d0_b5c9_13d68891efec -->|calls| 2ac8d08a_6c80_ae3f_d4aa_e140740ac030
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  2ac8d08a_6c80_ae3f_d4aa_e140740ac030 -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  style 2ac8d08a_6c80_ae3f_d4aa_e140740ac030 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts lines 2584–2611

function codegenValue(
  cx: Context,
  loc: SourceLocation,
  value: boolean | number | string | null | undefined,
): t.Expression {
  if (typeof value === 'number') {
    if (value < 0) {
      /**
       * Babel's code generator produces invalid JS for negative numbers when
       * run with { compact: true }.
       * See repro https://codesandbox.io/p/devbox/5d47fr
       */
      return t.unaryExpression('-', t.numericLiteral(-value), false);
    } else {
      return t.numericLiteral(value);
    }
  } else if (typeof value === 'boolean') {
    return t.booleanLiteral(value);
  } else if (typeof value === 'string') {
    return createStringLiteral(loc, value);
  } else if (value === null) {
    return t.nullLiteral();
  } else if (value === undefined) {
    return t.identifier('undefined');
  } else {
    assertExhaustive(value, 'Unexpected primitive value kind');
  }
}

Domain

Subdomains

Frequently Asked Questions

What does codegenValue() do?
codegenValue() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts.
Where is codegenValue() defined?
codegenValue() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts at line 2584.
What does codegenValue() call?
codegenValue() calls 1 function(s): assertExhaustive.
What calls codegenValue()?
codegenValue() is called by 1 function(s): codegenInstructionValue.

Analyze Your Own Codebase

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

Try Supermodel Free