* Determines if the given node has a 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)
| 436 | * @returns {boolean} |
| 437 | */ |
| 438 | function sibling(node, matcher, ancestry, side, options) { |
| 439 | const [parent] = ancestry; |
| 440 | if (!parent) { return false; } |
| 441 | const keys = getVisitorKeys(parent, options); |
| 442 | for (let i = 0; i < keys.length; ++i) { |
| 443 | const listProp = parent[keys[i]]; |
| 444 | if (Array.isArray(listProp)) { |
| 445 | const startIndex = listProp.indexOf(node); |
| 446 | if (startIndex < 0) { continue; } |
| 447 | let lowerBound, upperBound; |
| 448 | if (side === LEFT_SIDE) { |
| 449 | lowerBound = 0; |
| 450 | upperBound = startIndex; |
| 451 | } else { |
| 452 | lowerBound = startIndex + 1; |
| 453 | upperBound = listProp.length; |
| 454 | } |
| 455 | for (let k = lowerBound; k < upperBound; ++k) { |
| 456 | if (isNode(listProp[k], options) && matcher(listProp[k], ancestry, options)) { |
| 457 | return true; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Determines if the given node has an adjacent sibling that matches |
no test coverage detected