Lazy-install sourceMapSupport (#6651)
* Install sourceMapSupport only when sourceMaps are requested * Add tests for sourceMapSupport * Fix sourceMap position for tests * Fix gen_error file * fix the test descriptions * Refactor install sourceMap support * Run sourceMapSupport only once * Handle cases where sourceMaps is undefined
This commit is contained in:
committed by
Logan Smyth
parent
aefbb1380e
commit
83cd3fb2c9
@@ -12,21 +12,23 @@ const maps = {};
|
||||
const transformOpts = {};
|
||||
let piratesRevert = null;
|
||||
|
||||
sourceMapSupport.install({
|
||||
handleUncaughtExceptions: false,
|
||||
environment: "node",
|
||||
retrieveSourceMap(source) {
|
||||
const map = maps && maps[source];
|
||||
if (map) {
|
||||
return {
|
||||
url: null,
|
||||
map: map,
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
function installSourceMapSupport() {
|
||||
sourceMapSupport.install({
|
||||
handleUncaughtExceptions: false,
|
||||
environment: "node",
|
||||
retrieveSourceMap(source) {
|
||||
const map = maps && maps[source];
|
||||
if (map) {
|
||||
return {
|
||||
url: null,
|
||||
map: map,
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
registerCache.load();
|
||||
let cache = registerCache.get();
|
||||
@@ -67,7 +69,7 @@ function compile(code, filename) {
|
||||
// Do not process config files since has already been done with the OptionManager
|
||||
// calls above and would introduce duplicates.
|
||||
babelrc: false,
|
||||
sourceMaps: "both",
|
||||
sourceMaps: opts.sourceMaps === undefined ? "both" : opts.sourceMaps,
|
||||
ast: false,
|
||||
}),
|
||||
);
|
||||
@@ -77,7 +79,12 @@ function compile(code, filename) {
|
||||
result.mtime = mtime(filename);
|
||||
}
|
||||
|
||||
maps[filename] = result.map;
|
||||
if (result.map) {
|
||||
if (Object.keys(maps).length === 0) {
|
||||
installSourceMapSupport();
|
||||
}
|
||||
maps[filename] = result.map;
|
||||
}
|
||||
|
||||
return result.code;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user