diff --git a/src/ast/scopes/ModuleScope.js b/src/ast/scopes/ModuleScope.js index f451d20..cdc2c93 100644 --- a/src/ast/scopes/ModuleScope.js +++ b/src/ast/scopes/ModuleScope.js @@ -19,14 +19,15 @@ export default class ModuleScope extends Scope { forOwn( this.module.imports, specifier => { if ( specifier.module.isExternal ) return; - if ( specifier.name === '*' ) { - specifier.module.getExports().forEach( name => { - names.set( name, true ); - }); - } else { + specifier.module.getExports().forEach( name => { + names.set(name); + }); + if ( specifier.name !== '*' ) { const declaration = specifier.module.traceExport( specifier.name ); const name = declaration.getName( true ); - if ( name !== specifier.name ) names.set( declaration.getName( true ) ); + if ( name !== specifier.name ) { + names.set(declaration.getName( true )); + } } }); diff --git a/test/function/namespacing-in-sub-functions/_config.js b/test/function/namespacing-in-sub-functions/_config.js new file mode 100644 index 0000000..025b117 --- /dev/null +++ b/test/function/namespacing-in-sub-functions/_config.js @@ -0,0 +1,8 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'correctly namespaces sub-functions (#910)', + exports: function ( exports ) { + assert.equal( exports, 'foobar' ); + } +}; diff --git a/test/function/namespacing-in-sub-functions/main.js b/test/function/namespacing-in-sub-functions/main.js new file mode 100644 index 0000000..ac9d9da --- /dev/null +++ b/test/function/namespacing-in-sub-functions/main.js @@ -0,0 +1,11 @@ +import { problematicFunc as otherFunc } from './problematicFunc'; +function innerFunc() { + function problematicFunc () { + return otherFunc(); + } + return problematicFunc(); +} + +var res = innerFunc(); + +export default res; \ No newline at end of file diff --git a/test/function/namespacing-in-sub-functions/problematicFunc.js b/test/function/namespacing-in-sub-functions/problematicFunc.js new file mode 100644 index 0000000..1fbecc0 --- /dev/null +++ b/test/function/namespacing-in-sub-functions/problematicFunc.js @@ -0,0 +1,5 @@ +function problematicFunc() { + return 'foobar'; +} + +export { problematicFunc }; \ No newline at end of file