From 20b9e98532b043056db07ced4fd6117beef9c179 Mon Sep 17 00:00:00 2001 From: Zhibin Liu Date: Sun, 18 Nov 2018 21:36:13 +0800 Subject: [PATCH] [Namespace] add check for null ExportMap --- src/rules/namespace.js | 6 +++++- tests/files/re-export-common.js | 1 + tests/src/rules/namespace.js | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/files/re-export-common.js diff --git a/src/rules/namespace.js b/src/rules/namespace.js index bbba2ce2ef..4cf92b6153 100644 --- a/src/rules/namespace.js +++ b/src/rules/namespace.js @@ -186,7 +186,11 @@ module.exports = { } path.push(property.key.name) - testKey(property.value, namespace.get(property.key.name).namespace, path) + const dependencyExportMap = namespace.get(property.key.name) + // could be null when ignored or ambiguous + if (dependencyExportMap !== null) { + testKey(property.value, dependencyExportMap.namespace, path) + } path.pop() } } diff --git a/tests/files/re-export-common.js b/tests/files/re-export-common.js new file mode 100644 index 0000000000..3c47cd8c15 --- /dev/null +++ b/tests/files/re-export-common.js @@ -0,0 +1 @@ +export { a as foo } from './common' diff --git a/tests/src/rules/namespace.js b/tests/src/rules/namespace.js index 7fa8cfcdb9..e642a2b484 100644 --- a/tests/src/rules/namespace.js +++ b/tests/src/rules/namespace.js @@ -104,6 +104,11 @@ const valid = [ parser: 'babel-eslint', }), + // #1144: should handle re-export CommonJS as namespace + test({ + code: `import * as ns from './re-export-common'; const {foo} = ns;`, + }), + // JSX test({ code: 'import * as Names from "./named-exports"; const Foo = ',