MappingsContext.js 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class MappingsContext {
  7. constructor() {
  8. this.sourcesIndices = new Map();
  9. this.sourcesContent = new Map();
  10. this.hasSourceContent = false;
  11. this.currentOriginalLine = 1;
  12. this.currentSource = 0;
  13. this.unfinishedGeneratedLine = false;
  14. }
  15. ensureSource(source, originalSource) {
  16. let idx = this.sourcesIndices.get(source);
  17. if(typeof idx === "number") {
  18. return idx;
  19. }
  20. idx = this.sourcesIndices.size;
  21. this.sourcesIndices.set(source, idx);
  22. this.sourcesContent.set(source, originalSource)
  23. if(typeof originalSource === "string")
  24. this.hasSourceContent = true;
  25. return idx;
  26. }
  27. getArrays() {
  28. const sources = [];
  29. const sourcesContent = [];
  30. for(const pair of this.sourcesContent) {
  31. sources.push(pair[0]);
  32. sourcesContent.push(pair[1]);
  33. }
  34. return {
  35. sources,
  36. sourcesContent
  37. };
  38. }
  39. }
  40. module.exports = MappingsContext;