createDeclarationIndexer.js 598 B

12345678910111213141516171819202122232425262728293031
  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. };