|
| 1 | +import { normalize } from 'node:path' |
1 | 2 | import { Identifier } from '@babel/types'
|
2 | 3 | import { SFCScriptCompileOptions, parse } from '../../src'
|
3 | 4 | import { ScriptCompileContext } from '../../src/script/context'
|
@@ -478,6 +479,33 @@ describe('resolveType', () => {
|
478 | 479 | expect(deps && [...deps]).toStrictEqual(Object.keys(files))
|
479 | 480 | })
|
480 | 481 |
|
| 482 | + test.runIf(process.platform === 'win32')('relative ts on Windows', () => { |
| 483 | + const files = { |
| 484 | + 'C:\\Test\\foo.ts': 'export type P = { foo: number }', |
| 485 | + 'C:\\Test\\bar.d.ts': |
| 486 | + 'type X = { bar: string }; export { X as Y };' + |
| 487 | + // verify that we can parse syntax that is only valid in d.ts |
| 488 | + 'export const baz: boolean' |
| 489 | + } |
| 490 | + const { props, deps } = resolve( |
| 491 | + ` |
| 492 | + import { P } from './foo' |
| 493 | + import { Y as PP } from './bar' |
| 494 | + defineProps<P & PP>() |
| 495 | + `, |
| 496 | + files, |
| 497 | + {}, |
| 498 | + 'C:\\Test\\Test.vue' |
| 499 | + ) |
| 500 | + expect(props).toStrictEqual({ |
| 501 | + foo: ['Number'], |
| 502 | + bar: ['String'] |
| 503 | + }) |
| 504 | + expect(deps && [...deps].map(normalize)).toStrictEqual( |
| 505 | + Object.keys(files).map(normalize) |
| 506 | + ) |
| 507 | + }) |
| 508 | + |
481 | 509 | // #8244
|
482 | 510 | test('utility type in external file', () => {
|
483 | 511 | const files = {
|
@@ -898,19 +926,20 @@ describe('resolveType', () => {
|
898 | 926 | function resolve(
|
899 | 927 | code: string,
|
900 | 928 | files: Record<string, string> = {},
|
901 |
| - options?: Partial<SFCScriptCompileOptions> |
| 929 | + options?: Partial<SFCScriptCompileOptions>, |
| 930 | + sourceFileName: string = '/Test.vue' |
902 | 931 | ) {
|
903 | 932 | const { descriptor } = parse(`<script setup lang="ts">\n${code}\n</script>`, {
|
904 |
| - filename: '/Test.vue' |
| 933 | + filename: sourceFileName |
905 | 934 | })
|
906 | 935 | const ctx = new ScriptCompileContext(descriptor, {
|
907 | 936 | id: 'test',
|
908 | 937 | fs: {
|
909 | 938 | fileExists(file) {
|
910 |
| - return !!files[file] |
| 939 | + return !!(files[file] ?? files[normalize(file)]) |
911 | 940 | },
|
912 | 941 | readFile(file) {
|
913 |
| - return files[file] |
| 942 | + return files[file] ?? files[normalize(file)] |
914 | 943 | }
|
915 | 944 | },
|
916 | 945 | ...options
|
|
0 commit comments