MCPcopy Create free account
hub / github.com/angular/angular / navigateBetween

Function navigateBetween

packages/core/src/hydration/node_lookup_utils.ts:298–322  ·  view source on GitHub ↗
(start: Node, finish: Node)

Source from the content-addressed store, hash-verified

296 * and `.nextSibling` operations.
297 */
298export function navigateBetween(start: Node, finish: Node): NodeNavigationStep[] | null {
299 if (start === finish) {
300 return [];
301 } else if (start.parentElement == null || finish.parentElement == null) {
302 return null;
303 } else if (start.parentElement === finish.parentElement) {
304 return navigateBetweenSiblings(start, finish);
305 } else {
306 // `finish` is a child of its parent, so the parent will always have a child.
307 const parent = finish.parentElement!;
308
309 const parentPath = navigateBetween(start, parent);
310 const childPath = navigateBetween(parent.firstChild!, finish);
311 if (!parentPath || !childPath) return null;
312
313 return [
314 // First navigate to `finish`'s parent
315 ...parentPath,
316 // Then to its first child.
317 NODE_NAVIGATION_STEP_FIRST_CHILD,
318 // And finally from that node to `finish` (maybe a no-op if we're already there).
319 ...childPath,
320 ];
321 }
322}
323
324/**
325 * Calculates a path between 2 sibling nodes (generates a number of `NextSibling` navigations).

Callers 1

calcPathBetweenFunction · 0.85

Calls 1

navigateBetweenSiblingsFunction · 0.85

Tested by

no test coverage detected