AlignMethodCallScopes.ts — react Source File
Architecture documentation for AlignMethodCallScopes.ts, a typescript file in the react codebase. 3 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 144792a6_40dd_95bb_1746_790346dbccd0["AlignMethodCallScopes.ts"] 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] 144792a6_40dd_95bb_1746_790346dbccd0 --> 0423f759_97e0_9101_4634_ed555abc5ca9 edec7689_7b1d_03c9_9cbb_bb9b0552bc30["DisjointSet.ts"] 144792a6_40dd_95bb_1746_790346dbccd0 --> edec7689_7b1d_03c9_9cbb_bb9b0552bc30 1765a682_3028_4441_b26f_c712ca2597d5["DisjointSet"] 144792a6_40dd_95bb_1746_790346dbccd0 --> 1765a682_3028_4441_b26f_c712ca2597d5 e3cfc07a_10c8_5dcd_e270_e8e14c29309b["Pipeline.ts"] e3cfc07a_10c8_5dcd_e270_e8e14c29309b --> 144792a6_40dd_95bb_1746_790346dbccd0 style 144792a6_40dd_95bb_1746_790346dbccd0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
HIRFunction,
IdentifierId,
ReactiveScope,
makeInstructionId,
} from '../HIR';
import DisjointSet from '../Utils/DisjointSet';
/**
* Ensures that method call instructions have scopes such that either:
* - Both the MethodCall and its property have the same scope
* - OR neither has a scope
*/
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
Functions
Dependencies
Source
Frequently Asked Questions
What does AlignMethodCallScopes.ts do?
AlignMethodCallScopes.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in AlignMethodCallScopes.ts?
AlignMethodCallScopes.ts defines 1 function(s): alignMethodCallScopes.
What does AlignMethodCallScopes.ts depend on?
AlignMethodCallScopes.ts imports 3 module(s): DisjointSet, DisjointSet.ts, index.ts.
What files import AlignMethodCallScopes.ts?
AlignMethodCallScopes.ts is imported by 1 file(s): Pipeline.ts.
Where is AlignMethodCallScopes.ts in the architecture?
AlignMethodCallScopes.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignMethodCallScopes.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free