From f85ffe8929208168a4b938c1d8a85e5d8ce493d1 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 12 Aug 2017 09:26:02 -0400 Subject: [PATCH] ignore external namespace imports when deshadowing - fixes #1547 --- src/ast/scopes/ModuleScope.js | 2 +- .../_config.js | 12 ++++++++++++ .../foo.js | 2 ++ .../main.js | 10 ++++++++++ .../ns.js | 3 +++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/deshadowed-namespaced-external-import-ignored/_config.js create mode 100644 test/function/samples/deshadowed-namespaced-external-import-ignored/foo.js create mode 100644 test/function/samples/deshadowed-namespaced-external-import-ignored/main.js create mode 100644 test/function/samples/deshadowed-namespaced-external-import-ignored/ns.js diff --git a/src/ast/scopes/ModuleScope.js b/src/ast/scopes/ModuleScope.js index ec9b1c157b8..5a9541e55c5 100644 --- a/src/ast/scopes/ModuleScope.js +++ b/src/ast/scopes/ModuleScope.js @@ -21,7 +21,7 @@ export default class ModuleScope extends Scope { if ( specifier.module.isExternal ) return; const addDeclaration = declaration => { - if ( declaration.isNamespace ) { + if ( declaration.isNamespace && !declaration.isExternal ) { declaration.module.getExports().forEach( name => { addDeclaration( declaration.module.traceExport(name) ); }); diff --git a/test/function/samples/deshadowed-namespaced-external-import-ignored/_config.js b/test/function/samples/deshadowed-namespaced-external-import-ignored/_config.js new file mode 100644 index 00000000000..850c0c8305f --- /dev/null +++ b/test/function/samples/deshadowed-namespaced-external-import-ignored/_config.js @@ -0,0 +1,12 @@ +module.exports = { + description: '#1547', + options: { + external: ['external'] + }, + context: { + require: id => { + if (id === 'external') return { foo: () => 42 }; + throw new Error('huh?'); + } + } +}; \ No newline at end of file diff --git a/test/function/samples/deshadowed-namespaced-external-import-ignored/foo.js b/test/function/samples/deshadowed-namespaced-external-import-ignored/foo.js new file mode 100644 index 00000000000..8f119b720ac --- /dev/null +++ b/test/function/samples/deshadowed-namespaced-external-import-ignored/foo.js @@ -0,0 +1,2 @@ +import * as ns from 'external'; +export { ns }; \ No newline at end of file diff --git a/test/function/samples/deshadowed-namespaced-external-import-ignored/main.js b/test/function/samples/deshadowed-namespaced-external-import-ignored/main.js new file mode 100644 index 00000000000..3178bf05289 --- /dev/null +++ b/test/function/samples/deshadowed-namespaced-external-import-ignored/main.js @@ -0,0 +1,10 @@ +import { ns } from './foo.js'; + +assert.equal((() => { + function foo() { + return ns.foo(); + } + + return foo(); +})(), 42); + diff --git a/test/function/samples/deshadowed-namespaced-external-import-ignored/ns.js b/test/function/samples/deshadowed-namespaced-external-import-ignored/ns.js new file mode 100644 index 00000000000..19ae356d4ec --- /dev/null +++ b/test/function/samples/deshadowed-namespaced-external-import-ignored/ns.js @@ -0,0 +1,3 @@ +export function foo() { + return 42; +} \ No newline at end of file