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.

42 lines
1.1 KiB

4 years ago
  1. var List = require('css-tree').List;
  2. var walk = require('css-tree').walk;
  3. function processRule(node, item, list) {
  4. var selectors = node.prelude.children;
  5. // generate new rule sets:
  6. // .a, .b { color: red; }
  7. // ->
  8. // .a { color: red; }
  9. // .b { color: red; }
  10. // while there are more than 1 simple selector split for rulesets
  11. while (selectors.head !== selectors.tail) {
  12. var newSelectors = new List();
  13. newSelectors.insert(selectors.remove(selectors.head));
  14. list.insert(list.createItem({
  15. type: 'Rule',
  16. loc: node.loc,
  17. prelude: {
  18. type: 'SelectorList',
  19. loc: node.prelude.loc,
  20. children: newSelectors
  21. },
  22. block: {
  23. type: 'Block',
  24. loc: node.block.loc,
  25. children: node.block.children.copy()
  26. },
  27. pseudoSignature: node.pseudoSignature
  28. }), item);
  29. }
  30. }
  31. module.exports = function disjoinRule(ast) {
  32. walk(ast, {
  33. visit: 'Rule',
  34. reverse: true,
  35. enter: processRule
  36. });
  37. };