Skip to content

Commit

Permalink
[Fix] newline-after-import: fix crash with export {} syntax
Browse files Browse the repository at this point in the history
Fixes #2063. Fixes #2065.
  • Loading branch information
ljharb committed May 14, 2021
1 parent e9e755d commit 8d7ec17
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/rules/newline-after-import.js
Expand Up @@ -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 = {
Expand Down
21 changes: 21 additions & 0 deletions tests/src/rules/newline-after-import.js
Expand Up @@ -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(
Expand Down

0 comments on commit 8d7ec17

Please sign in to comment.