Skip to content

Commit 944a35d

Browse files
committed
fix
1 parent e150661 commit 944a35d

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

source-map-support.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ function supportRelativeURL(file, url) {
279279
return url;
280280
}
281281
if(path.isAbsolute(url)) {
282-
return url;
283282
// Normalize at all? decodeURI or normalize slashes?
283+
return path.normalize(url);
284284
}
285285
// url is relative path or URL
286286
return path.join(file, '..', decodeURI(url));
@@ -297,6 +297,23 @@ function supportRelativeURL(file, url) {
297297
}
298298
}
299299

300+
// Return pathOrUrl in the same style as matchStyleOf: either a file URL or a native path
301+
function matchStyleOfPathOrUrl(matchStyleOf, pathOrUrl) {
302+
try {
303+
if(isAbsoluteUrl(matchStyleOf) || isSchemeRelativeUrl(matchStyleOf)) {
304+
if(isAbsoluteUrl(pathOrUrl) || isSchemeRelativeUrl(pathOrUrl)) return pathOrUrl;
305+
if(path.isAbsolute(pathOrUrl)) return pathToFileURL(pathOrUrl).toString();
306+
} else if(path.isAbsolute(matchStyleOf)) {
307+
if(isAbsoluteUrl(pathOrUrl) || isSchemeRelativeUrl(pathOrUrl)) {
308+
return fileURLToPath(new URL(pathOrUrl, 'file://'));
309+
}
310+
}
311+
return pathOrUrl;
312+
} catch(e) {
313+
return pathOrUrl;
314+
}
315+
}
316+
300317
function retrieveSourceMapURL(source) {
301318
var fileData;
302319

@@ -375,6 +392,7 @@ function mapSourcePosition(position) {
375392

376393
// Overwrite trace-mapping's resolutions, because they do not handle
377394
// Windows paths the way we want.
395+
// TODO Remove now that windows path support was added to resolve-uri and thus trace-mapping?
378396
sourceMap.map.resolvedSources = sourceMap.map.sources.map(s => supportRelativeURL(sourceMap.url, s));
379397

380398
// Load all sources stored inline with the source map into the file cache
@@ -405,8 +423,11 @@ function mapSourcePosition(position) {
405423
// better to give a precise location in the compiled file than a vague
406424
// location in the original file.
407425
if (originalPosition.source !== null) {
408-
originalPosition.source = supportRelativeURL(
409-
sourceMap.url, originalPosition.source);
426+
// originalPosition.source has *already* been resolved against sourceMap.url
427+
// so is *already* as absolute as possible.
428+
// However, we want to ensure we output in same format as input: URL or native path
429+
originalPosition.source = matchStyleOfPathOrUrl(
430+
position.source, originalPosition.source);
410431
return originalPosition;
411432
}
412433
}

0 commit comments

Comments
 (0)