(start: Node, finish: Node)
| 263 | * and `.nextSibling` operations. |
| 264 | */ |
| 265 | export function navigateBetween(start: Node, finish: Node): NodeNavigationStep[] | null { |
| 266 | if (start === finish) { |
| 267 | return []; |
| 268 | } else if (start.parentElement == null || finish.parentElement == null) { |
| 269 | return null; |
| 270 | } else if (start.parentElement === finish.parentElement) { |
| 271 | return navigateBetweenSiblings(start, finish); |
| 272 | } else { |
| 273 | // `finish` is a child of its parent, so the parent will always have a child. |
| 274 | const parent = finish.parentElement!; |
| 275 | |
| 276 | const parentPath = navigateBetween(start, parent); |
| 277 | const childPath = navigateBetween(parent.firstChild!, finish); |
| 278 | if (!parentPath || !childPath) return null; |
| 279 | |
| 280 | return [ |
| 281 | // First navigate to `finish`'s parent |
| 282 | ...parentPath, |
| 283 | // Then to its first child. |
| 284 | NODE_NAVIGATION_STEP_FIRST_CHILD, |
| 285 | // And finally from that node to `finish` (maybe a no-op if we're already there). |
| 286 | ...childPath, |
| 287 | ]; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Calculates a path between 2 sibling nodes (generates a number of `NextSibling` navigations). |
no test coverage detected
searching dependent graphs…