eachNodeUpToRoot.cjs 698 B

1234567891011121314151617181920212223242526272829
  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 typeGuards = require('./typeGuards.cjs');
  5. /** @import { Node } from 'postcss' */
  6. const STOP = 'STOP';
  7. /**
  8. * Iterates over each node up to the root node.
  9. *
  10. * @param {Node} node
  11. * @param {(node: Node) => void | STOP} callback
  12. * @returns {void}
  13. */
  14. function eachNodeUpToRoot(node, callback) {
  15. let currentNode = node.parent;
  16. while (currentNode && !typeGuards.isRoot(currentNode)) {
  17. if (callback(currentNode) === STOP) break;
  18. currentNode = currentNode.parent;
  19. }
  20. }
  21. exports.STOP = STOP;
  22. exports.default = eachNodeUpToRoot;