| 1 | (function (global, factory) {
|
|---|
| 2 | if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|---|
| 3 | factory(module, require('@jridgewell/resolve-uri'), require('@jridgewell/sourcemap-codec'));
|
|---|
| 4 | module.exports = def(module);
|
|---|
| 5 | } else if (typeof define === 'function' && define.amd) {
|
|---|
| 6 | define(['module', '@jridgewell/resolve-uri', '@jridgewell/sourcemap-codec'], function(mod) {
|
|---|
| 7 | factory.apply(this, arguments);
|
|---|
| 8 | mod.exports = def(mod);
|
|---|
| 9 | });
|
|---|
| 10 | } else {
|
|---|
| 11 | const mod = { exports: {} };
|
|---|
| 12 | factory(mod, global.resolveURI, global.sourcemapCodec);
|
|---|
| 13 | global = typeof globalThis !== 'undefined' ? globalThis : global || self;
|
|---|
| 14 | global.traceMapping = def(mod);
|
|---|
| 15 | }
|
|---|
| 16 | function def(m) { return 'default' in m.exports ? m.exports.default : m.exports; }
|
|---|
| 17 | })(this, (function (module, require_resolveURI, require_sourcemapCodec) {
|
|---|
| 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 |
|
|---|
| 50 | // umd:@jridgewell/sourcemap-codec
|
|---|
| 51 | var require_sourcemap_codec = __commonJS({
|
|---|
| 52 | "umd:@jridgewell/sourcemap-codec"(exports, module2) {
|
|---|
| 53 | module2.exports = require_sourcemapCodec;
|
|---|
| 54 | }
|
|---|
| 55 | });
|
|---|
| 56 |
|
|---|
| 57 | // umd:@jridgewell/resolve-uri
|
|---|
| 58 | var require_resolve_uri = __commonJS({
|
|---|
| 59 | "umd:@jridgewell/resolve-uri"(exports, module2) {
|
|---|
| 60 | module2.exports = require_resolveURI;
|
|---|
| 61 | }
|
|---|
| 62 | });
|
|---|
| 63 |
|
|---|
| 64 | // src/trace-mapping.ts
|
|---|
| 65 | var trace_mapping_exports = {};
|
|---|
| 66 | __export(trace_mapping_exports, {
|
|---|
| 67 | AnyMap: () => FlattenMap,
|
|---|
| 68 | FlattenMap: () => FlattenMap,
|
|---|
| 69 | GREATEST_LOWER_BOUND: () => GREATEST_LOWER_BOUND,
|
|---|
| 70 | LEAST_UPPER_BOUND: () => LEAST_UPPER_BOUND,
|
|---|
| 71 | TraceMap: () => TraceMap,
|
|---|
| 72 | allGeneratedPositionsFor: () => allGeneratedPositionsFor,
|
|---|
| 73 | decodedMap: () => decodedMap,
|
|---|
| 74 | decodedMappings: () => decodedMappings,
|
|---|
| 75 | eachMapping: () => eachMapping,
|
|---|
| 76 | encodedMap: () => encodedMap,
|
|---|
| 77 | encodedMappings: () => encodedMappings,
|
|---|
| 78 | generatedPositionFor: () => generatedPositionFor,
|
|---|
| 79 | isIgnored: () => isIgnored,
|
|---|
| 80 | originalPositionFor: () => originalPositionFor,
|
|---|
| 81 | presortedDecodedMap: () => presortedDecodedMap,
|
|---|
| 82 | sourceContentFor: () => sourceContentFor,
|
|---|
| 83 | traceSegment: () => traceSegment
|
|---|
| 84 | });
|
|---|
| 85 | module.exports = __toCommonJS(trace_mapping_exports);
|
|---|
| 86 | var import_sourcemap_codec = __toESM(require_sourcemap_codec());
|
|---|
| 87 |
|
|---|
| 88 | // src/resolve.ts
|
|---|
| 89 | var import_resolve_uri = __toESM(require_resolve_uri());
|
|---|
| 90 |
|
|---|
| 91 | // src/strip-filename.ts
|
|---|
| 92 | function stripFilename(path) {
|
|---|
| 93 | if (!path) return "";
|
|---|
| 94 | const index = path.lastIndexOf("/");
|
|---|
| 95 | return path.slice(0, index + 1);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | // src/resolve.ts
|
|---|
| 99 | function resolver(mapUrl, sourceRoot) {
|
|---|
| 100 | const from = stripFilename(mapUrl);
|
|---|
| 101 | const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|---|
| 102 | return (source) => (0, import_resolve_uri.default)(prefix + (source || ""), from);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | // src/sourcemap-segment.ts
|
|---|
| 106 | var COLUMN = 0;
|
|---|
| 107 | var SOURCES_INDEX = 1;
|
|---|
| 108 | var SOURCE_LINE = 2;
|
|---|
| 109 | var SOURCE_COLUMN = 3;
|
|---|
| 110 | var NAMES_INDEX = 4;
|
|---|
| 111 | var REV_GENERATED_LINE = 1;
|
|---|
| 112 | var REV_GENERATED_COLUMN = 2;
|
|---|
| 113 |
|
|---|
| 114 | // src/sort.ts
|
|---|
| 115 | function maybeSort(mappings, owned) {
|
|---|
| 116 | const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|---|
| 117 | if (unsortedIndex === mappings.length) return mappings;
|
|---|
| 118 | if (!owned) mappings = mappings.slice();
|
|---|
| 119 | for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|---|
| 120 | mappings[i] = sortSegments(mappings[i], owned);
|
|---|
| 121 | }
|
|---|
| 122 | return mappings;
|
|---|
| 123 | }
|
|---|
| 124 | function nextUnsortedSegmentLine(mappings, start) {
|
|---|
| 125 | for (let i = start; i < mappings.length; i++) {
|
|---|
| 126 | if (!isSorted(mappings[i])) return i;
|
|---|
| 127 | }
|
|---|
| 128 | return mappings.length;
|
|---|
| 129 | }
|
|---|
| 130 | function isSorted(line) {
|
|---|
| 131 | for (let j = 1; j < line.length; j++) {
|
|---|
| 132 | if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|---|
| 133 | return false;
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 | return true;
|
|---|
| 137 | }
|
|---|
| 138 | function sortSegments(line, owned) {
|
|---|
| 139 | if (!owned) line = line.slice();
|
|---|
| 140 | return line.sort(sortComparator);
|
|---|
| 141 | }
|
|---|
| 142 | function sortComparator(a, b) {
|
|---|
| 143 | return a[COLUMN] - b[COLUMN];
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | // src/by-source.ts
|
|---|
| 147 | function buildBySources(decoded, memos) {
|
|---|
| 148 | const sources = memos.map(() => []);
|
|---|
| 149 | for (let i = 0; i < decoded.length; i++) {
|
|---|
| 150 | const line = decoded[i];
|
|---|
| 151 | for (let j = 0; j < line.length; j++) {
|
|---|
| 152 | const seg = line[j];
|
|---|
| 153 | if (seg.length === 1) continue;
|
|---|
| 154 | const sourceIndex2 = seg[SOURCES_INDEX];
|
|---|
| 155 | const sourceLine = seg[SOURCE_LINE];
|
|---|
| 156 | const sourceColumn = seg[SOURCE_COLUMN];
|
|---|
| 157 | const source = sources[sourceIndex2];
|
|---|
| 158 | const segs = source[sourceLine] || (source[sourceLine] = []);
|
|---|
| 159 | segs.push([sourceColumn, i, seg[COLUMN]]);
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 | for (let i = 0; i < sources.length; i++) {
|
|---|
| 163 | const source = sources[i];
|
|---|
| 164 | for (let j = 0; j < source.length; j++) {
|
|---|
| 165 | const line = source[j];
|
|---|
| 166 | if (line) line.sort(sortComparator);
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 | return sources;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | // src/binary-search.ts
|
|---|
| 173 | var found = false;
|
|---|
| 174 | function binarySearch(haystack, needle, low, high) {
|
|---|
| 175 | while (low <= high) {
|
|---|
| 176 | const mid = low + (high - low >> 1);
|
|---|
| 177 | const cmp = haystack[mid][COLUMN] - needle;
|
|---|
| 178 | if (cmp === 0) {
|
|---|
| 179 | found = true;
|
|---|
| 180 | return mid;
|
|---|
| 181 | }
|
|---|
| 182 | if (cmp < 0) {
|
|---|
| 183 | low = mid + 1;
|
|---|
| 184 | } else {
|
|---|
| 185 | high = mid - 1;
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 188 | found = false;
|
|---|
| 189 | return low - 1;
|
|---|
| 190 | }
|
|---|
| 191 | function upperBound(haystack, needle, index) {
|
|---|
| 192 | for (let i = index + 1; i < haystack.length; index = i++) {
|
|---|
| 193 | if (haystack[i][COLUMN] !== needle) break;
|
|---|
| 194 | }
|
|---|
| 195 | return index;
|
|---|
| 196 | }
|
|---|
| 197 | function lowerBound(haystack, needle, index) {
|
|---|
| 198 | for (let i = index - 1; i >= 0; index = i--) {
|
|---|
| 199 | if (haystack[i][COLUMN] !== needle) break;
|
|---|
| 200 | }
|
|---|
| 201 | return index;
|
|---|
| 202 | }
|
|---|
| 203 | function memoizedState() {
|
|---|
| 204 | return {
|
|---|
| 205 | lastKey: -1,
|
|---|
| 206 | lastNeedle: -1,
|
|---|
| 207 | lastIndex: -1
|
|---|
| 208 | };
|
|---|
| 209 | }
|
|---|
| 210 | function memoizedBinarySearch(haystack, needle, state, key) {
|
|---|
| 211 | const { lastKey, lastNeedle, lastIndex } = state;
|
|---|
| 212 | let low = 0;
|
|---|
| 213 | let high = haystack.length - 1;
|
|---|
| 214 | if (key === lastKey) {
|
|---|
| 215 | if (needle === lastNeedle) {
|
|---|
| 216 | found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|---|
| 217 | return lastIndex;
|
|---|
| 218 | }
|
|---|
| 219 | if (needle >= lastNeedle) {
|
|---|
| 220 | low = lastIndex === -1 ? 0 : lastIndex;
|
|---|
| 221 | } else {
|
|---|
| 222 | high = lastIndex;
|
|---|
| 223 | }
|
|---|
| 224 | }
|
|---|
| 225 | state.lastKey = key;
|
|---|
| 226 | state.lastNeedle = needle;
|
|---|
| 227 | return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | // src/types.ts
|
|---|
| 231 | function parse(map) {
|
|---|
| 232 | return typeof map === "string" ? JSON.parse(map) : map;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | // src/flatten-map.ts
|
|---|
| 236 | var FlattenMap = function(map, mapUrl) {
|
|---|
| 237 | const parsed = parse(map);
|
|---|
| 238 | if (!("sections" in parsed)) {
|
|---|
| 239 | return new TraceMap(parsed, mapUrl);
|
|---|
| 240 | }
|
|---|
| 241 | const mappings = [];
|
|---|
| 242 | const sources = [];
|
|---|
| 243 | const sourcesContent = [];
|
|---|
| 244 | const names = [];
|
|---|
| 245 | const ignoreList = [];
|
|---|
| 246 | recurse(
|
|---|
| 247 | parsed,
|
|---|
| 248 | mapUrl,
|
|---|
| 249 | mappings,
|
|---|
| 250 | sources,
|
|---|
| 251 | sourcesContent,
|
|---|
| 252 | names,
|
|---|
| 253 | ignoreList,
|
|---|
| 254 | 0,
|
|---|
| 255 | 0,
|
|---|
| 256 | Infinity,
|
|---|
| 257 | Infinity
|
|---|
| 258 | );
|
|---|
| 259 | const joined = {
|
|---|
| 260 | version: 3,
|
|---|
| 261 | file: parsed.file,
|
|---|
| 262 | names,
|
|---|
| 263 | sources,
|
|---|
| 264 | sourcesContent,
|
|---|
| 265 | mappings,
|
|---|
| 266 | ignoreList
|
|---|
| 267 | };
|
|---|
| 268 | return presortedDecodedMap(joined);
|
|---|
| 269 | };
|
|---|
| 270 | function recurse(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
|
|---|
| 271 | const { sections } = input;
|
|---|
| 272 | for (let i = 0; i < sections.length; i++) {
|
|---|
| 273 | const { map, offset } = sections[i];
|
|---|
| 274 | let sl = stopLine;
|
|---|
| 275 | let sc = stopColumn;
|
|---|
| 276 | if (i + 1 < sections.length) {
|
|---|
| 277 | const nextOffset = sections[i + 1].offset;
|
|---|
| 278 | sl = Math.min(stopLine, lineOffset + nextOffset.line);
|
|---|
| 279 | if (sl === stopLine) {
|
|---|
| 280 | sc = Math.min(stopColumn, columnOffset + nextOffset.column);
|
|---|
| 281 | } else if (sl < stopLine) {
|
|---|
| 282 | sc = columnOffset + nextOffset.column;
|
|---|
| 283 | }
|
|---|
| 284 | }
|
|---|
| 285 | addSection(
|
|---|
| 286 | map,
|
|---|
| 287 | mapUrl,
|
|---|
| 288 | mappings,
|
|---|
| 289 | sources,
|
|---|
| 290 | sourcesContent,
|
|---|
| 291 | names,
|
|---|
| 292 | ignoreList,
|
|---|
| 293 | lineOffset + offset.line,
|
|---|
| 294 | columnOffset + offset.column,
|
|---|
| 295 | sl,
|
|---|
| 296 | sc
|
|---|
| 297 | );
|
|---|
| 298 | }
|
|---|
| 299 | }
|
|---|
| 300 | function addSection(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
|
|---|
| 301 | const parsed = parse(input);
|
|---|
| 302 | if ("sections" in parsed) return recurse(...arguments);
|
|---|
| 303 | const map = new TraceMap(parsed, mapUrl);
|
|---|
| 304 | const sourcesOffset = sources.length;
|
|---|
| 305 | const namesOffset = names.length;
|
|---|
| 306 | const decoded = decodedMappings(map);
|
|---|
| 307 | const { resolvedSources, sourcesContent: contents, ignoreList: ignores } = map;
|
|---|
| 308 | append(sources, resolvedSources);
|
|---|
| 309 | append(names, map.names);
|
|---|
| 310 | if (contents) append(sourcesContent, contents);
|
|---|
| 311 | else for (let i = 0; i < resolvedSources.length; i++) sourcesContent.push(null);
|
|---|
| 312 | if (ignores) for (let i = 0; i < ignores.length; i++) ignoreList.push(ignores[i] + sourcesOffset);
|
|---|
| 313 | for (let i = 0; i < decoded.length; i++) {
|
|---|
| 314 | const lineI = lineOffset + i;
|
|---|
| 315 | if (lineI > stopLine) return;
|
|---|
| 316 | const out = getLine(mappings, lineI);
|
|---|
| 317 | const cOffset = i === 0 ? columnOffset : 0;
|
|---|
| 318 | const line = decoded[i];
|
|---|
| 319 | for (let j = 0; j < line.length; j++) {
|
|---|
| 320 | const seg = line[j];
|
|---|
| 321 | const column = cOffset + seg[COLUMN];
|
|---|
| 322 | if (lineI === stopLine && column >= stopColumn) return;
|
|---|
| 323 | if (seg.length === 1) {
|
|---|
| 324 | out.push([column]);
|
|---|
| 325 | continue;
|
|---|
| 326 | }
|
|---|
| 327 | const sourcesIndex = sourcesOffset + seg[SOURCES_INDEX];
|
|---|
| 328 | const sourceLine = seg[SOURCE_LINE];
|
|---|
| 329 | const sourceColumn = seg[SOURCE_COLUMN];
|
|---|
| 330 | out.push(
|
|---|
| 331 | seg.length === 4 ? [column, sourcesIndex, sourceLine, sourceColumn] : [column, sourcesIndex, sourceLine, sourceColumn, namesOffset + seg[NAMES_INDEX]]
|
|---|
| 332 | );
|
|---|
| 333 | }
|
|---|
| 334 | }
|
|---|
| 335 | }
|
|---|
| 336 | function append(arr, other) {
|
|---|
| 337 | for (let i = 0; i < other.length; i++) arr.push(other[i]);
|
|---|
| 338 | }
|
|---|
| 339 | function getLine(arr, index) {
|
|---|
| 340 | for (let i = arr.length; i <= index; i++) arr[i] = [];
|
|---|
| 341 | return arr[index];
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | // src/trace-mapping.ts
|
|---|
| 345 | var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|---|
| 346 | var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|---|
| 347 | var LEAST_UPPER_BOUND = -1;
|
|---|
| 348 | var GREATEST_LOWER_BOUND = 1;
|
|---|
| 349 | var TraceMap = class {
|
|---|
| 350 | constructor(map, mapUrl) {
|
|---|
| 351 | const isString = typeof map === "string";
|
|---|
| 352 | if (!isString && map._decodedMemo) return map;
|
|---|
| 353 | const parsed = parse(map);
|
|---|
| 354 | const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|---|
| 355 | this.version = version;
|
|---|
| 356 | this.file = file;
|
|---|
| 357 | this.names = names || [];
|
|---|
| 358 | this.sourceRoot = sourceRoot;
|
|---|
| 359 | this.sources = sources;
|
|---|
| 360 | this.sourcesContent = sourcesContent;
|
|---|
| 361 | this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|---|
| 362 | const resolve = resolver(mapUrl, sourceRoot);
|
|---|
| 363 | this.resolvedSources = sources.map(resolve);
|
|---|
| 364 | const { mappings } = parsed;
|
|---|
| 365 | if (typeof mappings === "string") {
|
|---|
| 366 | this._encoded = mappings;
|
|---|
| 367 | this._decoded = void 0;
|
|---|
| 368 | } else if (Array.isArray(mappings)) {
|
|---|
| 369 | this._encoded = void 0;
|
|---|
| 370 | this._decoded = maybeSort(mappings, isString);
|
|---|
| 371 | } else if (parsed.sections) {
|
|---|
| 372 | throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|---|
| 373 | } else {
|
|---|
| 374 | throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|---|
| 375 | }
|
|---|
| 376 | this._decodedMemo = memoizedState();
|
|---|
| 377 | this._bySources = void 0;
|
|---|
| 378 | this._bySourceMemos = void 0;
|
|---|
| 379 | }
|
|---|
| 380 | };
|
|---|
| 381 | function cast(map) {
|
|---|
| 382 | return map;
|
|---|
| 383 | }
|
|---|
| 384 | function encodedMappings(map) {
|
|---|
| 385 | var _a, _b;
|
|---|
| 386 | return (_b = (_a = cast(map))._encoded) != null ? _b : _a._encoded = (0, import_sourcemap_codec.encode)(cast(map)._decoded);
|
|---|
| 387 | }
|
|---|
| 388 | function decodedMappings(map) {
|
|---|
| 389 | var _a;
|
|---|
| 390 | return (_a = cast(map))._decoded || (_a._decoded = (0, import_sourcemap_codec.decode)(cast(map)._encoded));
|
|---|
| 391 | }
|
|---|
| 392 | function traceSegment(map, line, column) {
|
|---|
| 393 | const decoded = decodedMappings(map);
|
|---|
| 394 | if (line >= decoded.length) return null;
|
|---|
| 395 | const segments = decoded[line];
|
|---|
| 396 | const index = traceSegmentInternal(
|
|---|
| 397 | segments,
|
|---|
| 398 | cast(map)._decodedMemo,
|
|---|
| 399 | line,
|
|---|
| 400 | column,
|
|---|
| 401 | GREATEST_LOWER_BOUND
|
|---|
| 402 | );
|
|---|
| 403 | return index === -1 ? null : segments[index];
|
|---|
| 404 | }
|
|---|
| 405 | function originalPositionFor(map, needle) {
|
|---|
| 406 | let { line, column, bias } = needle;
|
|---|
| 407 | line--;
|
|---|
| 408 | if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|---|
| 409 | if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|---|
| 410 | const decoded = decodedMappings(map);
|
|---|
| 411 | if (line >= decoded.length) return OMapping(null, null, null, null);
|
|---|
| 412 | const segments = decoded[line];
|
|---|
| 413 | const index = traceSegmentInternal(
|
|---|
| 414 | segments,
|
|---|
| 415 | cast(map)._decodedMemo,
|
|---|
| 416 | line,
|
|---|
| 417 | column,
|
|---|
| 418 | bias || GREATEST_LOWER_BOUND
|
|---|
| 419 | );
|
|---|
| 420 | if (index === -1) return OMapping(null, null, null, null);
|
|---|
| 421 | const segment = segments[index];
|
|---|
| 422 | if (segment.length === 1) return OMapping(null, null, null, null);
|
|---|
| 423 | const { names, resolvedSources } = map;
|
|---|
| 424 | return OMapping(
|
|---|
| 425 | resolvedSources[segment[SOURCES_INDEX]],
|
|---|
| 426 | segment[SOURCE_LINE] + 1,
|
|---|
| 427 | segment[SOURCE_COLUMN],
|
|---|
| 428 | segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|---|
| 429 | );
|
|---|
| 430 | }
|
|---|
| 431 | function generatedPositionFor(map, needle) {
|
|---|
| 432 | const { source, line, column, bias } = needle;
|
|---|
| 433 | return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
|
|---|
| 434 | }
|
|---|
| 435 | function allGeneratedPositionsFor(map, needle) {
|
|---|
| 436 | const { source, line, column, bias } = needle;
|
|---|
| 437 | return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true);
|
|---|
| 438 | }
|
|---|
| 439 | function eachMapping(map, cb) {
|
|---|
| 440 | const decoded = decodedMappings(map);
|
|---|
| 441 | const { names, resolvedSources } = map;
|
|---|
| 442 | for (let i = 0; i < decoded.length; i++) {
|
|---|
| 443 | const line = decoded[i];
|
|---|
| 444 | for (let j = 0; j < line.length; j++) {
|
|---|
| 445 | const seg = line[j];
|
|---|
| 446 | const generatedLine = i + 1;
|
|---|
| 447 | const generatedColumn = seg[0];
|
|---|
| 448 | let source = null;
|
|---|
| 449 | let originalLine = null;
|
|---|
| 450 | let originalColumn = null;
|
|---|
| 451 | let name = null;
|
|---|
| 452 | if (seg.length !== 1) {
|
|---|
| 453 | source = resolvedSources[seg[1]];
|
|---|
| 454 | originalLine = seg[2] + 1;
|
|---|
| 455 | originalColumn = seg[3];
|
|---|
| 456 | }
|
|---|
| 457 | if (seg.length === 5) name = names[seg[4]];
|
|---|
| 458 | cb({
|
|---|
| 459 | generatedLine,
|
|---|
| 460 | generatedColumn,
|
|---|
| 461 | source,
|
|---|
| 462 | originalLine,
|
|---|
| 463 | originalColumn,
|
|---|
| 464 | name
|
|---|
| 465 | });
|
|---|
| 466 | }
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 | function sourceIndex(map, source) {
|
|---|
| 470 | const { sources, resolvedSources } = map;
|
|---|
| 471 | let index = sources.indexOf(source);
|
|---|
| 472 | if (index === -1) index = resolvedSources.indexOf(source);
|
|---|
| 473 | return index;
|
|---|
| 474 | }
|
|---|
| 475 | function sourceContentFor(map, source) {
|
|---|
| 476 | const { sourcesContent } = map;
|
|---|
| 477 | if (sourcesContent == null) return null;
|
|---|
| 478 | const index = sourceIndex(map, source);
|
|---|
| 479 | return index === -1 ? null : sourcesContent[index];
|
|---|
| 480 | }
|
|---|
| 481 | function isIgnored(map, source) {
|
|---|
| 482 | const { ignoreList } = map;
|
|---|
| 483 | if (ignoreList == null) return false;
|
|---|
| 484 | const index = sourceIndex(map, source);
|
|---|
| 485 | return index === -1 ? false : ignoreList.includes(index);
|
|---|
| 486 | }
|
|---|
| 487 | function presortedDecodedMap(map, mapUrl) {
|
|---|
| 488 | const tracer = new TraceMap(clone(map, []), mapUrl);
|
|---|
| 489 | cast(tracer)._decoded = map.mappings;
|
|---|
| 490 | return tracer;
|
|---|
| 491 | }
|
|---|
| 492 | function decodedMap(map) {
|
|---|
| 493 | return clone(map, decodedMappings(map));
|
|---|
| 494 | }
|
|---|
| 495 | function encodedMap(map) {
|
|---|
| 496 | return clone(map, encodedMappings(map));
|
|---|
| 497 | }
|
|---|
| 498 | function clone(map, mappings) {
|
|---|
| 499 | return {
|
|---|
| 500 | version: map.version,
|
|---|
| 501 | file: map.file,
|
|---|
| 502 | names: map.names,
|
|---|
| 503 | sourceRoot: map.sourceRoot,
|
|---|
| 504 | sources: map.sources,
|
|---|
| 505 | sourcesContent: map.sourcesContent,
|
|---|
| 506 | mappings,
|
|---|
| 507 | ignoreList: map.ignoreList || map.x_google_ignoreList
|
|---|
| 508 | };
|
|---|
| 509 | }
|
|---|
| 510 | function OMapping(source, line, column, name) {
|
|---|
| 511 | return { source, line, column, name };
|
|---|
| 512 | }
|
|---|
| 513 | function GMapping(line, column) {
|
|---|
| 514 | return { line, column };
|
|---|
| 515 | }
|
|---|
| 516 | function traceSegmentInternal(segments, memo, line, column, bias) {
|
|---|
| 517 | let index = memoizedBinarySearch(segments, column, memo, line);
|
|---|
| 518 | if (found) {
|
|---|
| 519 | index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|---|
| 520 | } else if (bias === LEAST_UPPER_BOUND) index++;
|
|---|
| 521 | if (index === -1 || index === segments.length) return -1;
|
|---|
| 522 | return index;
|
|---|
| 523 | }
|
|---|
| 524 | function sliceGeneratedPositions(segments, memo, line, column, bias) {
|
|---|
| 525 | let min = traceSegmentInternal(segments, memo, line, column, GREATEST_LOWER_BOUND);
|
|---|
| 526 | if (!found && bias === LEAST_UPPER_BOUND) min++;
|
|---|
| 527 | if (min === -1 || min === segments.length) return [];
|
|---|
| 528 | const matchedColumn = found ? column : segments[min][COLUMN];
|
|---|
| 529 | if (!found) min = lowerBound(segments, matchedColumn, min);
|
|---|
| 530 | const max = upperBound(segments, matchedColumn, min);
|
|---|
| 531 | const result = [];
|
|---|
| 532 | for (; min <= max; min++) {
|
|---|
| 533 | const segment = segments[min];
|
|---|
| 534 | result.push(GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]));
|
|---|
| 535 | }
|
|---|
| 536 | return result;
|
|---|
| 537 | }
|
|---|
| 538 | function generatedPosition(map, source, line, column, bias, all) {
|
|---|
| 539 | var _a, _b;
|
|---|
| 540 | line--;
|
|---|
| 541 | if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|---|
| 542 | if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|---|
| 543 | const { sources, resolvedSources } = map;
|
|---|
| 544 | let sourceIndex2 = sources.indexOf(source);
|
|---|
| 545 | if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
|
|---|
| 546 | if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
|
|---|
| 547 | const bySourceMemos = (_a = cast(map))._bySourceMemos || (_a._bySourceMemos = sources.map(memoizedState));
|
|---|
| 548 | const generated = (_b = cast(map))._bySources || (_b._bySources = buildBySources(decodedMappings(map), bySourceMemos));
|
|---|
| 549 | const segments = generated[sourceIndex2][line];
|
|---|
| 550 | if (segments == null) return all ? [] : GMapping(null, null);
|
|---|
| 551 | const memo = bySourceMemos[sourceIndex2];
|
|---|
| 552 | if (all) return sliceGeneratedPositions(segments, memo, line, column, bias);
|
|---|
| 553 | const index = traceSegmentInternal(segments, memo, line, column, bias);
|
|---|
| 554 | if (index === -1) return GMapping(null, null);
|
|---|
| 555 | const segment = segments[index];
|
|---|
| 556 | return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
|---|
| 557 | }
|
|---|
| 558 | }));
|
|---|
| 559 | //# sourceMappingURL=trace-mapping.umd.js.map
|
|---|