You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 634B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Expose `visit()`.
  3. */
  4. module.exports = visit;
  5. /**
  6. * Visit `node`'s declarations recursively and
  7. * invoke `fn(declarations, node)`.
  8. *
  9. * @param {Object} node
  10. * @param {Function} fn
  11. * @api private
  12. */
  13. function visit(node, fn){
  14. node.rules.forEach(function(rule){
  15. // @media etc
  16. if (rule.rules) {
  17. visit(rule, fn);
  18. return;
  19. }
  20. // keyframes
  21. if (rule.keyframes) {
  22. rule.keyframes.forEach(function(keyframe){
  23. fn(keyframe.declarations, rule);
  24. });
  25. return;
  26. }
  27. // @charset, @import etc
  28. if (!rule.declarations) return;
  29. fn(rule.declarations, node);
  30. });
  31. };