Skip to content

Commit

Permalink
fix(compiler-sfc): also search for .tsx when type import's extensio…
Browse files Browse the repository at this point in the history
…n is omitted (#10637)

Co-authored-by: liuxiaofei <liuxfb@digiwin.com>

Closes #10635
  • Loading branch information
shaw996 authored Apr 9, 2024
1 parent c51be5c commit 34106bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,27 @@ describe('resolveType', () => {
expect(deps && [...deps]).toStrictEqual(Object.keys(files))
})

// #10635
test('relative tsx', () => {
const files = {
'/foo.tsx': 'export type P = { foo: number }',
'/bar/index.tsx': 'export type PP = { bar: string }',
}
const { props, deps } = resolve(
`
import { P } from './foo'
import { PP } from './bar'
defineProps<P & PP>()
`,
files,
)
expect(props).toStrictEqual({
foo: ['Number'],
bar: ['String'],
})
expect(deps && [...deps]).toStrictEqual(Object.keys(files))
})

test.runIf(process.platform === 'win32')('relative ts on Windows', () => {
const files = {
'C:\\Test\\FolderA\\foo.ts': 'export type P = { foo: number }',
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,10 @@ function resolveExt(filename: string, fs: FS) {
return (
tryResolve(filename) ||
tryResolve(filename + `.ts`) ||
tryResolve(filename + `.tsx`) ||
tryResolve(filename + `.d.ts`) ||
tryResolve(joinPaths(filename, `index.ts`)) ||
tryResolve(joinPaths(filename, `index.tsx`)) ||
tryResolve(joinPaths(filename, `index.d.ts`))
)
}
Expand Down

0 comments on commit 34106bc

Please sign in to comment.