Transform Class — react Architecture
Architecture documentation for the Transform class in PropagateEarlyReturns.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD bf2c5ad7_6533_e158_24c8_7c2ada4951ad["Transform"] adcc884e_716d_15ed_4c6a_2983e4feb77c["PropagateEarlyReturns.ts"] bf2c5ad7_6533_e158_24c8_7c2ada4951ad -->|defined in| adcc884e_716d_15ed_4c6a_2983e4feb77c 15c85194_3015_244e_fc92_6962dbfaea63["constructor()"] bf2c5ad7_6533_e158_24c8_7c2ada4951ad -->|method| 15c85194_3015_244e_fc92_6962dbfaea63 f5f5a371_91bd_f082_46b8_671e0a645189["visitScope()"] bf2c5ad7_6533_e158_24c8_7c2ada4951ad -->|method| f5f5a371_91bd_f082_46b8_671e0a645189 7c4a8c4f_1fe5_f001_a91f_cb85243c13e8["transformTerminal()"] bf2c5ad7_6533_e158_24c8_7c2ada4951ad -->|method| 7c4a8c4f_1fe5_f001_a91f_cb85243c13e8
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateEarlyReturns.ts lines 126–337
class Transform extends ReactiveFunctionTransform<State> {
env: Environment;
constructor(env: Environment) {
super();
this.env = env;
}
override visitScope(
scopeBlock: ReactiveScopeBlock,
parentState: State,
): void {
/**
* Exit early if an earlier pass has already created an early return,
* which may happen in alternate compiler configurations.
*/
if (scopeBlock.scope.earlyReturnValue !== null) {
return;
}
const innerState: State = {
withinReactiveScope: true,
earlyReturnValue: parentState.earlyReturnValue,
};
this.traverseScope(scopeBlock, innerState);
const earlyReturnValue = innerState.earlyReturnValue;
if (earlyReturnValue !== null) {
if (!parentState.withinReactiveScope) {
// This is the outermost scope wrapping an early return, store the early return information
scopeBlock.scope.earlyReturnValue = earlyReturnValue;
scopeBlock.scope.declarations.set(earlyReturnValue.value.id, {
identifier: earlyReturnValue.value,
scope: scopeBlock.scope,
});
const instructions = scopeBlock.instructions;
const loc = earlyReturnValue.loc;
const sentinelTemp = createTemporaryPlace(this.env, loc);
const symbolTemp = createTemporaryPlace(this.env, loc);
const forTemp = createTemporaryPlace(this.env, loc);
const argTemp = createTemporaryPlace(this.env, loc);
scopeBlock.instructions = [
{
kind: 'instruction',
instruction: {
id: makeInstructionId(0),
loc,
lvalue: {...symbolTemp},
value: {
kind: 'LoadGlobal',
binding: {
kind: 'Global',
name: 'Symbol',
},
loc,
},
},
},
{
kind: 'instruction',
instruction: {
id: makeInstructionId(0),
loc,
lvalue: {...forTemp},
value: {
kind: 'PropertyLoad',
object: {...symbolTemp},
property: makePropertyLiteral('for'),
loc,
},
},
},
{
kind: 'instruction',
instruction: {
id: makeInstructionId(0),
loc,
lvalue: {...argTemp},
value: {
kind: 'Primitive',
value: EARLY_RETURN_SENTINEL,
Domain
Defined In
Source
Frequently Asked Questions
What is the Transform class?
Transform is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateEarlyReturns.ts.
Where is Transform defined?
Transform is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateEarlyReturns.ts at line 126.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free