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

Commit 3429b0b

Browse files
committed
Use maybeAddSegment to declutter mappings
Instead of implementing this in the remapping package, it's done inside the generator package.
1 parent cb14ea8 commit 3429b0b

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"typescript": "4.6.3"
5858
},
5959
"dependencies": {
60-
"@jridgewell/gen-mapping": "^0.2.0",
60+
"@jridgewell/gen-mapping": "^0.3.0",
6161
"@jridgewell/trace-mapping": "^0.3.9"
6262
}
6363
}

src/source-map-tree.ts

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

44
import type { TraceMap } from '@jridgewell/trace-mapping';
@@ -79,6 +79,8 @@ export function OriginalSource(source: string, content: string | null): Original
7979
* resolving each mapping in terms of the original source files.
8080
*/
8181
export function traceMappings(tree: MapSource): GenMapping {
82+
// TODO: Eventually support sourceRoot, which has to be removed because the sources are already
83+
// fully resolved. We'll need to make sources relative to the sourceRoot before adding them.
8284
const gen = new GenMapping({ file: tree.map.file });
8385
const { sources: rootSources, map } = tree;
8486
const rootNames = map.names;
@@ -87,10 +89,6 @@ export function traceMappings(tree: MapSource): GenMapping {
8789
for (let i = 0; i < rootMappings.length; i++) {
8890
const segments = rootMappings[i];
8991

90-
let lastSource = null;
91-
let lastSourceLine = null;
92-
let lastSourceColumn = null;
93-
9492
for (let j = 0; j < segments.length; j++) {
9593
const segment = segments[j];
9694
const genCol = segment[0];
@@ -112,19 +110,11 @@ export function traceMappings(tree: MapSource): GenMapping {
112110
if (traced == null) continue;
113111
}
114112

115-
// So we traced a segment down into its original source file. Now push a
116-
// new segment pointing to this location.
117113
const { column, line, name, content, source } = traced;
118-
if (line === lastSourceLine && column === lastSourceColumn && source === lastSource) {
119-
continue;
120-
}
121-
lastSourceLine = line;
122-
lastSourceColumn = column;
123-
lastSource = source;
124114

125115
// Sigh, TypeScript can't figure out source/line/column are either all null, or all non-null...
126-
(addSegment as any)(gen, i, genCol, source, line, column, name);
127-
if (content != null) setSourceContent(gen, source, content);
116+
(maybeAddSegment as any)(gen, i, genCol, source, line, column, name);
117+
if (source && content != null) setSourceContent(gen, source, content);
128118
}
129119
}
130120

0 commit comments

Comments
 (0)