alignMethodCallScopes() — react Function Reference
Architecture documentation for the alignMethodCallScopes() function in AlignMethodCallScopes.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD bdad7522_9507_6e0a_8551_e304482ab97e["alignMethodCallScopes()"] 144792a6_40dd_95bb_1746_790346dbccd0["AlignMethodCallScopes.ts"] bdad7522_9507_6e0a_8551_e304482ab97e -->|defined in| 144792a6_40dd_95bb_1746_790346dbccd0 c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"] c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| bdad7522_9507_6e0a_8551_e304482ab97e 4c434fb2_75ab_6c2c_c237_b1d38a1b0141["forEach()"] bdad7522_9507_6e0a_8551_e304482ab97e -->|calls| 4c434fb2_75ab_6c2c_c237_b1d38a1b0141 74efde51_a311_d84c_0e23_ddafd072e338["find()"] bdad7522_9507_6e0a_8551_e304482ab97e -->|calls| 74efde51_a311_d84c_0e23_ddafd072e338 style bdad7522_9507_6e0a_8551_e304482ab97e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignMethodCallScopes.ts lines 21–80
export function alignMethodCallScopes(fn: HIRFunction): void {
const scopeMapping = new Map<IdentifierId, ReactiveScope | null>();
const mergedScopes = new DisjointSet<ReactiveScope>();
for (const [, block] of fn.body.blocks) {
for (const instr of block.instructions) {
const {lvalue, value} = instr;
if (value.kind === 'MethodCall') {
const lvalueScope = lvalue.identifier.scope;
const propertyScope = value.property.identifier.scope;
if (lvalueScope !== null) {
if (propertyScope !== null) {
// Both have a scope: merge the scopes
mergedScopes.union([lvalueScope, propertyScope]);
} else {
/*
* Else the call itself has a scope but not the property,
* record that this property should be in this scope
*/
scopeMapping.set(value.property.identifier.id, lvalueScope);
}
} else if (propertyScope !== null) {
// else this property does not need a scope
scopeMapping.set(value.property.identifier.id, null);
}
} else if (
value.kind === 'FunctionExpression' ||
value.kind === 'ObjectMethod'
) {
alignMethodCallScopes(value.loweredFunc.func);
}
}
}
mergedScopes.forEach((scope, root) => {
if (scope === root) {
return;
}
root.range.start = makeInstructionId(
Math.min(scope.range.start, root.range.start),
);
root.range.end = makeInstructionId(
Math.max(scope.range.end, root.range.end),
);
});
for (const [, block] of fn.body.blocks) {
for (const instr of block.instructions) {
const mappedScope = scopeMapping.get(instr.lvalue.identifier.id);
if (mappedScope !== undefined) {
instr.lvalue.identifier.scope = mappedScope;
} else if (instr.lvalue.identifier.scope !== null) {
const mergedScope = mergedScopes.find(instr.lvalue.identifier.scope);
if (mergedScope != null) {
instr.lvalue.identifier.scope = mergedScope;
}
}
}
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does alignMethodCallScopes() do?
alignMethodCallScopes() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignMethodCallScopes.ts.
Where is alignMethodCallScopes() defined?
alignMethodCallScopes() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignMethodCallScopes.ts at line 21.
What does alignMethodCallScopes() call?
alignMethodCallScopes() calls 2 function(s): find, forEach.
What calls alignMethodCallScopes()?
alignMethodCallScopes() is called by 1 function(s): runWithEnvironment.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free