* Determines if the given node is the `nth` child. * If `nth` is negative then the position is counted * from the end of the list of children. * @param {external:AST} node * @param {external:AST[]} ancestry * @param {Integer} nth * @param {ESQueryOptions|undefined} options * @returns {boolean
(node, ancestry, nth, options)
| 503 | * @returns {boolean} |
| 504 | */ |
| 505 | function nthChild(node, ancestry, nth, options) { |
| 506 | if (nth === 0) { return false; } |
| 507 | const [parent] = ancestry; |
| 508 | if (!parent) { return false; } |
| 509 | const keys = getVisitorKeys(parent, options); |
| 510 | for (let i = 0; i < keys.length; ++i) { |
| 511 | const listProp = parent[keys[i]]; |
| 512 | if (Array.isArray(listProp)){ |
| 513 | const idx = nth < 0 ? listProp.length + nth : nth - 1; |
| 514 | if (idx >= 0 && idx < listProp.length && listProp[idx] === node) { |
| 515 | return true; |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * For each selector node marked as a subject, find the portion of the |
no test coverage detected