Skip to content

Commit 8d7ec17

Browse files
committed
[Fix] newline-after-import: fix crash with export {} syntax
Fixes #2063. Fixes #2065.
1 parent e9e755d commit 8d7ec17

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
66

77
## [Unreleased]
88

9+
### Fixed
10+
- [`newline-after-import`]: fix crash with `export {}` syntax ([#2063], [#2065], thanks [@ljharb])
11+
912
## [2.23.0] - 2021-05-13
1013

1114
### Added
@@ -1003,6 +1006,8 @@ for info on changes for earlier releases.
10031006
[#211]: https://github.com/benmosher/eslint-plugin-import/pull/211
10041007
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164
10051008
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
1009+
[#2065]: https://github.com/benmosher/eslint-plugin-import/issues/2065
1010+
[#2063]: https://github.com/benmosher/eslint-plugin-import/issues/2063
10061011
[#1965]: https://github.com/benmosher/eslint-plugin-import/issues/1965
10071012
[#1924]: https://github.com/benmosher/eslint-plugin-import/issues/1924
10081013
[#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854

src/rules/newline-after-import.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function isExportDefaultClass(node) {
4848
}
4949

5050
function isExportNameClass(node) {
51-
return node.type === 'ExportNamedDeclaration' && node.declaration.type === 'ClassDeclaration';
51+
52+
return node.type === 'ExportNamedDeclaration' && node.declaration && node.declaration.type === 'ClassDeclaration';
5253
}
5354

5455
module.exports = {

tests/src/rules/newline-after-import.js

+21
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,28 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
231231
parser: parser,
232232
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
233233
},
234+
{
235+
code: `
236+
import stub from './stub';
237+
238+
export {
239+
stub
240+
}
241+
`,
242+
parser: parser,
243+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
244+
},
234245
]),
246+
{
247+
code: `
248+
import stub from './stub';
249+
250+
export {
251+
stub
252+
}
253+
`,
254+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
255+
},
235256
],
236257

237258
invalid: [].concat(

0 commit comments

Comments
 (0)