Browse Source

warn on missing unused imports in deshadowing phase, rather than throwing - fixes #928

legacy-quote-reserved-properties
Rich-Harris 8 years ago
parent
commit
e152bb95c5
  1. 5
      src/ast/scopes/ModuleScope.js
  2. 12
      test/function/warn-on-unused-missing-imports/_config.js
  3. 1
      test/function/warn-on-unused-missing-imports/foo.js
  4. 3
      test/function/warn-on-unused-missing-imports/main.js

5
src/ast/scopes/ModuleScope.js

@ -22,8 +22,13 @@ export default class ModuleScope extends Scope {
specifier.module.getExports().forEach( name => {
names.set(name);
});
if ( specifier.name !== '*' ) {
const declaration = specifier.module.traceExport( specifier.name );
if ( !declaration ) {
this.module.bundle.onwarn( `Non-existent export '${specifier.name}' is imported from ${specifier.module.id} by ${this.module.id}` );
return;
}
const name = declaration.getName( true );
if ( name !== specifier.name ) {
names.set( declaration.getName( true ) );

12
test/function/warn-on-unused-missing-imports/_config.js

@ -0,0 +1,12 @@
const path = require( 'path' );
const assert = require( 'assert' );
module.exports = {
solo: true,
description: 'warns on missing (but unused) imports',
warnings: warnings => {
assert.deepEqual( warnings, [
`Non-existent export 'b' is imported from ${path.resolve(__dirname, 'foo.js')} by ${path.resolve(__dirname, 'main.js')}`
]);
}
};

1
test/function/warn-on-unused-missing-imports/foo.js

@ -0,0 +1 @@
export const a = 42;

3
test/function/warn-on-unused-missing-imports/main.js

@ -0,0 +1,3 @@
import { a, b } from './foo.js';
assert.equal( a, 42 );
Loading…
Cancel
Save