Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #124 - type import specifier dupe #125

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/utils/__tests__/explode-type-and-value-specifiers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ test('it should return named type imports unchanged', () => {
);
});

test('it should return inline named type imports unchanged', () => {
const code = `import { type NamedType1, type NamedType2 } from './source';`;
const importNodes = getImportNodes(code, { plugins: ['typescript'] });
const explodedNodes = explodeTypeAndValueSpecifiers(importNodes);
const formatted = getCodeFromAst({
nodesToOutput: explodedNodes,
originalCode: code,
directives: [],
});
expect(formatted).toEqual(
`import { type NamedType1, type NamedType2 } from './source';`,
);
});

test('it should separate named type and value imports', () => {
const code = `import { named, type NamedType } from './source';`;
const importNodes = getImportNodes(code, { plugins: ['typescript'] });
Expand Down
2 changes: 1 addition & 1 deletion src/utils/explode-type-and-value-specifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const explodeTypeAndValueSpecifiers: ExplodeTypeAndValueSpecifiers = (
);

// If we have a mix of type and value imports, we need to 'splode them into two import declarations
if (typeImports.length) {
if (typeImports.length && typeImports.length < node.specifiers.length) {
const valueImports = node.specifiers.filter(
(i) =>
!(i.type === 'ImportSpecifier' && i.importKind === 'type'),
Expand Down