diff --git a/src/Module.js b/src/Module.js index ae01215..ecb22f8 100644 --- a/src/Module.js +++ b/src/Module.js @@ -6,6 +6,7 @@ import { basename, extname } from './utils/path.js'; import getLocation from './utils/getLocation.js'; import makeLegalIdentifier from './utils/makeLegalIdentifier.js'; import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; +import error from './utils/error.js'; import relativeId from './utils/relativeId.js'; import { SyntheticNamespaceDeclaration } from './Declaration.js'; import extractNames from './ast/utils/extractNames.js'; @@ -205,7 +206,7 @@ export default class Module { const isNamespace = specifier.type === 'ImportNamespaceSpecifier'; const name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name; - this.imports[ localName ] = { source, name, module: null }; + this.imports[ localName ] = { source, specifier, name, module: null }; }); } @@ -359,7 +360,14 @@ export default class Module { const declaration = otherModule.traceExport( importDeclaration.name ); - if ( !declaration ) throw new Error( `'${importDeclaration.name}' is not exported by ${relativeId( otherModule.id )} (imported by ${relativeId( this.id )}). For help fixing this error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module` ); + if ( !declaration ) { + error({ + message: `'${importDeclaration.name}' is not exported by ${relativeId( otherModule.id )} (imported by ${relativeId( this.id )}). For help fixing this error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module`, + file: this.id, + loc: getLocation( this.code, importDeclaration.specifier.start ) + }); + } + return declaration; } @@ -373,10 +381,11 @@ export default class Module { const declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName ); if ( !declaration ) { - const err = new Error( `'${reexportDeclaration.localName}' is not exported by '${reexportDeclaration.module.id}' (imported by '${this.id}')` ); - err.file = this.id; - err.loc = getLocation( this.code, reexportDeclaration.start ); - throw err; + error({ + message: `'${reexportDeclaration.localName}' is not exported by '${reexportDeclaration.module.id}' (imported by '${this.id}')`, + file: this.id, + loc: getLocation( this.code, reexportDeclaration.start ) + }); } return declaration; @@ -390,6 +399,8 @@ export default class Module { return declaration || this.bundle.scope.findDeclaration( name ); } + if ( name === 'default' ) return; + for ( let i = 0; i < this.exportAllModules.length; i += 1 ) { const module = this.exportAllModules[i]; const declaration = module.traceExport( name ); diff --git a/test/function/default-not-reexported/_config.js b/test/function/default-not-reexported/_config.js new file mode 100644 index 0000000..4280924 --- /dev/null +++ b/test/function/default-not-reexported/_config.js @@ -0,0 +1,8 @@ +const assert = require( 'assert' ); + +module.exports = { + description: 'default export is not re-exported with export *', + error ( error ) { + assert.equal( error.message, `'default' is not exported by foo.js (imported by main.js). For help fixing this error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module` ); + } +}; diff --git a/test/function/default-not-reexported/bar.js b/test/function/default-not-reexported/bar.js new file mode 100644 index 0000000..f3f6547 --- /dev/null +++ b/test/function/default-not-reexported/bar.js @@ -0,0 +1,2 @@ +export const named = 42; +export default 'should not be re-exported'; diff --git a/test/function/default-not-reexported/foo.js b/test/function/default-not-reexported/foo.js new file mode 100644 index 0000000..a8e4f7c --- /dev/null +++ b/test/function/default-not-reexported/foo.js @@ -0,0 +1 @@ +export * from './bar.js'; diff --git a/test/function/default-not-reexported/main.js b/test/function/default-not-reexported/main.js new file mode 100644 index 0000000..6aa8dfa --- /dev/null +++ b/test/function/default-not-reexported/main.js @@ -0,0 +1,3 @@ +import def from './foo.js'; + +console.log( def );