Browse Source

Merge pull request #1046 from rollup/gh-1045

fix missing namespace member warnings
gh-1132
Rich Harris 8 years ago
committed by GitHub
parent
commit
8120b509c9
  1. 14
      src/ast/nodes/MemberExpression.js
  2. 2
      test/function/namespace-missing-export/_config.js

14
src/ast/nodes/MemberExpression.js

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

2
test/function/namespace-missing-export/_config.js

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

Loading…
Cancel
Save