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:
Amin Marashi
2017-11-10 04:20:26 +08:00
committed by Logan Smyth
parent aefbb1380e
commit 83cd3fb2c9
3 changed files with 62 additions and 17 deletions

View File

@@ -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;
}