Skip to content

Commit 42497fd

Browse files
committed
populate map.sources and map.sourcesContent even if none of the original code is used
1 parent c1ba763 commit 42497fd

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/generators/Generator.js

+9
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ export default class Generator {
149149

150150
const { filename } = options;
151151

152+
// special case — the source file doesn't actually get used anywhere. we need
153+
// to add an empty file to populate map.sources and map.sourcesContent
154+
if ( !parts.length ) {
155+
compiled.addSource({
156+
filename,
157+
content: new MagicString( this.source ).remove( 0, this.source.length )
158+
});
159+
}
160+
152161
parts.forEach( str => {
153162
const chunk = str.replace( pattern, '' );
154163
if ( chunk ) addString( chunk );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>no moving parts</p>
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fs = require( 'fs' );
2+
const path = require( 'path' );
3+
4+
export function test ({ assert, map }) {
5+
assert.deepEqual( map.sources, [ 'input.html' ]);
6+
assert.deepEqual( map.sourcesContent, [
7+
fs.readFileSync( path.join( __dirname, 'input.html' ), 'utf-8' )
8+
]);
9+
}

0 commit comments

Comments
 (0)