fix(source-maps): resolve empty sourceRoot sources against the map URL (#8107)

webpack 5 and tsc write "sourceRoot": "" for map-relative sources. Since
5f702dd6c the shared join added "/" for any non-null root, so these
sources resolved from the URL root: rxjs's ../../../src/internal/Observable.ts
under /npm/rxjs@7.8.1/dist/cjs/internal/ became /src/internal/Observable.ts,
and xterm's webpack://xterm/./src/... became https://host/webpack://xterm/....

Treat an empty root like a null root in sourceMapReference, the single join
used by trace-web-source-location, analyze-javascript-application and the
web source-map fetcher. Chrome, Firefox and trace-mapping skip an empty root,
and tc39/ecma426#183 wrote the current steps to match them. Non-empty roots,
including "/" and repeated slashes (#6726), keep their existing behavior.

Fixes #8106

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822andClaude Opus 5.5 authored and GitHub committed 2026-10-30 01:00:41 -07:00
1 parent 0ce76e70f4
commit 24398a89e4
6 files changed
+108 -9

No files matched your search

@@ -57,11 +57,19 @@ export const resolveJavaScriptSourceMapUrl = (
);
};
/**
* Prefix a source with its declared root before URL resolution. An empty root
* adds no prefix: webpack 5 and tsc emit `"sourceRoot": ""` for map-relative
* sources. Chrome, Firefox and trace-mapping all skip it, and ECMA-426's
* DecodeSourceMapSources steps were written to match them (tc39/ecma426#183).
* Only a non-empty root gains a `/` separator, so repeated slashes stay
* significant.
*/
const sourceMapReference = (
source: string,
sourceRoot: string | null | undefined,
): string => {
if (sourceRoot == null) return source;
if (sourceRoot == null || sourceRoot === "") return source;
return `${sourceRoot}${sourceRoot.endsWith("/") ? "" : "/"}${source}`;
};