Context Class — react Architecture
Architecture documentation for the Context class in TransformFire.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 1cc5203c_bda6_d474_ce02_0de0532830f0["Context"] 6061353e_921a_a1a8_d6c1_777e8d9f8896["TransformFire.ts"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|defined in| 6061353e_921a_a1a8_d6c1_777e8d9f8896 8bb7bd10_2011_c915_614b_d41604e3c259["constructor()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 8bb7bd10_2011_c915_614b_d41604e3c259 7d01f68a_73c6_619d_f94a_4a30b935a1dc["pushError()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 7d01f68a_73c6_619d_f94a_4a30b935a1dc 82b132d3_0738_0762_bb98_68350fff1f76["withFunctionScope()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 82b132d3_0738_0762_bb98_68350fff1f76 83c88e3e_bf8b_2746_f1b3_d72ab4fca53c["withUseEffectLambdaScope()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 83c88e3e_bf8b_2746_f1b3_d72ab4fca53c cfbc9247_0a52_6843_51c3_de1b6590436b["addCallExpression()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| cfbc9247_0a52_6843_51c3_de1b6590436b efc0c907_cf38_5506_2490_59f5022ca2f6["getCallExpression()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| efc0c907_cf38_5506_2490_59f5022ca2f6 0ad6254b_d5bf_e4b7_ac33_5109105cc98c["addLoadLocalInstr()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 0ad6254b_d5bf_e4b7_ac33_5109105cc98c 1f319b98_a7fb_1a86_ba1e_cd5a76ace0bf["getLoadLocalInstr()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 1f319b98_a7fb_1a86_ba1e_cd5a76ace0bf 10535d5e_42c3_cc4d_c710_f6388cf67d53["getOrGenerateFireFunctionBinding()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 10535d5e_42c3_cc4d_c710_f6388cf67d53 87b734d8_7872_5707_79f3_c595b3542664["mergeCalleesFromInnerScope()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 87b734d8_7872_5707_79f3_c595b3542664 65848e0e_926f_e89b_6b6d_02c250615f44["addCalleeWithInsertedFire()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 65848e0e_926f_e89b_6b6d_02c250615f44 a9536a88_f563_4f72_20a0_40128435fa78["hasCalleeWithInsertedFire()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| a9536a88_f563_4f72_20a0_40128435fa78 6480f474_15c5_2790_ea80_e2999abf8760["inUseEffectLambda()"] 1cc5203c_bda6_d474_ce02_0de0532830f0 -->|method| 6480f474_15c5_2790_ea80_e2999abf8760
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts lines 526–707
class Context {
#env: Environment;
#errors: CompilerError = new CompilerError();
/*
* Used to look up the call expression passed to a `fire(callExpr())`. Gives back
* the `callExpr()`.
*/
#callExpressions = new Map<IdentifierId, CallExpression>();
/*
* We keep track of function expressions so that we can traverse them when
* we encounter a lambda passed to a useEffect call
*/
#functionExpressions = new Map<IdentifierId, FunctionExpression>();
/*
* Mapping from lvalue ids to the LoadLocal for it. Allows us to replace dependency LoadLocals.
*/
#loadLocals = new Map<IdentifierId, LoadLocal>();
/*
* Maps all of the fire callees found in a component/hook to the generated fire function places
* we create for them. Allows us to reuse already-inserted useFire results
*/
#fireCalleesToFireFunctions: Map<IdentifierId, Place> = new Map();
/*
* The callees for which we have already created fire bindings. Used to skip inserting a new
* useFire call for a fire callee if one has already been created.
*/
#calleesWithInsertedFire = new Set<IdentifierId>();
/*
* A mapping from fire callees to the created fire function bindings that are reachable from this
* scope.
*
* We additionally keep track of the captured callee identifier so that we can properly reference
* it in the place where we LoadLocal the callee as an argument to useFire.
*/
#capturedCalleeIdentifierIds: FireCalleesToFireFunctionBinding = new Map();
/*
* We only transform fire calls if we're syntactically within a useEffect lambda (for now)
*/
#inUseEffectLambda = false;
/*
* Mapping from useEffect callee identifier ids to the instruction id of the
* load global instruction for the useEffect call. We use this to insert the
* useFire calls before the useEffect call
*/
#loadGlobalInstructionIds = new Map<IdentifierId, InstructionId>();
constructor(env: Environment) {
this.#env = env;
}
/*
* We keep track of array expressions so we can rewrite dependency arrays passed to useEffect
* to use the fire functions
*/
#arrayExpressions = new Map<IdentifierId, ArrayExpression>();
pushError(error: CompilerErrorDetailOptions): void {
this.#errors.push(error);
}
withFunctionScope(fn: () => void): FireCalleesToFireFunctionBinding {
fn();
return this.#capturedCalleeIdentifierIds;
}
withUseEffectLambdaScope(fn: () => void): FireCalleesToFireFunctionBinding {
const capturedCalleeIdentifierIds = this.#capturedCalleeIdentifierIds;
const inUseEffectLambda = this.#inUseEffectLambda;
this.#capturedCalleeIdentifierIds = new Map();
this.#inUseEffectLambda = true;
Domain
Source
Frequently Asked Questions
What is the Context class?
Context is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts.
Where is Context defined?
Context is defined in compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts at line 526.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free