From 8d7ec179c2ba2672d4d06200166ab64e1821527c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 14 May 2021 09:12:21 -0700 Subject: [PATCH] [Fix] `newline-after-import`: fix crash with `export {}` syntax Fixes #2063. Fixes #2065. --- CHANGELOG.md | 5 +++++ src/rules/newline-after-import.js | 3 ++- tests/src/rules/newline-after-import.js | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 766516416..a21c4f3ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## [Unreleased] +### Fixed +- [`newline-after-import`]: fix crash with `export {}` syntax ([#2063], [#2065], thanks [@ljharb]) + ## [2.23.0] - 2021-05-13 ### Added @@ -1003,6 +1006,8 @@ 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 +[#2065]: https://github.com/benmosher/eslint-plugin-import/issues/2065 +[#2063]: https://github.com/benmosher/eslint-plugin-import/issues/2063 [#1965]: https://github.com/benmosher/eslint-plugin-import/issues/1965 [#1924]: https://github.com/benmosher/eslint-plugin-import/issues/1924 [#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854 diff --git a/src/rules/newline-after-import.js b/src/rules/newline-after-import.js index 935572aa4..f9a817846 100644 --- a/src/rules/newline-after-import.js +++ b/src/rules/newline-after-import.js @@ -48,7 +48,8 @@ function isExportDefaultClass(node) { } function isExportNameClass(node) { - return node.type === 'ExportNamedDeclaration' && node.declaration.type === 'ClassDeclaration'; + + return node.type === 'ExportNamedDeclaration' && node.declaration && node.declaration.type === 'ClassDeclaration'; } module.exports = { diff --git a/tests/src/rules/newline-after-import.js b/tests/src/rules/newline-after-import.js index a01bfead6..867a64857 100644 --- a/tests/src/rules/newline-after-import.js +++ b/tests/src/rules/newline-after-import.js @@ -231,7 +231,28 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { parser: parser, parserOptions: { ecmaVersion: 2015, sourceType: 'module' }, }, + { + code: ` + import stub from './stub'; + + export { + stub + } + `, + parser: parser, + parserOptions: { ecmaVersion: 2015, sourceType: 'module' }, + }, ]), + { + code: ` + import stub from './stub'; + + export { + stub + } + `, + parserOptions: { ecmaVersion: 2015, sourceType: 'module' }, + }, ], invalid: [].concat(