Skip to content

Commit 97621d7

Browse files
authored
add sourcemap normalization to fetch loader (#2277)
1 parent f0fe5a4 commit 97621d7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/features/fetch-load.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { errMsg } from '../err-msg.js';
2+
import { resolveUrl } from '../common.js';
23
import { importMap } from '../features/import-maps.js';
34
import { systemJSPrototype } from '../system-core.js';
45

@@ -28,6 +29,13 @@ systemJSPrototype.instantiate = function (url, parent) {
2829
if (!contentType || !jsContentTypeRegEx.test(contentType))
2930
throw Error(errMsg(4, process.env.SYSTEM_PRODUCTION ? contentType : 'Unknown Content-Type "' + contentType + '", loading ' + url + (parent ? ' from ' + parent : '')));
3031
return res.text().then(function (source) {
32+
var sourceMappingIndex = source.lastIndexOf('//# sourceMappingURL=');
33+
if (sourceMappingIndex > -1) {
34+
var sourceMappingEnd = source.indexOf('\n', sourceMappingIndex);
35+
var sourceMapping = source.slice(sourceMappingIndex, sourceMappingEnd > -1 ? sourceMappingEnd : undefined);
36+
source += '\n//# sourceMappingURL=' + resolveUrl(sourceMapping.slice(21), url);
37+
}
38+
source += '\n//# sourceURL=' + url;
3139
(0, eval)(source);
3240
return loader.getRegister();
3341
});

0 commit comments

Comments
 (0)