diff --git a/src/utils/transform.js b/src/utils/transform.js index 761a217..5ddde28 100644 --- a/src/utils/transform.js +++ b/src/utils/transform.js @@ -25,6 +25,10 @@ export default function transform ( source, id, transformers ) { map: null }; } + // `result.map` can only be a string if `result` isn't + else if ( typeof result.map === 'string' ) { + result.map = JSON.parse( result.map ); + } sourceMapChain.push( result.map ); ast = result.ast; diff --git a/test/function/handles-stringified-sourcemaps/_config.js b/test/function/handles-stringified-sourcemaps/_config.js new file mode 100644 index 0000000..d09a3ce --- /dev/null +++ b/test/function/handles-stringified-sourcemaps/_config.js @@ -0,0 +1,22 @@ +module.exports = { + description: 'handles transforms that return stringified source maps (#377)', + + options: { + plugins: [ + { + transform: function ( code ) { + return { + code: code, + // just stringify an otherwise acceptable source map + map: JSON.stringify({ mappings: '' }) + }; + } + } + ] + }, + + // ensure source maps are generated + bundleOptions: { + sourceMap: true + } +}; diff --git a/test/function/handles-stringified-sourcemaps/main.js b/test/function/handles-stringified-sourcemaps/main.js new file mode 100644 index 0000000..7a4e8a7 --- /dev/null +++ b/test/function/handles-stringified-sourcemaps/main.js @@ -0,0 +1 @@ +export default 42;