source: frontend/node_modules/@jridgewell/trace-mapping/src/by-source.ts

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: 1.2 KB
Line 
1import { COLUMN, SOURCES_INDEX, SOURCE_LINE, SOURCE_COLUMN } from './sourcemap-segment';
2import { sortComparator } from './sort';
3
4import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment';
5
6export type Source = ReverseSegment[][];
7
8// Rebuilds the original source files, with mappings that are ordered by source line/column instead
9// of generated line/column.
10export default function buildBySources(
11 decoded: readonly SourceMapSegment[][],
12 memos: unknown[],
13): Source[] {
14 const sources: Source[] = memos.map(() => []);
15
16 for (let i = 0; i < decoded.length; i++) {
17 const line = decoded[i];
18 for (let j = 0; j < line.length; j++) {
19 const seg = line[j];
20 if (seg.length === 1) continue;
21
22 const sourceIndex = seg[SOURCES_INDEX];
23 const sourceLine = seg[SOURCE_LINE];
24 const sourceColumn = seg[SOURCE_COLUMN];
25
26 const source = sources[sourceIndex];
27 const segs = (source[sourceLine] ||= []);
28 segs.push([sourceColumn, i, seg[COLUMN]]);
29 }
30 }
31
32 for (let i = 0; i < sources.length; i++) {
33 const source = sources[i];
34 for (let j = 0; j < source.length; j++) {
35 const line = source[j];
36 if (line) line.sort(sortComparator);
37 }
38 }
39
40 return sources;
41}
Note: See TracBrowser for help on using the repository browser.