diff --git a/src/Module.js b/src/Module.js index 7764a08..4b2e7d4 100644 --- a/src/Module.js +++ b/src/Module.js @@ -102,37 +102,37 @@ export default class Module { this.declarations.default = new SyntheticDefaultDeclaration( node, statement, identifier || this.basename() ); } - // export { foo, bar, baz } // export var { foo, bar } = ... // export var foo = 42; // export var a = 1, b = 2, c = 3; // export function foo () {} - else if ( node.type === 'ExportNamedDeclaration' ) { + else if ( node.declaration ) { + let declaration = node.declaration; + + if ( declaration.type === 'VariableDeclaration' ) { + declaration.declarations.forEach( decl => { + extractNames( decl.id ).forEach( localName => { + this.exports[ localName ] = { localName }; + }); + }); + } else { + // export function foo () {} + const localName = declaration.id.name; + this.exports[ localName ] = { localName }; + } + } + + // export { foo, bar, baz } + else { if ( node.specifiers.length ) { - // export { foo, bar, baz } node.specifiers.forEach( specifier => { const localName = specifier.local.name; const exportedName = specifier.exported.name; this.exports[ exportedName ] = { localName }; }); - } - - else { - let declaration = node.declaration; - - if ( declaration.type === 'VariableDeclaration' ) { - declaration.declarations.forEach( decl => { - extractNames( decl.id ).forEach( localName => { - this.exports[ localName ] = { localName }; - }); - }); - } - else { - // export function foo () {} - const localName = declaration.id.name; - this.exports[ localName ] = { localName }; - } + } else { + this.bundle.onwarn( `Module ${this.id} has an empty export declaration` ); } } } diff --git a/test/function/empty-exports/_config.js b/test/function/empty-exports/_config.js new file mode 100644 index 0000000..65b2185 --- /dev/null +++ b/test/function/empty-exports/_config.js @@ -0,0 +1,17 @@ +var assert = require( 'assert' ); + +var warned = false; + +module.exports = { + description: 'warns on export {}, but does not fail', + options: { + onwarn: function ( msg ) { + warned = true; + assert.ok( /main\.js has an empty export declaration/.test( msg ) ); + } + }, + exports: function ( exports ) { + assert.equal( Object.keys( exports ).length, 0 ); + assert.ok( warned, 'did not warn' ); + } +}; diff --git a/test/function/empty-exports/main.js b/test/function/empty-exports/main.js new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/function/empty-exports/main.js @@ -0,0 +1 @@ +export {};