Environment Class — react Architecture
Architecture documentation for the Environment class in Environment.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD cba0c8a2_0db5_48e2_0d19_b2c6a46799e8["Environment"] 1b971013_8a90_0d8d_1fcc_f31581cd66aa["Environment.ts"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|defined in| 1b971013_8a90_0d8d_1fcc_f31581cd66aa bec8431d_08f7_cef1_8a71_8be17fc7a31a["constructor()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| bec8431d_08f7_cef1_8a71_8be17fc7a31a 7741ec50_982e_3532_46b1_3f812ba7af09["typeContext()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 7741ec50_982e_3532_46b1_3f812ba7af09 a9157c32_9c0c_6b97_0720_6e53605b370d["enableDropManualMemoization()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| a9157c32_9c0c_6b97_0720_6e53605b370d 0effb24b_fd6b_177a_a58f_284356ae70b8["enableMemoization()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 0effb24b_fd6b_177a_a58f_284356ae70b8 dc625857_4f60_7249_b574_89713671db5d["enableValidations()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| dc625857_4f60_7249_b574_89713671db5d 4c5901ab_3021_6976_bae2_bbcfa9ceacfc["nextIdentifierId()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 4c5901ab_3021_6976_bae2_bbcfa9ceacfc b5270442_a3d4_c0ac_4004_38c1f96753df["nextBlockId()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| b5270442_a3d4_c0ac_4004_38c1f96753df 681b220d_e67e_5b0e_c774_2b836e0c27bc["nextScopeId()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 681b220d_e67e_5b0e_c774_2b836e0c27bc 211c5bf6_6e8d_0959_64f1_09503c23dd6f["scope()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 211c5bf6_6e8d_0959_64f1_09503c23dd6f 702fa0b8_ba8c_390e_cde1_4dca39712628["logErrors()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 702fa0b8_ba8c_390e_cde1_4dca39712628 2bbf96a6_6ccc_e175_4d4e_97f8806e7af6["isContextIdentifier()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 2bbf96a6_6ccc_e175_4d4e_97f8806e7af6 129cba6c_ded6_779e_cc49_b175d871418b["isHoistedIdentifier()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 129cba6c_ded6_779e_cc49_b175d871418b 47f643e0_1f78_f692_e4ee_835bc08fbf68["generateGloballyUniqueIdentifierName()"] cba0c8a2_0db5_48e2_0d19_b2c6a46799e8 -->|method| 47f643e0_1f78_f692_e4ee_835bc08fbf68
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts lines 751–1240
export class Environment {
#globals: GlobalRegistry;
#shapes: ShapeRegistry;
#moduleTypes: Map<string, Global | null> = new Map();
#nextIdentifer: number = 0;
#nextBlock: number = 0;
#nextScope: number = 0;
#scope: BabelScope;
#outlinedFunctions: Array<{
fn: HIRFunction;
type: ReactFunctionType | null;
}> = [];
logger: Logger | null;
filename: string | null;
code: string | null;
config: EnvironmentConfig;
fnType: ReactFunctionType;
outputMode: CompilerOutputMode;
programContext: ProgramContext;
hasFireRewrite: boolean;
hasInferredEffect: boolean;
inferredEffectLocations: Set<SourceLocation> = new Set();
#contextIdentifiers: Set<t.Identifier>;
#hoistedIdentifiers: Set<t.Identifier>;
parentFunction: NodePath<t.Function>;
#flowTypeEnvironment: FlowTypeEnv | null;
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,
Domain
Source
Frequently Asked Questions
What is the Environment class?
Environment is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts.
Where is Environment defined?
Environment is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts at line 751.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free