remapping.umd.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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.remapping = 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/remapping.ts
  62. var remapping_exports = {};
  63. __export(remapping_exports, {
  64. default: () => remapping
  65. });
  66. module.exports = __toCommonJS(remapping_exports);
  67. // src/build-source-map-tree.ts
  68. var import_trace_mapping2 = __toESM(require_trace_mapping());
  69. // src/source-map-tree.ts
  70. var import_gen_mapping = __toESM(require_gen_mapping());
  71. var import_trace_mapping = __toESM(require_trace_mapping());
  72. var SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null, false);
  73. var EMPTY_SOURCES = [];
  74. function SegmentObject(source, line, column, name, content, ignore) {
  75. return { source, line, column, name, content, ignore };
  76. }
  77. function Source(map, sources, source, content, ignore) {
  78. return {
  79. map,
  80. sources,
  81. source,
  82. content,
  83. ignore
  84. };
  85. }
  86. function MapSource(map, sources) {
  87. return Source(map, sources, "", null, false);
  88. }
  89. function OriginalSource(source, content, ignore) {
  90. return Source(null, EMPTY_SOURCES, source, content, ignore);
  91. }
  92. function traceMappings(tree) {
  93. const gen = new import_gen_mapping.GenMapping({ file: tree.map.file });
  94. const { sources: rootSources, map } = tree;
  95. const rootNames = map.names;
  96. const rootMappings = (0, import_trace_mapping.decodedMappings)(map);
  97. for (let i = 0; i < rootMappings.length; i++) {
  98. const segments = rootMappings[i];
  99. for (let j = 0; j < segments.length; j++) {
  100. const segment = segments[j];
  101. const genCol = segment[0];
  102. let traced = SOURCELESS_MAPPING;
  103. if (segment.length !== 1) {
  104. const source2 = rootSources[segment[1]];
  105. traced = originalPositionFor(
  106. source2,
  107. segment[2],
  108. segment[3],
  109. segment.length === 5 ? rootNames[segment[4]] : ""
  110. );
  111. if (traced == null) continue;
  112. }
  113. const { column, line, name, content, source, ignore } = traced;
  114. (0, import_gen_mapping.maybeAddSegment)(gen, i, genCol, source, line, column, name);
  115. if (source && content != null) (0, import_gen_mapping.setSourceContent)(gen, source, content);
  116. if (ignore) (0, import_gen_mapping.setIgnore)(gen, source, true);
  117. }
  118. }
  119. return gen;
  120. }
  121. function originalPositionFor(source, line, column, name) {
  122. if (!source.map) {
  123. return SegmentObject(source.source, line, column, name, source.content, source.ignore);
  124. }
  125. const segment = (0, import_trace_mapping.traceSegment)(source.map, line, column);
  126. if (segment == null) return null;
  127. if (segment.length === 1) return SOURCELESS_MAPPING;
  128. return originalPositionFor(
  129. source.sources[segment[1]],
  130. segment[2],
  131. segment[3],
  132. segment.length === 5 ? source.map.names[segment[4]] : name
  133. );
  134. }
  135. // src/build-source-map-tree.ts
  136. function asArray(value) {
  137. if (Array.isArray(value)) return value;
  138. return [value];
  139. }
  140. function buildSourceMapTree(input, loader) {
  141. const maps = asArray(input).map((m) => new import_trace_mapping2.TraceMap(m, ""));
  142. const map = maps.pop();
  143. for (let i = 0; i < maps.length; i++) {
  144. if (maps[i].sources.length > 1) {
  145. throw new Error(
  146. `Transformation map ${i} must have exactly one source file.
  147. Did you specify these with the most recent transformation maps first?`
  148. );
  149. }
  150. }
  151. let tree = build(map, loader, "", 0);
  152. for (let i = maps.length - 1; i >= 0; i--) {
  153. tree = MapSource(maps[i], [tree]);
  154. }
  155. return tree;
  156. }
  157. function build(map, loader, importer, importerDepth) {
  158. const { resolvedSources, sourcesContent, ignoreList } = map;
  159. const depth = importerDepth + 1;
  160. const children = resolvedSources.map((sourceFile, i) => {
  161. const ctx = {
  162. importer,
  163. depth,
  164. source: sourceFile || "",
  165. content: void 0,
  166. ignore: void 0
  167. };
  168. const sourceMap = loader(ctx.source, ctx);
  169. const { source, content, ignore } = ctx;
  170. if (sourceMap) return build(new import_trace_mapping2.TraceMap(sourceMap, source), loader, source, depth);
  171. const sourceContent = content !== void 0 ? content : sourcesContent ? sourcesContent[i] : null;
  172. const ignored = ignore !== void 0 ? ignore : ignoreList ? ignoreList.includes(i) : false;
  173. return OriginalSource(source, sourceContent, ignored);
  174. });
  175. return MapSource(map, children);
  176. }
  177. // src/source-map.ts
  178. var import_gen_mapping2 = __toESM(require_gen_mapping());
  179. var SourceMap = class {
  180. constructor(map, options) {
  181. const out = options.decodedMappings ? (0, import_gen_mapping2.toDecodedMap)(map) : (0, import_gen_mapping2.toEncodedMap)(map);
  182. this.version = out.version;
  183. this.file = out.file;
  184. this.mappings = out.mappings;
  185. this.names = out.names;
  186. this.ignoreList = out.ignoreList;
  187. this.sourceRoot = out.sourceRoot;
  188. this.sources = out.sources;
  189. if (!options.excludeContent) {
  190. this.sourcesContent = out.sourcesContent;
  191. }
  192. }
  193. toString() {
  194. return JSON.stringify(this);
  195. }
  196. };
  197. // src/remapping.ts
  198. function remapping(input, loader, options) {
  199. const opts = typeof options === "object" ? options : { excludeContent: !!options, decodedMappings: false };
  200. const tree = buildSourceMapTree(input, loader);
  201. return new SourceMap(traceMappings(tree), opts);
  202. }
  203. }));
  204. //# sourceMappingURL=remapping.umd.js.map