From f9c808b5fafc88d76ea52a1c85e29515a93fa858 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Thu, 30 Dec 2021 14:38:27 -0500 Subject: [PATCH] fix(sourcemap): fall back to low-resolution line mapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …inside `Link.traceSegment` instead of returning null, so that a low-resolution sourcemap preceding a high-resolution sourcemap in the sourcemap chain doesn't fail. --- src/utils/collapseSourcemaps.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index 784eadf6696..1d8c302006a 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -117,6 +117,23 @@ class Link { const segments = this.mappings[line]; if (!segments) return null; + // Sometimes a high-resolution sourcemap will be preceded in the sourcemap chain + // by a low-resolution sourcemap. We can detect this by checking if the mappings + // array for this line only contains a segment for column zero. In that case, we + // want to fall back to a low-resolution mapping instead of returning null. + if (segments.length == 1 && segments[0][0] == 0) { + const segment = segments[0]; + if (segment.length == 1) { + return null; + } + const source = this.sources[segment[1]] || null; + return source?.traceSegment( + segment[2], + segment[3], + segment.length === 5 ? this.names[segment[4]] : name + ); + } + // binary search through segments for the given column let i = 0; let j = segments.length - 1;