]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): also search for `.tsx` when type import's extension is omitted...
authorliudaodanOo <75828211+liudaodanOo@users.noreply.github.com>
Tue, 9 Apr 2024 08:14:11 +0000 (16:14 +0800)
committerGitHub <noreply@github.com>
Tue, 9 Apr 2024 08:14:11 +0000 (16:14 +0800)
Co-authored-by: liuxiaofei <liuxfb@digiwin.com>
Closes #10635

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
packages/compiler-sfc/src/script/resolveType.ts

index 0c5c95cd17fffdfc59b61955e52465dcd7fac168..f3be58a301c1262a2846ae0de857ef85f6df6057 100644 (file)
@@ -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 }',
index 968c168ddb94edcc5930e312af06313fb64cb05a..f6e291791a849dc169e65921bcf58c8c3d178320 100644 (file)
@@ -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`))
   )
 }