Browse Source

include importing module in error message when load fails

better-aggressive
Rich-Harris 9 years ago
parent
commit
814003cee2
  1. 13
      src/Bundle.js

13
src/Bundle.js

@ -56,7 +56,7 @@ export default class Bundle {
build () { build () {
return Promise.resolve( this.resolveId( this.entry, undefined ) ) return Promise.resolve( this.resolveId( this.entry, undefined ) )
.then( id => this.fetchModule( id ) ) .then( id => this.fetchModule( id, undefined ) )
.then( entryModule => { .then( entryModule => {
this.entryModule = entryModule; this.entryModule = entryModule;
@ -118,12 +118,19 @@ export default class Bundle {
}); });
} }
fetchModule ( id ) { fetchModule ( id, importer ) {
// short-circuit cycles // short-circuit cycles
if ( this.pending[ id ] ) return null; if ( this.pending[ id ] ) return null;
this.pending[ id ] = true; this.pending[ id ] = true;
return Promise.resolve( this.load( id ) ) return Promise.resolve( this.load( id ) )
.catch( err => {
let msg = `Could not load ${id}`;
if ( importer ) msg += ` (imported by ${importer})`;
msg += `: ${err.message}`;
throw new Error( msg );
})
.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;
@ -158,7 +165,7 @@ export default class Bundle {
} }
module.resolvedIds[ source ] = resolvedId; module.resolvedIds[ source ] = resolvedId;
return this.fetchModule( resolvedId ); return this.fetchModule( resolvedId, module.id );
} }
}); });
}); });

Loading…
Cancel
Save