source-map.umd.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. (function (global, factory) {
  2. if (typeof exports === 'object' && typeof module !== 'undefined') {
  3. factory(module, require('@jridgewell/gen-mapping'), require('@jridgewell/trace-mapping'));
  4. module.exports = def(module);
  5. } else if (typeof define === 'function' && define.amd) {
  6. define(['module', '@jridgewell/gen-mapping', '@jridgewell/trace-mapping'], function(mod) {
  7. factory.apply(this, arguments);
  8. mod.exports = def(mod);
  9. });
  10. } else {
  11. const mod = { exports: {} };
  12. factory(mod, global.genMapping, global.traceMapping);
  13. global = typeof globalThis !== 'undefined' ? globalThis : global || self;
  14. global.sourceMap = def(mod);
  15. }
  16. function def(m) { return 'default' in m.exports ? m.exports.default : m.exports; }
  17. })(this, (function (module, require_genMapping, require_traceMapping) {
  18. "use strict";
  19. var __create = Object.create;
  20. var __defProp = Object.defineProperty;
  21. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  22. var __getOwnPropNames = Object.getOwnPropertyNames;
  23. var __getProtoOf = Object.getPrototypeOf;
  24. var __hasOwnProp = Object.prototype.hasOwnProperty;
  25. var __commonJS = (cb, mod) => function __require() {
  26. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  27. };
  28. var __export = (target, all) => {
  29. for (var name in all)
  30. __defProp(target, name, { get: all[name], enumerable: true });
  31. };
  32. var __copyProps = (to, from, except, desc) => {
  33. if (from && typeof from === "object" || typeof from === "function") {
  34. for (let key of __getOwnPropNames(from))
  35. if (!__hasOwnProp.call(to, key) && key !== except)
  36. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  37. }
  38. return to;
  39. };
  40. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  41. // If the importer is in node compatibility mode or this is not an ESM
  42. // file that has been converted to a CommonJS file using a Babel-
  43. // compatible transform (i.e. "__esModule" has not been set), then set
  44. // "default" to the CommonJS "module.exports" for node compatibility.
  45. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  46. mod
  47. ));
  48. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  49. // umd:@jridgewell/trace-mapping
  50. var require_trace_mapping = __commonJS({
  51. "umd:@jridgewell/trace-mapping"(exports, module2) {
  52. module2.exports = require_traceMapping;
  53. }
  54. });
  55. // umd:@jridgewell/gen-mapping
  56. var require_gen_mapping = __commonJS({
  57. "umd:@jridgewell/gen-mapping"(exports, module2) {
  58. module2.exports = require_genMapping;
  59. }
  60. });
  61. // src/source-map.ts
  62. var source_map_exports = {};
  63. __export(source_map_exports, {
  64. SourceMapConsumer: () => SourceMapConsumer,
  65. SourceMapGenerator: () => SourceMapGenerator
  66. });
  67. module.exports = __toCommonJS(source_map_exports);
  68. var import_trace_mapping = __toESM(require_trace_mapping());
  69. var import_gen_mapping = __toESM(require_gen_mapping());
  70. var SourceMapConsumer = class _SourceMapConsumer {
  71. constructor(map, mapUrl) {
  72. const trace = this._map = new import_trace_mapping.AnyMap(map, mapUrl);
  73. this.file = trace.file;
  74. this.names = trace.names;
  75. this.sourceRoot = trace.sourceRoot;
  76. this.sources = trace.resolvedSources;
  77. this.sourcesContent = trace.sourcesContent;
  78. this.version = trace.version;
  79. }
  80. static fromSourceMap(map, mapUrl) {
  81. if (map.toDecodedMap) {
  82. return new _SourceMapConsumer(map.toDecodedMap(), mapUrl);
  83. }
  84. return new _SourceMapConsumer(map.toJSON(), mapUrl);
  85. }
  86. get mappings() {
  87. return (0, import_trace_mapping.encodedMappings)(this._map);
  88. }
  89. originalPositionFor(needle) {
  90. return (0, import_trace_mapping.originalPositionFor)(this._map, needle);
  91. }
  92. generatedPositionFor(originalPosition) {
  93. return (0, import_trace_mapping.generatedPositionFor)(this._map, originalPosition);
  94. }
  95. allGeneratedPositionsFor(originalPosition) {
  96. return (0, import_trace_mapping.allGeneratedPositionsFor)(this._map, originalPosition);
  97. }
  98. hasContentsOfAllSources() {
  99. if (!this.sourcesContent || this.sourcesContent.length !== this.sources.length) {
  100. return false;
  101. }
  102. for (const content of this.sourcesContent) {
  103. if (content == null) {
  104. return false;
  105. }
  106. }
  107. return true;
  108. }
  109. sourceContentFor(source, nullOnMissing) {
  110. const sourceContent = (0, import_trace_mapping.sourceContentFor)(this._map, source);
  111. if (sourceContent != null) {
  112. return sourceContent;
  113. }
  114. if (nullOnMissing) {
  115. return null;
  116. }
  117. throw new Error(`"${source}" is not in the SourceMap.`);
  118. }
  119. eachMapping(callback, context) {
  120. (0, import_trace_mapping.eachMapping)(this._map, context ? callback.bind(context) : callback);
  121. }
  122. destroy() {
  123. }
  124. };
  125. var SourceMapGenerator = class _SourceMapGenerator {
  126. constructor(opts) {
  127. this._map = opts instanceof import_gen_mapping.GenMapping ? opts : new import_gen_mapping.GenMapping(opts);
  128. }
  129. static fromSourceMap(consumer) {
  130. return new _SourceMapGenerator((0, import_gen_mapping.fromMap)(consumer));
  131. }
  132. addMapping(mapping) {
  133. (0, import_gen_mapping.maybeAddMapping)(this._map, mapping);
  134. }
  135. setSourceContent(source, content) {
  136. (0, import_gen_mapping.setSourceContent)(this._map, source, content);
  137. }
  138. toJSON() {
  139. return (0, import_gen_mapping.toEncodedMap)(this._map);
  140. }
  141. toString() {
  142. return JSON.stringify(this.toJSON());
  143. }
  144. toDecodedMap() {
  145. return (0, import_gen_mapping.toDecodedMap)(this._map);
  146. }
  147. };
  148. }));
  149. //# sourceMappingURL=source-map.umd.js.map