Skip to content

Commit

Permalink
[Fix] no-duplicates: avoid crash with empty import type {}
Browse files Browse the repository at this point in the history
Fixes #2201
  • Loading branch information
ljharb committed Aug 22, 2021
1 parent 94d6739 commit aa8d566
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- `ExportMap`: Add default export when esModuleInterop is true and anything is exported ([#2184], thanks [@Maxim-Mazurok])
- [`named`], [`namespace`]: properly set reexports on `export * as … from` ([#1998], [#2161], thanks [@ljharb])
- [`no-duplicates`]: correctly handle case of mixed default/named type imports ([#2149], thanks [@GoodForOneFare], [@nwalters512])
- [`no-duplicates`]: avoid crash with empty `import type {}` ([#2201], thanks [@ljharb])

### Changed
- [Docs] `max-dependencies`: 📖 Document `ignoreTypeImports` option ([#2196], thanks [@himynameisdave])
Expand Down Expand Up @@ -1150,6 +1151,7 @@ for info on changes for earlier releases.
[#211]: https://github.com/import-js/eslint-plugin-import/pull/211
[#164]: https://github.com/import-js/eslint-plugin-import/pull/164
[#157]: https://github.com/import-js/eslint-plugin-import/pull/157
[#2201]: https://github.com/import-js/eslint-plugin-import/issues/2201
[#2161]: https://github.com/import-js/eslint-plugin-import/issues/2161
[#2118]: https://github.com/import-js/eslint-plugin-import/issues/2118
[#2067]: https://github.com/import-js/eslint-plugin-import/issues/2067
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-duplicates.js
Expand Up @@ -281,7 +281,7 @@ module.exports = {

function getImportMap(n) {
if (n.importKind === 'type') {
return n.specifiers[0].type === 'ImportDefaultSpecifier' ? defaultTypesImported : namedTypesImported;
return n.specifiers.length > 0 && n.specifiers[0].type === 'ImportDefaultSpecifier' ? defaultTypesImported : namedTypesImported;
}

return hasNamespace(n) ? nsImported : imported;
Expand Down
7 changes: 7 additions & 0 deletions tests/src/rules/no-duplicates.js
Expand Up @@ -446,6 +446,13 @@ context('TypeScript', function() {
code: "import type x from './foo'; import type {y} from './foo'",
...parserConfig,
}),
test({
code: `
import type {} from './module';
import {} from './module2';
`,
...parserConfig,
}),
],
invalid: [
test({
Expand Down

0 comments on commit aa8d566

Please sign in to comment.