web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.2 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _sourceMap = _interopRequireDefault(require("source-map"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. class SourceMap {
  9. constructor(opts, code) {
  10. this._cachedMap = void 0;
  11. this._code = void 0;
  12. this._opts = void 0;
  13. this._rawMappings = void 0;
  14. this._lastGenLine = void 0;
  15. this._lastSourceLine = void 0;
  16. this._lastSourceColumn = void 0;
  17. this._cachedMap = null;
  18. this._code = code;
  19. this._opts = opts;
  20. this._rawMappings = [];
  21. }
  22. get() {
  23. if (!this._cachedMap) {
  24. const map = this._cachedMap = new _sourceMap.default.SourceMapGenerator({
  25. sourceRoot: this._opts.sourceRoot
  26. });
  27. const code = this._code;
  28. if (typeof code === "string") {
  29. map.setSourceContent(this._opts.sourceFileName.replace(/\\/g, "/"), code);
  30. } else if (typeof code === "object") {
  31. Object.keys(code).forEach(sourceFileName => {
  32. map.setSourceContent(sourceFileName.replace(/\\/g, "/"), code[sourceFileName]);
  33. });
  34. }
  35. this._rawMappings.forEach(mapping => map.addMapping(mapping), map);
  36. }
  37. return this._cachedMap.toJSON();
  38. }
  39. getRawMappings() {
  40. return this._rawMappings.slice();
  41. }
  42. mark(generatedLine, generatedColumn, line, column, identifierName, filename, force) {
  43. if (this._lastGenLine !== generatedLine && line === null) return;
  44. if (!force && 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).replace(/\\/g, "/"),
  58. original: line == null ? undefined : {
  59. line: line,
  60. column: column
  61. }
  62. });
  63. }
  64. }
  65. exports.default = SourceMap;