source: frontend/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

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