Transform Class — react Architecture
Architecture documentation for the Transform class in PruneUnusedLabels.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 894c3941_1d64_1249_9677_948e95b5ad37["Transform"] ac9d1354_1036_e3da_7e02_40ce71b820eb["PruneUnusedLabels.ts"] 894c3941_1d64_1249_9677_948e95b5ad37 -->|defined in| ac9d1354_1036_e3da_7e02_40ce71b820eb 3ce1ff3b_6e81_02a3_536a_76e3ce96f6c3["transformTerminal()"] 894c3941_1d64_1249_9677_948e95b5ad37 -->|method| 3ce1ff3b_6e81_02a3_536a_76e3ce96f6c3
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedLabels.ts lines 31–66
class Transform extends ReactiveFunctionTransform<Labels> {
override transformTerminal(
stmt: ReactiveTerminalStatement,
state: Labels,
): Transformed<ReactiveStatement> {
this.traverseTerminal(stmt, state);
const {terminal} = stmt;
if (
(terminal.kind === 'break' || terminal.kind === 'continue') &&
terminal.targetKind === 'labeled'
) {
state.add(terminal.target);
}
// Is this terminal reachable via a break/continue to its label?
const isReachableLabel = stmt.label !== null && state.has(stmt.label.id);
if (stmt.terminal.kind === 'label' && !isReachableLabel) {
// Flatten labeled terminals where the label isn't necessary
const block = [...stmt.terminal.block];
const last = block.at(-1);
if (
last !== undefined &&
last.kind === 'terminal' &&
last.terminal.kind === 'break' &&
last.terminal.target === null
) {
block.pop();
}
return {kind: 'replace-many', value: block};
} else {
if (!isReachableLabel && stmt.label != null) {
stmt.label.implicit = true;
}
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/PruneUnusedLabels.ts.
Where is Transform defined?
Transform is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedLabels.ts at line 31.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free