addDependency() — react Function Reference
Architecture documentation for the addDependency() function in DeriveMinimalDependenciesHIR.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 61f036d0_eb91_7e31_154e_acb3c7c8f23c["addDependency()"] ce8ab5d9_db4b_3be5_3f9c_38fa68bcbaa1["ReactiveScopeDependencyTreeHIR"] 61f036d0_eb91_7e31_154e_acb3c7c8f23c -->|defined in| ce8ab5d9_db4b_3be5_3f9c_38fa68bcbaa1 55f3fce3_0db5_e260_b549_d5a721561462["propagateScopeDependenciesHIR()"] 55f3fce3_0db5_e260_b549_d5a721561462 -->|calls| 61f036d0_eb91_7e31_154e_acb3c7c8f23c ca434b67_031d_2bec_f10c_3b8a790002ed["inferMinimalDependencies()"] ca434b67_031d_2bec_f10c_3b8a790002ed -->|calls| 61f036d0_eb91_7e31_154e_acb3c7c8f23c 38ab4c9b_814c_2f1c_3661_630e72f557fd["makeOrMergeProperty()"] 61f036d0_eb91_7e31_154e_acb3c7c8f23c -->|calls| 38ab4c9b_814c_2f1c_3661_630e72f557fd fde4af26_13b5_6adc_3afe_f724f66c9a93["merge()"] 61f036d0_eb91_7e31_154e_acb3c7c8f23c -->|calls| fde4af26_13b5_6adc_3afe_f724f66c9a93 style 61f036d0_eb91_7e31_154e_acb3c7c8f23c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/DeriveMinimalDependenciesHIR.ts lines 104–181
addDependency(dep: ReactiveScopeDependency): void {
const {identifier, reactive, path} = dep;
let depCursor = ReactiveScopeDependencyTreeHIR.#getOrCreateRoot(
identifier,
reactive,
this.#deps,
PropertyAccessType.UnconditionalAccess,
);
/**
* hoistableCursor is null if depCursor is not an object we can hoist
* property reads from otherwise, it represents the same node in the
* hoistable / cfg-informed tree
*/
let hoistableCursor: HoistableNode | undefined =
this.#hoistableObjects.get(identifier);
// All properties read 'on the way' to a dependency are marked as 'access'
for (const entry of path) {
let nextHoistableCursor: HoistableNode | undefined;
let nextDepCursor: DependencyNode;
if (entry.optional) {
/**
* No need to check the access type since we can match both optional or non-optionals
* in the hoistable
* e.g. a?.b<rest> is hoistable if a.b<rest> is hoistable
*/
if (hoistableCursor != null) {
nextHoistableCursor = hoistableCursor?.properties.get(entry.property);
}
let accessType;
if (
hoistableCursor != null &&
hoistableCursor.accessType === 'NonNull'
) {
/**
* For an optional chain dep `a?.b`: if the hoistable tree only
* contains `a`, we can keep either `a?.b` or 'a.b' as a dependency.
* (note that we currently do the latter for perf)
*/
accessType = PropertyAccessType.UnconditionalAccess;
} else {
/**
* Given that it's safe to evaluate `depCursor` and optional load
* never throws, it's also safe to evaluate `depCursor?.entry`
*/
accessType = PropertyAccessType.OptionalAccess;
}
nextDepCursor = makeOrMergeProperty(
depCursor,
entry.property,
accessType,
);
} else if (
hoistableCursor != null &&
hoistableCursor.accessType === 'NonNull'
) {
nextHoistableCursor = hoistableCursor.properties.get(entry.property);
nextDepCursor = makeOrMergeProperty(
depCursor,
entry.property,
PropertyAccessType.UnconditionalAccess,
);
} else {
/**
* Break to truncate the dependency on its first non-optional entry that PropertyLoads are not hoistable from
*/
break;
}
depCursor = nextDepCursor;
hoistableCursor = nextHoistableCursor;
}
// mark the final node as a dependency
depCursor.accessType = merge(
depCursor.accessType,
PropertyAccessType.OptionalDependency,
);
}
Domain
Subdomains
Source
Frequently Asked Questions
What does addDependency() do?
addDependency() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/DeriveMinimalDependenciesHIR.ts.
Where is addDependency() defined?
addDependency() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/DeriveMinimalDependenciesHIR.ts at line 104.
What does addDependency() call?
addDependency() calls 2 function(s): makeOrMergeProperty, merge.
What calls addDependency()?
addDependency() is called by 2 function(s): inferMinimalDependencies, propagateScopeDependenciesHIR.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free