Skip to content

Commit

Permalink
Merge pull request #1541 from rollup/gh-1488
Browse files Browse the repository at this point in the history
deshadow indirectly-imported namespaces
  • Loading branch information
Rich-Harris committed Aug 12, 2017
2 parents 2e76960 + 0e5f8b6 commit 5dec01d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ast/scopes/ModuleScope.js
Expand Up @@ -20,8 +20,18 @@ export default class ModuleScope extends Scope {
forOwn( this.module.imports, specifier => {
if ( specifier.module.isExternal ) return;

const addDeclaration = declaration => {
if ( declaration.isNamespace ) {
declaration.module.getExports().forEach( name => {
addDeclaration( declaration.module.traceExport(name) );
});
}

names.add( declaration.name );
};

specifier.module.getExports().forEach( name => {
names.add( specifier.module.traceExport(name).name );
addDeclaration( specifier.module.traceExport(name) );
});

if ( specifier.name !== '*' ) {
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/deshadowed-namespaced-import/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: '#1488'
};
2 changes: 2 additions & 0 deletions test/function/samples/deshadowed-namespaced-import/foo.js
@@ -0,0 +1,2 @@
import * as ns from './ns.js';
export { ns };
10 changes: 10 additions & 0 deletions test/function/samples/deshadowed-namespaced-import/main.js
@@ -0,0 +1,10 @@
import { ns } from './foo.js';

assert.equal((() => {
function foo() {
return ns.foo();
}

return foo();
})(), 42);

3 changes: 3 additions & 0 deletions test/function/samples/deshadowed-namespaced-import/ns.js
@@ -0,0 +1,3 @@
export function foo() {
return 42;
}

0 comments on commit 5dec01d

Please sign in to comment.