Visitor Class — react Architecture
Architecture documentation for the Visitor class in ValidatePreservedManualMemoization.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 310c2965_2897_08a7_588d_8109c9f88c0c["Visitor"] 24b95621_3482_c406_4b63_5b9d9e94b5af["ValidatePreservedManualMemoization.ts"] 310c2965_2897_08a7_588d_8109c9f88c0c -->|defined in| 24b95621_3482_c406_4b63_5b9d9e94b5af 2430e594_74e0_ca9a_14be_251ff6fa4bb8["recordDepsInValue()"] 310c2965_2897_08a7_588d_8109c9f88c0c -->|method| 2430e594_74e0_ca9a_14be_251ff6fa4bb8 1d0d9ade_8ca6_4897_7d4a_358a8565f5b3["recordTemporaries()"] 310c2965_2897_08a7_588d_8109c9f88c0c -->|method| 1d0d9ade_8ca6_4897_7d4a_358a8565f5b3 7d870135_2212_e6ce_9c8d_5751aca84f6f["visitScope()"] 310c2965_2897_08a7_588d_8109c9f88c0c -->|method| 7d870135_2212_e6ce_9c8d_5751aca84f6f 483921e6_5f43_cd9b_e1c3_c4e31c74fe85["visitPrunedScope()"] 310c2965_2897_08a7_588d_8109c9f88c0c -->|method| 483921e6_5f43_cd9b_e1c3_c4e31c74fe85 ad786783_79dc_d97c_fb6f_d2e1268b8fd5["visitInstruction()"] 310c2965_2897_08a7_588d_8109c9f88c0c -->|method| ad786783_79dc_d97c_fb6f_d2e1268b8fd5
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts lines 318–605
class Visitor extends ReactiveFunctionVisitor<VisitorState> {
/**
* Records all completed scopes (regardless of transitive memoization
* of scope dependencies)
*
* Both @scopes and @prunedScopes are live sets. We rely on iterating
* the reactive-ir in evaluation order, as they are used to determine
* whether scope dependencies / declarations have completed mutation.
*/
scopes: Set<ScopeId> = new Set();
prunedScopes: Set<ScopeId> = new Set();
temporaries: Map<IdentifierId, ManualMemoDependency> = new Map();
/**
* Recursively visit values and instructions to collect declarations
* and property loads.
* @returns a @{ManualMemoDependency} representing the variable +
* property reads represented by @value
*/
recordDepsInValue(value: ReactiveValue, state: VisitorState): void {
switch (value.kind) {
case 'SequenceExpression': {
for (const instr of value.instructions) {
this.visitInstruction(instr, state);
}
this.recordDepsInValue(value.value, state);
break;
}
case 'OptionalExpression': {
this.recordDepsInValue(value.value, state);
break;
}
case 'ConditionalExpression': {
this.recordDepsInValue(value.test, state);
this.recordDepsInValue(value.consequent, state);
this.recordDepsInValue(value.alternate, state);
break;
}
case 'LogicalExpression': {
this.recordDepsInValue(value.left, state);
this.recordDepsInValue(value.right, state);
break;
}
default: {
collectMaybeMemoDependencies(value, this.temporaries, false);
if (
value.kind === 'StoreLocal' ||
value.kind === 'StoreContext' ||
value.kind === 'Destructure'
) {
for (const storeTarget of eachInstructionValueLValue(value)) {
state.manualMemoState?.decls.add(
storeTarget.identifier.declarationId,
);
if (storeTarget.identifier.name?.kind === 'named') {
this.temporaries.set(storeTarget.identifier.id, {
root: {
kind: 'NamedLocal',
value: storeTarget,
constant: false,
},
path: [],
loc: storeTarget.loc,
});
}
}
}
break;
}
}
}
recordTemporaries(instr: ReactiveInstruction, state: VisitorState): void {
const temporaries = this.temporaries;
const {lvalue, value} = instr;
const lvalId = lvalue?.identifier.id;
if (lvalId != null && temporaries.has(lvalId)) {
return;
}
const isNamedLocal = lvalue?.identifier.name?.kind === 'named';
if (lvalue !== null && isNamedLocal && state.manualMemoState != null) {
Domain
Defined In
Source
Frequently Asked Questions
What is the Visitor class?
Visitor is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts.
Where is Visitor defined?
Visitor is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts at line 318.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free