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.

31 lines
598 B

4 years ago
  1. var generate = require('css-tree').generate;
  2. function Index() {
  3. this.seed = 0;
  4. this.map = Object.create(null);
  5. }
  6. Index.prototype.resolve = function(str) {
  7. var index = this.map[str];
  8. if (!index) {
  9. index = ++this.seed;
  10. this.map[str] = index;
  11. }
  12. return index;
  13. };
  14. module.exports = function createDeclarationIndexer() {
  15. var ids = new Index();
  16. return function markDeclaration(node) {
  17. var id = generate(node);
  18. node.id = ids.resolve(id);
  19. node.length = id.length;
  20. node.fingerprint = null;
  21. return node;
  22. };
  23. };