mirror of
https://github.com/nodejs/node.git
synced 2025-08-18 15:18:46 +02:00

PR-URL: https://github.com/nodejs/node/pull/40055 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Beth Griggs <bgriggs@redhat.com>
18 lines
691 B
JavaScript
18 lines
691 B
JavaScript
// given a starting node, what is the *deepest* target where name could go?
|
|
// This is not on the Node class for the simple reason that we sometimes
|
|
// need to check the deepest *potential* target for a Node that is not yet
|
|
// added to the tree where we are checking.
|
|
const deepestNestingTarget = (start, name) => {
|
|
for (const target of start.ancestry()) {
|
|
// note: this will skip past the first target if edge is peer
|
|
if (target.isProjectRoot || !target.resolveParent || target.globalTop) {
|
|
return target
|
|
}
|
|
const targetEdge = target.edgesOut.get(name)
|
|
if (!targetEdge || !targetEdge.peer) {
|
|
return target
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = deepestNestingTarget
|