Skip to content

Commit 996cbef

Browse files
committed
remapping: get most test cases passing
* add back line information for traceSegmentsInRange because it needs to be represented somehow in the return result (an alternative would be a start line + array of arrays) * fixes most range mapping remapping test failures that came up due to rebasing these patches
1 parent ae462f0 commit 996cbef

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

packages/remapping/src/source-map-tree.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export function originalPositionFor(
262262
// If we couldn't find a segment, then this doesn't exist in the sourcemap.
263263
if (segment == null) return null;
264264
const maybeRange = isRange(source.map, segment);
265-
let startLine = 0; // FIXME this should be the line of the segment
265+
let startLine = line;
266266
if (maybeRange) {
267267
startLine = maybeRange.line;
268268
}
@@ -320,27 +320,25 @@ function originalPositionsForRange(
320320
];
321321
}
322322

323-
// We additional trace the start position of the range to because we may need to
323+
// We additionally trace the start position of the range to because we may need to
324324
// intersect with a range that starts before the given position, or map the start
325325
// of the range to it if there aren't any exact hits.
326326
const initialSegment = traceSegment(source.map, line, column);
327327
const segments = traceSegmentsInRange(source.map, line, column, endLine, endColumn);
328328

329329
// If tracing the start of the range hits a mapping that isn't in the segmenObjects list,
330330
// add it to the list to process first.
331-
if (initialSegment !== null && (segments.length === 0 || initialSegment !== segments[0])) {
332-
segments.splice(0, 0, initialSegment);
331+
if (initialSegment !== null && (segments.length === 0 || initialSegment !== segments[0][1])) {
332+
segments.splice(0, 0, [line, initialSegment]);
333333
}
334334

335335
const originalPositions = [];
336-
for (const segment of segments) {
336+
for (const [startLine, segment] of segments) {
337337
if (segment == null) continue;
338338

339-
let startLine = 0; // FIXME this should be the line of the segment
340339
let childEndLine, endSegment;
341340
const maybeRange = isRange(source.map, segment);
342341
if (maybeRange) {
343-
startLine = maybeRange.line;
344342
childEndLine = maybeRange.endLine;
345343
endSegment = maybeRange.endSegment;
346344
}

packages/trace-mapping/src/trace-mapping.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export function traceSegmentsInRange(
289289
startColumn: number,
290290
endLine: number,
291291
endColumn: number,
292-
): Readonly<SourceMapSegment>[] {
292+
): [number, Readonly<SourceMapSegment>][] {
293293
const lines = decodedMappings(map);
294294
const segments = startLine < lines.length ? lines[startLine] : [];
295295
const memo = cast(map)._decodedMemo;
@@ -309,9 +309,11 @@ export function traceSegmentsInRange(
309309
const range = (start: number, end: number) => {
310310
return Array.from({ length: end - start + 1 }, (_, i: number) => i + start);
311311
};
312-
const gen = (line: number) => (index: number) => {
313-
return lines[line][index];
314-
};
312+
function gen(line: number) {
313+
return (index: number) : [number, Readonly<SourceMapSegment>] => {
314+
return [line, lines[line][index]];
315+
};
316+
}
315317

316318
function previousPosition(line: number, column: number) {
317319
if (column === 0) {

0 commit comments

Comments
 (0)