From ed6a339c168a8540b4ca2a0a3937b9379ca96417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Tue, 29 Dec 2015 16:15:04 +0100 Subject: [PATCH 1/3] Add failing test --- .../handles-stringified-sourcemaps/_config.js | 18 ++++++++++++++++++ .../handles-stringified-sourcemaps/main.js | 1 + 2 files changed, 19 insertions(+) create mode 100644 test/function/handles-stringified-sourcemaps/_config.js create mode 100644 test/function/handles-stringified-sourcemaps/main.js diff --git a/test/function/handles-stringified-sourcemaps/_config.js b/test/function/handles-stringified-sourcemaps/_config.js new file mode 100644 index 0000000..a0220e9 --- /dev/null +++ b/test/function/handles-stringified-sourcemaps/_config.js @@ -0,0 +1,18 @@ +module.exports = { + options: { + plugins: [ + { + transform: function ( code ) { + return { + code: code, + map: JSON.stringify({ mappings: '' }) + }; + } + } + ] + }, + + 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; From f05bc8293f09b828eb9703cd6cd70e39a6cb4396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Tue, 29 Dec 2015 16:16:42 +0100 Subject: [PATCH 2/3] Make failing test pass --- src/utils/transform.js | 4 ++++ 1 file changed, 4 insertions(+) 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; From 9ce73156a2b26afa111da2b3ba1d5b5c65d86007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Tue, 29 Dec 2015 16:19:30 +0100 Subject: [PATCH 3/3] Add description and comments --- test/function/handles-stringified-sourcemaps/_config.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/function/handles-stringified-sourcemaps/_config.js b/test/function/handles-stringified-sourcemaps/_config.js index a0220e9..d09a3ce 100644 --- a/test/function/handles-stringified-sourcemaps/_config.js +++ b/test/function/handles-stringified-sourcemaps/_config.js @@ -1,10 +1,13 @@ 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: '' }) }; } @@ -12,6 +15,7 @@ module.exports = { ] }, + // ensure source maps are generated bundleOptions: { sourceMap: true }