diff --git a/lib/plugins.js b/lib/plugins.js index f57ef6b4..5f87e805 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -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) { diff --git a/lib/register.js b/lib/register.js index 0cf4c94d..695726ad 100644 --- a/lib/register.js +++ b/lib/register.js @@ -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;