source-map.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _genMapping = require("@jridgewell/gen-mapping");
  7. class SourceMap {
  8. constructor(opts, code) {
  9. var _opts$sourceFileName;
  10. this._map = void 0;
  11. this._rawMappings = void 0;
  12. this._sourceFileName = void 0;
  13. this._lastGenLine = 0;
  14. this._lastSourceLine = 0;
  15. this._lastSourceColumn = 0;
  16. const map = this._map = new _genMapping.GenMapping({
  17. sourceRoot: opts.sourceRoot
  18. });
  19. this._sourceFileName = (_opts$sourceFileName = opts.sourceFileName) == null ? void 0 : _opts$sourceFileName.replace(/\\/g, "/");
  20. this._rawMappings = undefined;
  21. if (typeof code === "string") {
  22. (0, _genMapping.setSourceContent)(map, this._sourceFileName, code);
  23. } else if (typeof code === "object") {
  24. Object.keys(code).forEach(sourceFileName => {
  25. (0, _genMapping.setSourceContent)(map, sourceFileName.replace(/\\/g, "/"), code[sourceFileName]);
  26. });
  27. }
  28. }
  29. get() {
  30. return (0, _genMapping.toEncodedMap)(this._map);
  31. }
  32. getDecoded() {
  33. return (0, _genMapping.toDecodedMap)(this._map);
  34. }
  35. getRawMappings() {
  36. return this._rawMappings || (this._rawMappings = (0, _genMapping.allMappings)(this._map));
  37. }
  38. mark(generated, line, column, identifierName, filename) {
  39. this._rawMappings = undefined;
  40. (0, _genMapping.maybeAddMapping)(this._map, {
  41. name: identifierName,
  42. generated,
  43. source: line == null ? undefined : (filename == null ? void 0 : filename.replace(/\\/g, "/")) || this._sourceFileName,
  44. original: line == null ? undefined : {
  45. line: line,
  46. column: column
  47. }
  48. });
  49. }
  50. }
  51. exports.default = SourceMap;
  52. //# sourceMappingURL=source-map.js.map