Skip to content

Commit

Permalink
[Fix] no-internal-modules: avoid a crash on a named export declaration
Browse files Browse the repository at this point in the history
Fixes #1814.
  • Loading branch information
ljharb committed Jun 9, 2020
1 parent 903e8fb commit 4ce280a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Fixed
- [`order`]: avoid a crash on TypeScript’s `export import` syntax ([#1808], thanks [@ljharb])
- [`newline-after-import`]: consider TypeScript `import =` syntax' ([#1811], thanks [@ljharb])
- [`no-internal-modules`]: avoid a crash on a named export declaration ([#1814], thanks [@ljharb])

## [2.21.1] - 2020-06-07
### Fixed
Expand Down Expand Up @@ -901,6 +902,7 @@ for info on changes for earlier releases.
[#211]: https://github.com/benmosher/eslint-plugin-import/pull/211
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
[#1814]: https://github.com/benmosher/eslint-plugin-import/issues/1814
[#1811]: https://github.com/benmosher/eslint-plugin-import/issues/1811
[#1808]: https://github.com/benmosher/eslint-plugin-import/issues/1808
[#1805]: https://github.com/benmosher/eslint-plugin-import/issues/1805
Expand Down
4 changes: 3 additions & 1 deletion src/rules/no-internal-modules.js
Expand Up @@ -95,7 +95,9 @@ module.exports = {
checkImportForReaching(node.source.value, node.source)
},
ExportNamedDeclaration(node) {
checkImportForReaching(node.source.value, node.source)
if (node.source) {
checkImportForReaching(node.source.value, node.source)
}
},
CallExpression(node) {
if (isStaticRequire(node)) {
Expand Down
24 changes: 23 additions & 1 deletion tests/src/rules/no-internal-modules.js
@@ -1,7 +1,8 @@
import { RuleTester } from 'eslint'
import flatMap from 'array.prototype.flatmap'
import rule from 'rules/no-internal-modules'

import { test, testFilePath } from '../utils'
import { test, testFilePath, getTSParsers } from '../utils'

const ruleTester = new RuleTester()

Expand Down Expand Up @@ -92,6 +93,27 @@ ruleTester.run('no-internal-modules', rule, {
allow: [ '**/index{.js,}' ],
} ],
}),
test({
code: `
export class AuthHelper {
static checkAuth(auth) {
}
}
`,
}),
...flatMap(getTSParsers(), (parser) => [
test({
code: `
export class AuthHelper {
public static checkAuth(auth?: string): boolean {
}
}
`,
parser: parser,
}),
]),
],

invalid: [
Expand Down

0 comments on commit 4ce280a

Please sign in to comment.