move source map sanitization back to translate for build support

This commit is contained in:
guybedford 2016-01-01 20:45:08 +02:00
parent 2f56b0c904
commit 8a688f7d21
2 changed files with 24 additions and 20 deletions

View File

@ -177,6 +177,30 @@
hook('translate', function(translate) {
return function(load) {
/*
* Source map sanitization for load.metadata.sourceMap
* Used to set browser and build-level source maps for
* translated sources in a general way.
*
* This isn't plugin-specific, but can't go anywhere else for now
* As it is post-translate
*/
var sourceMap = load.metadata.sourceMap;
// if an object not a JSON string do sanitizing
if (sourceMap && typeof sourceMap == 'object') {
var originalName = load.name.split('!')[0];
// force set the filename of the original file
sourceMap.file = originalName + '!transpiled';
// force set the sources list if only one source
if (!sourceMap.sources || sourceMap.sources.length == 1)
sourceMap.sources = [originalName];
load.metadata.sourceMap = JSON.stringify(sourceMap);
}
var loader = this;
if (load.metadata.loaderModule && load.metadata.loaderModule.translate && load.metadata.format != 'defined') {
return Promise.resolve(load.metadata.loaderModule.translate.call(loader, load)).then(function(result) {

View File

@ -498,26 +498,6 @@ function createEntry() {
hook('instantiate', function(instantiate) {
return function(load) {
/*
* Source map sanitization for load.metadata.sourceMap
* Used to set browser and build-level source maps for
* translated sources in a general way.
*/
var sourceMap = load.metadata.sourceMap;
// if an object not a JSON string do sanitizing
if (sourceMap && typeof sourceMap == 'object') {
var originalName = load.name.split('!')[0];
// force set the filename of the original file
sourceMap.file = originalName + '!transpiled';
// force set the sources list if only one source
if (!sourceMap.sources || sourceMap.sources.length == 1)
sourceMap.sources = [originalName];
load.metadata.sourceMap = JSON.stringify(sourceMap);
}
if (load.metadata.format == 'detect')
load.metadata.format = undefined;