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

Function inPath

esquery.js:52–70  ·  view source on GitHub ↗

* Determine whether `node` can be reached by following `path`, * starting at `ancestor`. * @param {?external:AST} node * @param {?external:AST} ancestor * @param {string[]} path * @param {Integer} fromPathIndex * @returns {boolean}

(node, ancestor, path, fromPathIndex)

Source from the content-addressed store, hash-verified

50 * @returns {boolean}
51 */
52function inPath(node, ancestor, path, fromPathIndex) {
53 let current = ancestor;
54 for (let i = fromPathIndex; i < path.length; ++i) {
55 if (current == null) {
56 return false;
57 }
58 const field = current[path[i]];
59 if (Array.isArray(field)) {
60 for (let k = 0; k < field.length; ++k) {
61 if (inPath(node, field[k], path, i + 1)) {
62 return true;
63 }
64 }
65 return false;
66 }
67 current = field;
68 }
69 return node === current;
70}
71
72/**
73 * A generated matcher function for a selector.

Callers 1

generateMatcherFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected