Skip to content

Commit

Permalink
[Namespace] add check for null ExportMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ljqx committed Nov 18, 2018
1 parent 798eed7 commit 20b9e98
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/files/re-export-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { a as foo } from './common'
5 changes: 5 additions & 0 deletions tests/src/rules/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Names.a/>',
Expand Down

0 comments on commit 20b9e98

Please sign in to comment.