source-map.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. exports.__esModule = true;
  3. var _keys = require("babel-runtime/core-js/object/keys");
  4. var _keys2 = _interopRequireDefault(_keys);
  5. var _typeof2 = require("babel-runtime/helpers/typeof");
  6. var _typeof3 = _interopRequireDefault(_typeof2);
  7. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  8. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  9. var _sourceMap = require("source-map");
  10. var _sourceMap2 = _interopRequireDefault(_sourceMap);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. var SourceMap = function () {
  13. function SourceMap(opts, code) {
  14. var _this = this;
  15. (0, _classCallCheck3.default)(this, SourceMap);
  16. this._opts = opts;
  17. this._map = new _sourceMap2.default.SourceMapGenerator({
  18. file: opts.sourceMapTarget,
  19. sourceRoot: opts.sourceRoot
  20. });
  21. if (typeof code === "string") {
  22. this._map.setSourceContent(opts.sourceFileName, code);
  23. } else if ((typeof code === "undefined" ? "undefined" : (0, _typeof3.default)(code)) === "object") {
  24. (0, _keys2.default)(code).forEach(function (sourceFileName) {
  25. _this._map.setSourceContent(sourceFileName, code[sourceFileName]);
  26. });
  27. }
  28. }
  29. SourceMap.prototype.get = function get() {
  30. return this._map.toJSON();
  31. };
  32. SourceMap.prototype.mark = function mark(generatedLine, generatedColumn, line, column, identifierName, filename) {
  33. if (this._lastGenLine !== generatedLine && line === null) return;
  34. if (this._lastGenLine === generatedLine && this._lastSourceLine === line && this._lastSourceColumn === column) {
  35. return;
  36. }
  37. this._lastGenLine = generatedLine;
  38. this._lastSourceLine = line;
  39. this._lastSourceColumn = column;
  40. this._map.addMapping({
  41. name: identifierName,
  42. generated: {
  43. line: generatedLine,
  44. column: generatedColumn
  45. },
  46. source: line == null ? null : filename || this._opts.sourceFileName,
  47. original: line == null ? null : {
  48. line: line,
  49. column: column
  50. }
  51. });
  52. };
  53. return SourceMap;
  54. }();
  55. exports.default = SourceMap;
  56. module.exports = exports["default"];