Home / Function/ constructor() — react Function Reference

constructor() — react Function Reference

Architecture documentation for the constructor() function in Environment.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  bec8431d_08f7_cef1_8a71_8be17fc7a31a["constructor()"]
  cba0c8a2_0db5_48e2_0d19_b2c6a46799e8["Environment"]
  bec8431d_08f7_cef1_8a71_8be17fc7a31a -->|defined in| cba0c8a2_0db5_48e2_0d19_b2c6a46799e8
  8bb7bd10_2011_c915_614b_d41604e3c259["constructor()"]
  8bb7bd10_2011_c915_614b_d41604e3c259 -->|calls| bec8431d_08f7_cef1_8a71_8be17fc7a31a
  f4dabc03_d648_e2d6_19ef_83872ae711d3["throwInvalidConfig()"]
  bec8431d_08f7_cef1_8a71_8be17fc7a31a -->|calls| f4dabc03_d648_e2d6_19ef_83872ae711d3
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  bec8431d_08f7_cef1_8a71_8be17fc7a31a -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  d0882928_65af_dce8_5416_84ed7f492587["addHook()"]
  bec8431d_08f7_cef1_8a71_8be17fc7a31a -->|calls| d0882928_65af_dce8_5416_84ed7f492587
  4ba5c3ad_186f_8c38_7db0_a6d2e5ee2b25["getReanimatedModuleType()"]
  bec8431d_08f7_cef1_8a71_8be17fc7a31a -->|calls| 4ba5c3ad_186f_8c38_7db0_a6d2e5ee2b25
  e3d1f312_c52c_8d71_91e3_cec13c53ceb5["init()"]
  bec8431d_08f7_cef1_8a71_8be17fc7a31a -->|calls| e3d1f312_c52c_8d71_91e3_cec13c53ceb5
  style bec8431d_08f7_cef1_8a71_8be17fc7a31a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts lines 780–858

  constructor(
    scope: BabelScope,
    fnType: ReactFunctionType,
    outputMode: CompilerOutputMode,
    config: EnvironmentConfig,
    contextIdentifiers: Set<t.Identifier>,
    parentFunction: NodePath<t.Function>, // the outermost function being compiled
    logger: Logger | null,
    filename: string | null,
    code: string | null,
    programContext: ProgramContext,
  ) {
    this.#scope = scope;
    this.fnType = fnType;
    this.outputMode = outputMode;
    this.config = config;
    this.filename = filename;
    this.code = code;
    this.logger = logger;
    this.programContext = programContext;
    this.#shapes = new Map(DEFAULT_SHAPES);
    this.#globals = new Map(DEFAULT_GLOBALS);
    this.hasFireRewrite = false;
    this.hasInferredEffect = false;

    if (
      config.disableMemoizationForDebugging &&
      config.enableChangeDetectionForDebugging != null
    ) {
      CompilerError.throwInvalidConfig({
        reason: `Invalid environment config: the 'disableMemoizationForDebugging' and 'enableChangeDetectionForDebugging' options cannot be used together`,
        description: null,
        loc: null,
        suggestions: null,
      });
    }

    for (const [hookName, hook] of this.config.customHooks) {
      CompilerError.invariant(!this.#globals.has(hookName), {
        reason: `[Globals] Found existing definition in global registry for custom hook ${hookName}`,
        loc: GeneratedSource,
      });
      this.#globals.set(
        hookName,
        addHook(this.#shapes, {
          positionalParams: [],
          restParam: hook.effectKind,
          returnType: hook.transitiveMixedData
            ? {kind: 'Object', shapeId: BuiltInMixedReadonlyId}
            : {kind: 'Poly'},
          returnValueKind: hook.valueKind,
          calleeEffect: Effect.Read,
          hookKind: 'Custom',
          noAlias: hook.noAlias,
        }),
      );
    }

    if (config.enableCustomTypeDefinitionForReanimated) {
      const reanimatedModuleType = getReanimatedModuleType(this.#shapes);
      this.#moduleTypes.set(REANIMATED_MODULE_NAME, reanimatedModuleType);
    }

    this.parentFunction = parentFunction;
    this.#contextIdentifiers = contextIdentifiers;
    this.#hoistedIdentifiers = new Set();

    if (config.flowTypeProvider != null) {
      this.#flowTypeEnvironment = new FlowTypeEnv();
      CompilerError.invariant(code != null, {
        reason:
          'Expected Environment to be initialized with source code when a Flow type provider is specified',
        loc: GeneratedSource,
      });
      this.#flowTypeEnvironment.init(this, code);
    } else {
      this.#flowTypeEnvironment = null;
    }
  }

Subdomains

Called By

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts.
Where is constructor() defined?
constructor() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts at line 780.
What does constructor() call?
constructor() calls 5 function(s): addHook, getReanimatedModuleType, init, invariant, throwInvalidConfig.
What calls constructor()?
constructor() is called by 1 function(s): constructor.

Analyze Your Own Codebase

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

Try Supermodel Free