Browse Source

Merge pull request #926 from nolanlawson/namespacing-functions

Correctly deshadow re-assigned module functions
gh-953
Rich Harris 8 years ago
committed by GitHub
parent
commit
37a8b39fde
  1. 13
      src/ast/scopes/ModuleScope.js
  2. 8
      test/function/namespacing-in-sub-functions/_config.js
  3. 11
      test/function/namespacing-in-sub-functions/main.js
  4. 5
      test/function/namespacing-in-sub-functions/problematicFunc.js

13
src/ast/scopes/ModuleScope.js

@ -19,14 +19,15 @@ export default class ModuleScope extends Scope {
forOwn( this.module.imports, specifier => { forOwn( this.module.imports, specifier => {
if ( specifier.module.isExternal ) return; if ( specifier.module.isExternal ) return;
if ( specifier.name === '*' ) { specifier.module.getExports().forEach( name => {
specifier.module.getExports().forEach( name => { names.set(name);
names.set( name, true ); });
}); if ( specifier.name !== '*' ) {
} else {
const declaration = specifier.module.traceExport( specifier.name ); const declaration = specifier.module.traceExport( specifier.name );
const name = declaration.getName( true ); const name = declaration.getName( true );
if ( name !== specifier.name ) names.set( declaration.getName( true ) ); if ( name !== specifier.name ) {
names.set(declaration.getName( true ));
}
} }
}); });

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

11
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;

5
test/function/namespacing-in-sub-functions/problematicFunc.js

@ -0,0 +1,5 @@
function problematicFunc() {
return 'foobar';
}
export { problematicFunc };
Loading…
Cancel
Save