Browse Source

warn on empty exports, dont fail (closes #486)

gh-669
Rich-Harris 9 years ago
parent
commit
ab767b125d
  1. 40
      src/Module.js
  2. 17
      test/function/empty-exports/_config.js
  3. 1
      test/function/empty-exports/main.js

40
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` );
}
}
}

17
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' );
}
};

1
test/function/empty-exports/main.js

@ -0,0 +1 @@
export {};
Loading…
Cancel
Save