Import.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Import = void 0;
  4. const ast_1 = require("./ast");
  5. class Import {
  6. constructor(parent, symbols) {
  7. this.parent = parent;
  8. this.symbols = symbols;
  9. this.byText = new Map();
  10. this.offset = parent ? parent.offset + parent.length : 1;
  11. this.length = symbols.length;
  12. for (let i = 0; i < symbols.length; i++) {
  13. const symbol = symbols[i];
  14. this.byText.set(symbol, this.offset + i);
  15. }
  16. }
  17. getId(symbol) {
  18. const id = this.byText.get(symbol);
  19. if (id !== undefined)
  20. return id;
  21. if (this.parent)
  22. this.parent.getId(symbol);
  23. return undefined;
  24. }
  25. getText(id) {
  26. if (id < this.offset)
  27. return this.parent ? this.parent.getText(id) : undefined;
  28. return this.symbols[id - this.offset];
  29. }
  30. add(symbol) {
  31. let id = this.byText.get(symbol);
  32. if (id !== undefined)
  33. return id;
  34. const length = this.symbols.length;
  35. id = this.offset + length;
  36. this.symbols.push(symbol);
  37. this.length++;
  38. this.byText.set(symbol, id);
  39. return id;
  40. }
  41. toAst() {
  42. const map = new Map();
  43. map.set(7, (0, ast_1.toAst)(this.symbols, this));
  44. return new ast_1.ObjAstNode(map);
  45. }
  46. }
  47. exports.Import = Import;
  48. //# sourceMappingURL=Import.js.map