MCPcopy Create free account
hub / github.com/estools/esquery / sibling

Function sibling

esquery.js:438–463  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

436 * @returns {boolean}
437 */
438function 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

Callers 1

generateMatcherFunction · 0.85

Calls 2

getVisitorKeysFunction · 0.85
isNodeFunction · 0.85

Tested by

no test coverage detected