eachRoot.js 626 B

12345678910111213141516171819202122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = _default;
  6. /**
  7. * Executes a provided function once for each CSS block element.
  8. *
  9. * @param {Root|Document} root - root element of file.
  10. * @param {function} cb - Function to execute for each CSS block element
  11. */
  12. function _default(root, cb) {
  13. // class `Document` is a part of `postcss-html`,
  14. // It is collection of roots in HTML File.
  15. // See: https://github.com/gucong3000/postcss-html/blob/master/lib/document.js
  16. if (root.constructor.name === "Document") {
  17. root.nodes.forEach(cb);
  18. } else {
  19. cb(root);
  20. }
  21. }