visitScope() — react Function Reference
Architecture documentation for the visitScope() function in PropagateEarlyReturns.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD f5f5a371_91bd_f082_46b8_671e0a645189["visitScope()"] bf2c5ad7_6533_e158_24c8_7c2ada4951ad["Transform"] f5f5a371_91bd_f082_46b8_671e0a645189 -->|defined in| bf2c5ad7_6533_e158_24c8_7c2ada4951ad 2eebfc2b_b1f6_9f25_ad32_78be0b56f06b["traverseScope()"] f5f5a371_91bd_f082_46b8_671e0a645189 -->|calls| 2eebfc2b_b1f6_9f25_ad32_78be0b56f06b 49446ae1_b830_9411_8258_1139d21b314b["createTemporaryPlace()"] f5f5a371_91bd_f082_46b8_671e0a645189 -->|calls| 49446ae1_b830_9411_8258_1139d21b314b 4acb57df_5348_9aab_9691_41cf35127db4["visitScope()"] f5f5a371_91bd_f082_46b8_671e0a645189 -->|calls| 4acb57df_5348_9aab_9691_41cf35127db4 style f5f5a371_91bd_f082_46b8_671e0a645189 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateEarlyReturns.ts lines 133–272
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,
loc,
},
},
},
{
kind: 'instruction',
instruction: {
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does visitScope() do?
visitScope() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateEarlyReturns.ts.
Where is visitScope() defined?
visitScope() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateEarlyReturns.ts at line 133.
What does visitScope() call?
visitScope() calls 3 function(s): createTemporaryPlace, traverseScope, visitScope.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free