diff --git a/src/generators/Generator.js b/src/generators/Generator.js index beca3ec09f..995c39dd23 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -149,6 +149,15 @@ export default class Generator { const { filename } = options; + // special case — the source file doesn't actually get used anywhere. we need + // to add an empty file to populate map.sources and map.sourcesContent + if ( !parts.length ) { + compiled.addSource({ + filename, + content: new MagicString( this.source ).remove( 0, this.source.length ) + }); + } + parts.forEach( str => { const chunk = str.replace( pattern, '' ); if ( chunk ) addString( chunk ); diff --git a/test/sourcemaps/static-no-script/input.html b/test/sourcemaps/static-no-script/input.html new file mode 100644 index 0000000000..1e2d597971 --- /dev/null +++ b/test/sourcemaps/static-no-script/input.html @@ -0,0 +1 @@ +

no moving parts

\ No newline at end of file diff --git a/test/sourcemaps/static-no-script/test.js b/test/sourcemaps/static-no-script/test.js new file mode 100644 index 0000000000..0a989619ac --- /dev/null +++ b/test/sourcemaps/static-no-script/test.js @@ -0,0 +1,9 @@ +const fs = require( 'fs' ); +const path = require( 'path' ); + +export function test ({ assert, map }) { + assert.deepEqual( map.sources, [ 'input.html' ]); + assert.deepEqual( map.sourcesContent, [ + fs.readFileSync( path.join( __dirname, 'input.html' ), 'utf-8' ) + ]); +}