findNodeUpToRoot.cjs 726 B

12345678910111213141516171819202122232425262728293031
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const eachNodeUpToRoot = require('./eachNodeUpToRoot.cjs');
  5. /** @import { Node } from 'postcss' */
  6. /**
  7. * Finds the node satisfying the specified predicate up to the root node.
  8. *
  9. * @param {Node} node
  10. * @param {(node: Node) => boolean} predicate
  11. * @returns {Node | undefined}
  12. */
  13. function findNodeUpToRoot(node, predicate) {
  14. /** @type {Node | undefined} */
  15. let found;
  16. eachNodeUpToRoot.default(node, (current) => {
  17. if (predicate(current)) {
  18. found = current;
  19. return eachNodeUpToRoot.STOP;
  20. }
  21. });
  22. return found;
  23. }
  24. module.exports = findNodeUpToRoot;