Skip to content

Commit

Permalink
[fix] namespace: add check for null ExportMap
Browse files Browse the repository at this point in the history
Fixes #1144.
  • Loading branch information
ljqx authored and ljharb committed Nov 18, 2018
1 parent 2d21c4c commit 918567d
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 @@ -187,7 +187,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 918567d

Please sign in to comment.