Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 72a4ee2

Browse files
committed
Add ignoreList support
1 parent d791f83 commit 72a4ee2

10 files changed

+220
-69
lines changed

package-lock.json

Lines changed: 44 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"typescript": "4.6.3"
7070
},
7171
"dependencies": {
72-
"@jridgewell/gen-mapping": "^0.3.0",
73-
"@jridgewell/trace-mapping": "^0.3.9"
72+
"@jridgewell/gen-mapping": "^0.3.5",
73+
"@jridgewell/trace-mapping": "^0.3.24"
7474
}
7575
}

src/build-source-map-tree.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function build(
5050
importer: string,
5151
importerDepth: number
5252
): MapSourceType {
53-
const { resolvedSources, sourcesContent } = map;
53+
const { resolvedSources, sourcesContent, ignoreList } = map;
5454

5555
const depth = importerDepth + 1;
5656
const children = resolvedSources.map((sourceFile: string | null, i: number): Sources => {
@@ -63,24 +63,26 @@ function build(
6363
depth,
6464
source: sourceFile || '',
6565
content: undefined,
66+
ignore: undefined,
6667
};
6768

6869
// Use the provided loader callback to retrieve the file's sourcemap.
6970
// TODO: We should eventually support async loading of sourcemap files.
7071
const sourceMap = loader(ctx.source, ctx);
7172

72-
const { source, content } = ctx;
73+
const { source, content, ignore } = ctx;
7374

7475
// If there is a sourcemap, then we need to recurse into it to load its source files.
7576
if (sourceMap) return build(new TraceMap(sourceMap, source), loader, source, depth);
7677

77-
// Else, it's an an unmodified source file.
78+
// Else, it's an unmodified source file.
7879
// The contents of this unmodified source file can be overridden via the loader context,
7980
// allowing it to be explicitly null or a string. If it remains undefined, we fall back to
8081
// the importing sourcemap's `sourcesContent` field.
8182
const sourceContent =
8283
content !== undefined ? content : sourcesContent ? sourcesContent[i] : null;
83-
return OriginalSource(source, sourceContent);
84+
const ignored = ignore !== undefined ? ignore : ignoreList ? ignoreList.includes(i) : false;
85+
return OriginalSource(source, sourceContent, ignored);
8486
});
8587

8688
return MapSource(map, children);

src/source-map-tree.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GenMapping, maybeAddSegment, setSourceContent } from '@jridgewell/gen-mapping';
1+
import { GenMapping, maybeAddSegment, setIgnore, setSourceContent } from '@jridgewell/gen-mapping';
22
import { traceSegment, decodedMappings } from '@jridgewell/trace-mapping';
33

44
import type { TraceMap } from '@jridgewell/trace-mapping';
@@ -9,55 +9,68 @@ export type SourceMapSegmentObject = {
99
name: string;
1010
source: string;
1111
content: string | null;
12+
ignore: boolean;
1213
};
1314

1415
export type OriginalSource = {
1516
map: null;
1617
sources: Sources[];
1718
source: string;
1819
content: string | null;
20+
ignore: boolean;
1921
};
2022

2123
export type MapSource = {
2224
map: TraceMap;
2325
sources: Sources[];
2426
source: string;
2527
content: null;
28+
ignore: false;
2629
};
2730

2831
export type Sources = OriginalSource | MapSource;
2932

30-
const SOURCELESS_MAPPING = /* #__PURE__ */ SegmentObject('', -1, -1, '', null);
33+
const SOURCELESS_MAPPING = /* #__PURE__ */ SegmentObject('', -1, -1, '', null, false);
3134
const EMPTY_SOURCES: Sources[] = [];
3235

3336
function SegmentObject(
3437
source: string,
3538
line: number,
3639
column: number,
3740
name: string,
38-
content: string | null
41+
content: string | null,
42+
ignore: boolean
3943
): SourceMapSegmentObject {
40-
return { source, line, column, name, content };
44+
return { source, line, column, name, content, ignore };
4145
}
4246

43-
function Source(map: TraceMap, sources: Sources[], source: '', content: null): MapSource;
47+
function Source(
48+
map: TraceMap,
49+
sources: Sources[],
50+
source: '',
51+
content: null,
52+
ignore: false
53+
): MapSource;
4454
function Source(
4555
map: null,
4656
sources: Sources[],
4757
source: string,
48-
content: string | null
58+
content: string | null,
59+
ignore: boolean
4960
): OriginalSource;
5061
function Source(
5162
map: TraceMap | null,
5263
sources: Sources[],
5364
source: string | '',
54-
content: string | null
65+
content: string | null,
66+
ignore: boolean
5567
): Sources {
5668
return {
5769
map,
5870
sources,
5971
source,
6072
content,
73+
ignore,
6174
} as any;
6275
}
6376

@@ -66,15 +79,19 @@ function Source(
6679
* (which may themselves be SourceMapTrees).
6780
*/
6881
export function MapSource(map: TraceMap, sources: Sources[]): MapSource {
69-
return Source(map, sources, '', null);
82+
return Source(map, sources, '', null, false);
7083
}
7184

7285
/**
7386
* A "leaf" node in the sourcemap tree, representing an original, unmodified source file. Recursive
7487
* segment tracing ends at the `OriginalSource`.
7588
*/
76-
export function OriginalSource(source: string, content: string | null): OriginalSource {
77-
return Source(null, EMPTY_SOURCES, source, content);
89+
export function OriginalSource(
90+
source: string,
91+
content: string | null,
92+
ignore: boolean
93+
): OriginalSource {
94+
return Source(null, EMPTY_SOURCES, source, content, ignore);
7895
}
7996

8097
/**
@@ -113,10 +130,11 @@ export function traceMappings(tree: MapSource): GenMapping {
113130
if (traced == null) continue;
114131
}
115132

116-
const { column, line, name, content, source } = traced;
133+
const { column, line, name, content, source, ignore } = traced;
117134

118135
maybeAddSegment(gen, i, genCol, source, line, column, name);
119136
if (source && content != null) setSourceContent(gen, source, content);
137+
if (ignore) setIgnore(gen, source, true);
120138
}
121139
}
122140

@@ -134,7 +152,7 @@ export function originalPositionFor(
134152
name: string
135153
): SourceMapSegmentObject | null {
136154
if (!source.map) {
137-
return SegmentObject(source.source, line, column, name, source.content);
155+
return SegmentObject(source.source, line, column, name, source.content, source.ignore);
138156
}
139157

140158
const segment = traceSegment(source.map, line, column);

src/source-map.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ export default class SourceMap {
1515
declare sources: (string | null)[];
1616
declare sourcesContent?: (string | null)[];
1717
declare version: 3;
18+
declare ignoreList: number[] | undefined;
1819

1920
constructor(map: GenMapping, options: Options) {
2021
const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
2122
this.version = out.version; // SourceMap spec says this should be first.
2223
this.file = out.file;
2324
this.mappings = out.mappings as SourceMap['mappings'];
2425
this.names = out.names as SourceMap['names'];
25-
26+
this.ignoreList = out.ignoreList as SourceMap['ignoreList'];
2627
this.sourceRoot = out.sourceRoot;
2728

2829
this.sources = out.sources as SourceMap['sources'];

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type LoaderContext = {
1313
readonly depth: number;
1414
source: string;
1515
content: string | null | undefined;
16+
ignore: boolean | undefined;
1617
};
1718

1819
export type SourceMapLoader = (

0 commit comments

Comments
 (0)