Skip to content

Commit aa8d566

Browse files
committedAug 22, 2021
[Fix] no-duplicates: avoid crash with empty import type {}
Fixes #2201
1 parent 94d6739 commit aa8d566

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1212
- `ExportMap`: Add default export when esModuleInterop is true and anything is exported ([#2184], thanks [@Maxim-Mazurok])
1313
- [`named`], [`namespace`]: properly set reexports on `export * as … from` ([#1998], [#2161], thanks [@ljharb])
1414
- [`no-duplicates`]: correctly handle case of mixed default/named type imports ([#2149], thanks [@GoodForOneFare], [@nwalters512])
15+
- [`no-duplicates`]: avoid crash with empty `import type {}` ([#2201], thanks [@ljharb])
1516

1617
### Changed
1718
- [Docs] `max-dependencies`: 📖 Document `ignoreTypeImports` option ([#2196], thanks [@himynameisdave])
@@ -1150,6 +1151,7 @@ for info on changes for earlier releases.
11501151
[#211]: https://github.com/import-js/eslint-plugin-import/pull/211
11511152
[#164]: https://github.com/import-js/eslint-plugin-import/pull/164
11521153
[#157]: https://github.com/import-js/eslint-plugin-import/pull/157
1154+
[#2201]: https://github.com/import-js/eslint-plugin-import/issues/2201
11531155
[#2161]: https://github.com/import-js/eslint-plugin-import/issues/2161
11541156
[#2118]: https://github.com/import-js/eslint-plugin-import/issues/2118
11551157
[#2067]: https://github.com/import-js/eslint-plugin-import/issues/2067

‎src/rules/no-duplicates.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ module.exports = {
281281

282282
function getImportMap(n) {
283283
if (n.importKind === 'type') {
284-
return n.specifiers[0].type === 'ImportDefaultSpecifier' ? defaultTypesImported : namedTypesImported;
284+
return n.specifiers.length > 0 && n.specifiers[0].type === 'ImportDefaultSpecifier' ? defaultTypesImported : namedTypesImported;
285285
}
286286

287287
return hasNamespace(n) ? nsImported : imported;

‎tests/src/rules/no-duplicates.js

+7
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ context('TypeScript', function() {
446446
code: "import type x from './foo'; import type {y} from './foo'",
447447
...parserConfig,
448448
}),
449+
test({
450+
code: `
451+
import type {} from './module';
452+
import {} from './module2';
453+
`,
454+
...parserConfig,
455+
}),
449456
],
450457
invalid: [
451458
test({

0 commit comments

Comments
 (0)
Please sign in to comment.