* 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)
| 50 | * @returns {boolean} |
| 51 | */ |
| 52 | function 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. |