* Determines if the given node has an adjacent sibling that matches * the given selector matcher. * @param {external:AST} node * @param {SelectorMatcher} matcher * @param {external:AST[]} ancestry * @param {Side} side * @param {ESQueryOptions|undefined} options * @returns {boolean}
(node, matcher, ancestry, side, options)
| 473 | * @returns {boolean} |
| 474 | */ |
| 475 | function adjacent(node, matcher, ancestry, side, options) { |
| 476 | const [parent] = ancestry; |
| 477 | if (!parent) { return false; } |
| 478 | const keys = getVisitorKeys(parent, options); |
| 479 | for (let i = 0; i < keys.length; ++i) { |
| 480 | const listProp = parent[keys[i]]; |
| 481 | if (Array.isArray(listProp)) { |
| 482 | const idx = listProp.indexOf(node); |
| 483 | if (idx < 0) { continue; } |
| 484 | if (side === LEFT_SIDE && idx > 0 && isNode(listProp[idx - 1], options) && matcher(listProp[idx - 1], ancestry, options)) { |
| 485 | return true; |
| 486 | } |
| 487 | if (side === RIGHT_SIDE && idx < listProp.length - 1 && isNode(listProp[idx + 1], options) && matcher(listProp[idx + 1], ancestry, options)) { |
| 488 | return true; |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | return false; |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Determines if the given node is the `nth` child. |
no test coverage detected