codekingpro/portable-devtools
114k
1// given a starting node, what is the *deepest* target where name could go?
2// This is not on the Node class for the simple reason that we sometimes
3// need to check the deepest *potential* target for a Node that is not yet
4// added to the tree where we are checking.
5const deepestNestingTarget = (start, name) => {
6 for (const target of start.ancestry()) {
7 // note: this will skip past the first target if edge is peer
8 if (target.isProjectRoot || !target.resolveParent || target.globalTop) {
9 return target
10 }
11 const targetEdge = target.edgesOut.get(name)
12 if (!targetEdge || !targetEdge.peer) {
13 return target
14 }
15 }
16}
17
18module.exports = deepestNestingTarget
19 