diff --git a/src/Bundle.js b/src/Bundle.js index cf4085a..b79057f 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -1,3 +1,4 @@ +import { decode } from 'sourcemap-codec'; import { Bundle as MagicStringBundle } from 'magic-string'; import first from './utils/first.js'; import { find } from './utils/array.js'; @@ -354,6 +355,9 @@ export default class Bundle { if ( this.hasLoaders || find( this.plugins, plugin => plugin.transform || plugin.transformBundle ) ) { map = magicString.generateMap( {} ); + if ( typeof map.mappings === 'string' ) { + map.mappings = decode( map.mappings ); + } map = collapseSourcemaps( file, map, usedModules, bundleSourcemapChain, this.onwarn ); } else { map = magicString.generateMap({ file, includeContent: true }); diff --git a/src/utils/collapseSourcemaps.js b/src/utils/collapseSourcemaps.js index 173f714..7a504ba 100644 --- a/src/utils/collapseSourcemaps.js +++ b/src/utils/collapseSourcemaps.js @@ -1,4 +1,4 @@ -import { encode, decode } from 'sourcemap-codec'; +import { encode } from 'sourcemap-codec'; import { dirname, relative, resolve } from './path.js'; class Source { @@ -17,7 +17,7 @@ class Link { constructor ( map, sources ) { this.sources = sources; this.names = map.names; - this.mappings = decode( map.mappings ); + this.mappings = map.mappings; } traceMappings () { diff --git a/src/utils/transform.js b/src/utils/transform.js index b8ba263..2f0c167 100644 --- a/src/utils/transform.js +++ b/src/utils/transform.js @@ -1,8 +1,14 @@ +import { decode } from 'sourcemap-codec'; + export default function transform ( source, id, plugins ) { const sourceMapChain = []; const originalSourceMap = typeof source.map === 'string' ? JSON.parse( source.map ) : source.map; + if ( originalSourceMap && typeof originalSourceMap.mappings === 'string' ) { + originalSourceMap.mappings = decode( originalSourceMap.mappings ); + } + const originalCode = source.code; let ast = source.ast; @@ -25,6 +31,10 @@ export default function transform ( source, id, plugins ) { result.map = JSON.parse( result.map ); } + if ( result.map && typeof result.map.mappings === 'string' ) { + result.map.mappings = decode( result.map.mappings ); + } + sourceMapChain.push( result.map || { missing: true, plugin: plugin.name }); // lil' bit hacky but it works ast = result.ast; diff --git a/src/utils/transformBundle.js b/src/utils/transformBundle.js index 400e994..027c7f0 100644 --- a/src/utils/transformBundle.js +++ b/src/utils/transformBundle.js @@ -1,3 +1,5 @@ +import { decode } from 'sourcemap-codec'; + export default function transformBundle ( code, plugins, sourceMapChain ) { return plugins.reduce( ( code, plugin ) => { if ( !plugin.transformBundle ) return code; @@ -22,6 +24,10 @@ export default function transformBundle ( code, plugins, sourceMapChain ) { } const map = typeof result.map === 'string' ? JSON.parse( result.map ) : result.map; + if ( map && typeof map.mappings === 'string' ) { + map.mappings = decode( map.mappings ); + } + sourceMapChain.push( map ); return result.code;