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.

43 lines
1.6 KiB

4 years ago
  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. };