@@ -279,8 +279,8 @@ function supportRelativeURL(file, url) {
279
279
return url ;
280
280
}
281
281
if ( path . isAbsolute ( url ) ) {
282
- return url ;
283
282
// Normalize at all? decodeURI or normalize slashes?
283
+ return path . normalize ( url ) ;
284
284
}
285
285
// url is relative path or URL
286
286
return path . join ( file , '..' , decodeURI ( url ) ) ;
@@ -297,6 +297,23 @@ function supportRelativeURL(file, url) {
297
297
}
298
298
}
299
299
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
+
300
317
function retrieveSourceMapURL ( source ) {
301
318
var fileData ;
302
319
@@ -375,6 +392,7 @@ function mapSourcePosition(position) {
375
392
376
393
// Overwrite trace-mapping's resolutions, because they do not handle
377
394
// Windows paths the way we want.
395
+ // TODO Remove now that windows path support was added to resolve-uri and thus trace-mapping?
378
396
sourceMap . map . resolvedSources = sourceMap . map . sources . map ( s => supportRelativeURL ( sourceMap . url , s ) ) ;
379
397
380
398
// Load all sources stored inline with the source map into the file cache
@@ -405,8 +423,11 @@ function mapSourcePosition(position) {
405
423
// better to give a precise location in the compiled file than a vague
406
424
// location in the original file.
407
425
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 ) ;
410
431
return originalPosition ;
411
432
}
412
433
}
0 commit comments