PropertyPathRegistry Class — react Architecture
Architecture documentation for the PropertyPathRegistry class in CollectHoistablePropertyLoads.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 50c372df_146d_1b4c_de3a_0589d6591a75["PropertyPathRegistry"] 53e05ed1_ffb1_8db2_8573_ef5a3fb99c72["CollectHoistablePropertyLoads.ts"] 50c372df_146d_1b4c_de3a_0589d6591a75 -->|defined in| 53e05ed1_ffb1_8db2_8573_ef5a3fb99c72 084ee472_d720_c32a_2f8a_dffbbb1be6af["getOrCreateIdentifier()"] 50c372df_146d_1b4c_de3a_0589d6591a75 -->|method| 084ee472_d720_c32a_2f8a_dffbbb1be6af a6cc066a_d685_3022_a631_437bad493e6d["getOrCreatePropertyEntry()"] 50c372df_146d_1b4c_de3a_0589d6591a75 -->|method| a6cc066a_d685_3022_a631_437bad493e6d afcd35a2_87ac_64f3_d39b_e78954698dc0["getOrCreateProperty()"] 50c372df_146d_1b4c_de3a_0589d6591a75 -->|method| afcd35a2_87ac_64f3_d39b_e78954698dc0
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts lines 241–323
class PropertyPathRegistry {
roots: Map<IdentifierId, RootNode> = new Map();
getOrCreateIdentifier(
identifier: Identifier,
reactive: boolean,
): PropertyPathNode {
/**
* Reads from a statically scoped variable are always safe in JS,
* with the exception of TDZ (not addressed by this pass).
*/
let rootNode = this.roots.get(identifier.id);
if (rootNode === undefined) {
rootNode = {
root: identifier.id,
properties: new Map(),
optionalProperties: new Map(),
fullPath: {
identifier,
reactive,
path: [],
},
hasOptional: false,
parent: null,
};
this.roots.set(identifier.id, rootNode);
} else {
CompilerError.invariant(reactive === rootNode.fullPath.reactive, {
reason:
'[HoistablePropertyLoads] Found inconsistencies in `reactive` flag when deduping identifier reads within the same scope',
loc: identifier.loc,
});
}
return rootNode;
}
static getOrCreatePropertyEntry(
parent: PropertyPathNode,
entry: DependencyPathEntry,
): PropertyPathNode {
const map = entry.optional ? parent.optionalProperties : parent.properties;
let child = map.get(entry.property);
if (child == null) {
child = {
properties: new Map(),
optionalProperties: new Map(),
parent: parent,
fullPath: {
identifier: parent.fullPath.identifier,
reactive: parent.fullPath.reactive,
path: parent.fullPath.path.concat(entry),
},
hasOptional: parent.hasOptional || entry.optional,
};
map.set(entry.property, child);
}
return child;
}
getOrCreateProperty(n: ReactiveScopeDependency): PropertyPathNode {
/**
* We add ReactiveScopeDependencies according to instruction ordering,
* so all subpaths of a PropertyLoad should already exist
* (e.g. a.b is added before a.b.c),
*/
let currNode = this.getOrCreateIdentifier(n.identifier, n.reactive);
if (n.path.length === 0) {
return currNode;
}
for (let i = 0; i < n.path.length - 1; i++) {
currNode = PropertyPathRegistry.getOrCreatePropertyEntry(
currNode,
n.path[i],
);
}
return PropertyPathRegistry.getOrCreatePropertyEntry(
currNode,
n.path.at(-1)!,
);
Domain
Source
Frequently Asked Questions
What is the PropertyPathRegistry class?
PropertyPathRegistry is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts.
Where is PropertyPathRegistry defined?
PropertyPathRegistry is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts at line 241.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free