source-map.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _sourceMap() {
  7. var data = _interopRequireDefault(require("source-map"));
  8. _sourceMap = function _sourceMap() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. var SourceMap = function () {
  15. function SourceMap(opts, code) {
  16. this._cachedMap = null;
  17. this._code = code;
  18. this._opts = opts;
  19. this._rawMappings = [];
  20. }
  21. var _proto = SourceMap.prototype;
  22. _proto.get = function get() {
  23. if (!this._cachedMap) {
  24. var map = this._cachedMap = new (_sourceMap().default.SourceMapGenerator)({
  25. sourceRoot: this._opts.sourceRoot
  26. });
  27. var code = this._code;
  28. if (typeof code === "string") {
  29. map.setSourceContent(this._opts.sourceFileName, code);
  30. } else if (typeof code === "object") {
  31. Object.keys(code).forEach(function (sourceFileName) {
  32. map.setSourceContent(sourceFileName, code[sourceFileName]);
  33. });
  34. }
  35. this._rawMappings.forEach(map.addMapping, map);
  36. }
  37. return this._cachedMap.toJSON();
  38. };
  39. _proto.getRawMappings = function getRawMappings() {
  40. return this._rawMappings.slice();
  41. };
  42. _proto.mark = function mark(generatedLine, generatedColumn, line, column, identifierName, filename) {
  43. if (this._lastGenLine !== generatedLine && line === null) return;
  44. if (this._lastGenLine === generatedLine && this._lastSourceLine === line && this._lastSourceColumn === column) {
  45. return;
  46. }
  47. this._cachedMap = null;
  48. this._lastGenLine = generatedLine;
  49. this._lastSourceLine = line;
  50. this._lastSourceColumn = column;
  51. this._rawMappings.push({
  52. name: identifierName || undefined,
  53. generated: {
  54. line: generatedLine,
  55. column: generatedColumn
  56. },
  57. source: line == null ? undefined : filename || this._opts.sourceFileName,
  58. original: line == null ? undefined : {
  59. line: line,
  60. column: column
  61. }
  62. });
  63. };
  64. return SourceMap;
  65. }();
  66. exports.default = SourceMap;