8000 fix(compiler-sfc): also search for `.tsx` when type import's extension is omitted by shawfix · Pull Request #10637 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

fix(compiler-sfc): also search for .tsx when type import's extension is omitted #10637

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

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix(compiler-sfc): #10637 look up for .tsx before .d.ts and supply re…
…lative test cases
  • Loading branch information
liuxiaofei committed Apr 8, 2024
commit eef8149c028f427dec1ba473c7bc0270764da7c7
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
6 changes: 3 additions & 3 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,11 @@ function resolveExt(filename: string, fs: FS) {
return (
tryResolve(filename) ||
tryResolve(filename + `.ts`) ||
tryResolve(filename + `.d.ts`) ||
tryResolve(filename + `.tsx`) ||
tryResolve(filename + `.d.ts`) ||
tryResolve(joinPaths(filename, `index.ts`)) ||
tryResolve(joinPaths(filename, `index.d.ts`)) ||
tryResolve(joinPaths(filename, `index.tsx`))
tryResolve(joinPaths(filename, `index.tsx`)) ||
tryResolve(joinPaths(filename, `index.d.ts`))
)
}

Expand Down
0