createDeclarationIndexer.js 726 B

1234567891011121314151617181920212223242526272829303132
  1. var translate = require('../../../utils/translate.js');
  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 names = new Index();
  16. var values = new Index();
  17. return function markDeclaration(node) {
  18. var property = node.property.name;
  19. var value = translate(node.value);
  20. node.id = names.resolve(property) + (values.resolve(value) << 12);
  21. node.length = property.length + 1 + value.length;
  22. return node;
  23. };
  24. };