Skip to content

Commit

Permalink
fix: correctly process aliases which are inside generic types
Browse files Browse the repository at this point in the history
fix #317
  • Loading branch information
qmhc committed Apr 12, 2024
1 parent 1d65015 commit 0d204d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/transform.ts
Expand Up @@ -157,7 +157,7 @@ export function transformCode(options: {
if (!options.staticImport) {
s.update(node.argument.literal.pos, node.argument.literal.end, `'${libName}'`)

return false
return !!node.typeArguments
}

const importSet =
Expand Down
21 changes: 20 additions & 1 deletion tests/transform.spec.ts
Expand Up @@ -68,6 +68,15 @@ describe('transform tests', () => {
transformCode(options('import { Type } from "./test";\nconst test: import("./test").Test;'))
.content
).toEqual("import { Type, Test } from './test';\n\nconst test: Test;")

expect(
transformCode(options("const a: import('foo').A<{ b: import('foo').B<import('foo').C> }>"))
.content
).toEqual("import { A, B, C } from 'foo';\nconst a: A<{ b: B<C> }>")

expect(
transformCode(options("function d(param: import('foo').E): import('foo').F")).content
).toEqual("import { E, F } from 'foo';\nfunction d(param: E): F")
})

it('test: transformCode (process aliases)', () => {
Expand All @@ -83,7 +92,7 @@ describe('transform tests', () => {
filePath,
aliases,
aliasesExclude: [],
staticImport: true,
staticImport: false,
clearPureImport: false
})

Expand Down Expand Up @@ -117,6 +126,16 @@ describe('transform tests', () => {
expect(transformCode(options('import type { TestBase } from "$src/test";')).content).toEqual(
"import { TestBase } from './test';\n"
)

expect(
transformCode(
options("const a: import('~/test').A<{ b: import('~/test').B<import('~/test').C> }>")
).content
).toEqual("const a: import('./test').A<{ b: import('./test').B<import('./test').C> }>")

expect(
transformCode(options("function d(param: import('~/test').E): import('~/test').F")).content
).toEqual("function d(param: import('./test').E): import('./test').F")
})

it('test: transformCode (remove pure imports)', () => {
Expand Down

0 comments on commit 0d204d9

Please sign in to comment.