process-selectors.js 834 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Calls processFn for each selector found
  3. * at the given rule
  4. * @param {Object} rule
  5. * @param {Function} processFn
  6. */
  7. function processRuleSelectors(rule, processFn) {
  8. var selectors = rule.selectors;
  9. for (var i = 0; i < selectors.length; i++) {
  10. processFn(selectors[i]);
  11. }
  12. }
  13. /**
  14. * Calls processFn for each selector found
  15. * at the given rules
  16. * @param {Object[]} rules
  17. * @param {Function} processFn
  18. */
  19. function processSelectors(rules, processFn) {
  20. var rule;
  21. for (var i = 0; i < rules.length; i++) {
  22. rule = rules[i];
  23. if (rule.type === 'rule') {
  24. processRuleSelectors(rule, processFn);
  25. } else if (rule.rules) {
  26. // Add nested rules to the list
  27. // Will be checked after the current ones
  28. rules.push.apply(rules, rule.rules);
  29. }
  30. }
  31. }
  32. module.exports = processSelectors;