* Calculates a path between 2 sibling nodes (generates a number of `NextSibling` navigations). * Returns `null` if no such path exists between the given nodes.
(start: Node, finish: Node)
| 325 | * Returns `null` if no such path exists between the given nodes. |
| 326 | */ |
| 327 | function navigateBetweenSiblings(start: Node, finish: Node): NodeNavigationStep[] | null { |
| 328 | const nav: NodeNavigationStep[] = []; |
| 329 | let node: Node | null = null; |
| 330 | for (node = start; node != null && node !== finish; node = node.nextSibling) { |
| 331 | nav.push(NODE_NAVIGATION_STEP_NEXT_SIBLING); |
| 332 | } |
| 333 | // If the `node` becomes `null` or `undefined` at the end, that means that we |
| 334 | // didn't find the `end` node, thus return `null` (which would trigger serialization |
| 335 | // error to be produced). |
| 336 | return node == null ? null : nav; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Calculates a path between 2 nodes in terms of `nextSibling` and `firstChild` |