From 4ce280a0e1527380c25c7ca7d83767326d972442 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 9 Jun 2020 11:49:58 -0700 Subject: [PATCH] [Fix] `no-internal-modules`: avoid a crash on a named export declaration Fixes #1814. --- CHANGELOG.md | 2 ++ src/rules/no-internal-modules.js | 4 +++- tests/src/rules/no-internal-modules.js | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c58beba1a..0d5251dfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/src/rules/no-internal-modules.js b/src/rules/no-internal-modules.js index b5d7496a2..bd13ab07d 100644 --- a/src/rules/no-internal-modules.js +++ b/src/rules/no-internal-modules.js @@ -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)) { diff --git a/tests/src/rules/no-internal-modules.js b/tests/src/rules/no-internal-modules.js index 5058fcb34..da9a4ca1a 100644 --- a/tests/src/rules/no-internal-modules.js +++ b/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() @@ -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: [