Skip to content

Commit

Permalink
Merge pull request #1046 from rollup/gh-1045
Browse files Browse the repository at this point in the history
fix missing namespace member warnings
  • Loading branch information
Rich-Harris committed Dec 12, 2016
2 parents a492798 + 5412477 commit 8120b50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/ast/nodes/MemberExpression.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import getLocation from '../../utils/getLocation.js';
import relativeId from '../../utils/relativeId.js';
import isReference from '../utils/isReference.js';
import Node from '../Node.js';
import { UNKNOWN } from '../values.js';
Expand Down Expand Up @@ -26,12 +28,16 @@ export default class MemberExpression extends Node {
let declaration = scope.findDeclaration( keypath.root.name );

while ( declaration.isNamespace && keypath.parts.length ) {
const exporterId = declaration.module.id;

const part = keypath.parts[0];
declaration = declaration.module.traceExport( part.name );

if ( !declaration ) {
this.module.bundle.onwarn( `Export '${part.name}' is not defined by '${this.module.id}'` );
break;
const { line, column } = getLocation( this.module.code, this.start );
this.module.bundle.onwarn( `${relativeId( this.module.id )} (${line}:${column}) '${part.name}' is not exported by '${relativeId( exporterId )}'. See https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module` );
this.replacement = 'undefined';
return;
}

keypath.parts.shift();
Expand Down Expand Up @@ -64,6 +70,10 @@ export default class MemberExpression extends Node {
if ( name !== this.name ) code.overwrite( this.start, this.end, name, true );
}

else if ( this.replacement ) {
code.overwrite( this.start, this.end, this.replacement, true );
}

super.render( code, es );
}

Expand Down
2 changes: 1 addition & 1 deletion test/function/namespace-missing-export/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var assert = require( 'assert' );
module.exports = {
options: {
onwarn: function ( msg ) {
assert.ok( /Export 'foo' is not defined by/.test( msg ) );
assert.equal( msg, `main.js (3:21) 'foo' is not exported by 'empty.js'. See https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module` );
}
}
};

0 comments on commit 8120b50

Please sign in to comment.