Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deepest-nesting-target.js « lib « arborist « @npmcli « node_modules « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9c433a7652da2fcbab61b7ecfee42d4fc93d6387 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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