Transform Class — react Architecture
Architecture documentation for the Transform class in PruneUnusedScopes.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 5a05f31c_ebbc_2227_1399_e3e8c8cbcfa3["Transform"] c273bd3a_951b_cab6_1196_8484358b901c["PruneUnusedScopes.ts"] 5a05f31c_ebbc_2227_1399_e3e8c8cbcfa3 -->|defined in| c273bd3a_951b_cab6_1196_8484358b901c 6e959b1d_e382_2839_615b_63b0569cad1c["visitTerminal()"] 5a05f31c_ebbc_2227_1399_e3e8c8cbcfa3 -->|method| 6e959b1d_e382_2839_615b_63b0569cad1c 4f7ad929_f19e_7d55_33f1_e3306e7e41bc["transformScope()"] 5a05f31c_ebbc_2227_1399_e3e8c8cbcfa3 -->|method| 4f7ad929_f19e_7d55_33f1_e3306e7e41bc
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedScopes.ts lines 31–66
class Transform extends ReactiveFunctionTransform<State> {
override visitTerminal(stmt: ReactiveTerminalStatement, state: State): void {
this.traverseTerminal(stmt, state);
if (stmt.terminal.kind === 'return') {
state.hasReturnStatement = true;
}
}
override transformScope(
scopeBlock: ReactiveScopeBlock,
_state: State,
): Transformed<ReactiveStatement> {
const scopeState: State = {hasReturnStatement: false};
this.visitScope(scopeBlock, scopeState);
if (
!scopeState.hasReturnStatement &&
scopeBlock.scope.reassignments.size === 0 &&
(scopeBlock.scope.declarations.size === 0 ||
/*
* Can prune scopes where all declarations bubbled up from inner
* scopes
*/
!hasOwnDeclaration(scopeBlock))
) {
return {
kind: 'replace',
value: {
kind: 'pruned-scope',
scope: scopeBlock.scope,
instructions: scopeBlock.instructions,
},
};
} else {
return {kind: 'keep'};
}
}
}
Domain
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/PruneUnusedScopes.ts.
Where is Transform defined?
Transform is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedScopes.ts at line 31.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free