Skip to content

Commit ee00a1c

Browse files
laurens-dgLaurens De Graeve
authored andcommitted
[Fix] guard against empty parent
1 parent 3a5ad34 commit ee00a1c

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1111
- [`consistent-type-specifier-style`]: fix accidental removal of comma in certain cases ([#2754], thanks [@bradzacher])
1212
- [Perf] `ExportMap`: Improve `ExportMap.for` performance on larger codebases ([#2756], thanks [@leipert])
1313
- [`no-extraneous-dependencies`]/TypeScript: do not error when importing inline type from dev dependencies ([#1820], thanks [@andyogo])
14+
- [`newline-after-import`]/TypeScript: do not error when re-exporting a namespaced import ([#2832], thanks [@laurens-dg])
1415
* [`order`]: partial fix for [#2687] (thanks [@ljharb])
1516

1617
### Changed
@@ -1072,6 +1073,7 @@ for info on changes for earlier releases.
10721073

10731074
[`memo-parser`]: ./memo-parser/README.md
10741075

1076+
[#2832]: https://github.com/import-js/eslint-plugin-import/pull/2832
10751077
[#2756]: https://github.com/import-js/eslint-plugin-import/pull/2756
10761078
[#2754]: https://github.com/import-js/eslint-plugin-import/pull/2754
10771079
[#2748]: https://github.com/import-js/eslint-plugin-import/pull/2748
@@ -1746,6 +1748,7 @@ for info on changes for earlier releases.
17461748
[@KostyaZgara]: https://github.com/KostyaZgara
17471749
[@kylemh]: https://github.com/kylemh
17481750
[@laysent]: https://github.com/laysent
1751+
[@laurens-dg]: https://github.com/laurens-dg
17491752
[@le0nik]: https://github.com/le0nik
17501753
[@leipert]: https://github.com/leipert
17511754
[@lemonmade]: https://github.com/lemonmade

src/rules/newline-after-import.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ module.exports = {
149149

150150
function checkImport(node) {
151151
const { parent } = node;
152+
153+
if (!parent || !parent.body) {
154+
return;
155+
}
156+
152157
const nodePosition = parent.body.indexOf(node);
153158
const nextNode = parent.body[nodePosition + 1];
154159
const endLine = node.loc.end.line;

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
2626
code: `
2727
const x = () => require('baz')
2828
, y = () => require('bar')
29-
29+
3030
// some comment here
3131
`,
3232
parserOptions: { ecmaVersion: 6 },
@@ -273,6 +273,16 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
273273
parser,
274274
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
275275
},
276+
{
277+
code: `
278+
import { ns } from 'namespace';
279+
import Bar = ns.baz.foo.Bar;
280+
281+
export import Foo = ns.baz.bar.Foo;
282+
`,
283+
parser,
284+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
285+
},
276286
)),
277287
{
278288
code: `
@@ -299,7 +309,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
299309
{
300310
code: `
301311
import path from 'path';import foo from 'foo';
302-
312+
303313
/**
304314
* some multiline comment here
305315
* another line of comment
@@ -313,7 +323,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
313323
code: `
314324
import path from 'path';
315325
import foo from 'foo';
316-
326+
317327
// Some random single line comment
318328
var bar = 42;
319329
`,

0 commit comments

Comments
 (0)