diff --git a/src/Bundle.js b/src/Bundle.js index f5fedc8..d91479f 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -167,6 +167,12 @@ export default class Bundle { msg += `: ${err.message}`; throw new Error( msg ); }) + .then( source => { + if ( typeof source === 'string' ) return source; + if ( source && typeof source === 'object' && source.code ) return source; + + throw new Error( `Error loading ${id}: load hook should return a string, a { code, map } object, or nothing/null` ); + }) .then( source => transform( source, id, this.transformers ) ) .then( source => { const { code, originalCode, ast, sourceMapChain } = source; diff --git a/test/function/load-returns-string-or-null/_config.js b/test/function/load-returns-string-or-null/_config.js new file mode 100644 index 0000000..ea80699 --- /dev/null +++ b/test/function/load-returns-string-or-null/_config.js @@ -0,0 +1,15 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'throws error if load returns something wacky', + options: { + plugins: [{ + load: function () { + return 42; + } + }] + }, + error: function ( err ) { + assert.ok( /load hook should return a string, a \{ code, map \} object, or nothing\/null/.test( err.message ) ); + } +};