index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var resolveKeyword = require('css-tree').keyword;
  2. var walk = require('css-tree').walk;
  3. var generate = require('css-tree').generate;
  4. var createDeclarationIndexer = require('./createDeclarationIndexer');
  5. var processSelector = require('./processSelector');
  6. module.exports = function prepare(ast, options) {
  7. var markDeclaration = createDeclarationIndexer();
  8. walk(ast, {
  9. visit: 'Rule',
  10. enter: function processRule(node) {
  11. node.block.children.each(markDeclaration);
  12. processSelector(node, options.usage);
  13. }
  14. });
  15. walk(ast, {
  16. visit: 'Atrule',
  17. enter: function(node) {
  18. if (node.prelude) {
  19. node.prelude.id = null; // pre-init property to avoid multiple hidden class for generate
  20. node.prelude.id = generate(node.prelude);
  21. }
  22. // compare keyframe selectors by its values
  23. // NOTE: still no clarification about problems with keyframes selector grouping (issue #197)
  24. if (resolveKeyword(node.name).basename === 'keyframes') {
  25. node.block.avoidRulesMerge = true; /* probably we don't need to prevent those merges for @keyframes
  26. TODO: need to be checked */
  27. node.block.children.each(function(rule) {
  28. rule.prelude.children.each(function(simpleselector) {
  29. simpleselector.compareMarker = simpleselector.id;
  30. });
  31. });
  32. }
  33. }
  34. });
  35. return {
  36. declaration: markDeclaration
  37. };
  38. };