Browse Source

sanity check output of load hook

gh-669
Rich Harris 9 years ago
parent
commit
d1c1126b1a
  1. 6
      src/Bundle.js
  2. 15
      test/function/load-returns-string-or-null/_config.js

6
src/Bundle.js

@ -167,6 +167,12 @@ export default class Bundle {
msg += `: ${err.message}`; msg += `: ${err.message}`;
throw new Error( msg ); 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 => transform( source, id, this.transformers ) )
.then( source => { .then( source => {
const { code, originalCode, ast, sourceMapChain } = source; const { code, originalCode, ast, sourceMapChain } = source;

15
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 ) );
}
};
Loading…
Cancel
Save