]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): malformed filename on windows using path.posix.join() (#9478)
authorBogdan Kolesnyk <b12k@users.noreply.github.com>
Mon, 13 Nov 2023 07:48:25 +0000 (08:48 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Nov 2023 07:48:25 +0000 (15:48 +0800)
Closes: #8671, #9583
Not fixed with: #9446

Related: #9473

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

index fc600f1a51873e296ec63561bf8c56b0ad1298f6..5f421708af012c9808433922632475355e1e5d4c 100644 (file)
@@ -481,25 +481,28 @@ describe('resolveType', () => {
 
     test.runIf(process.platform === 'win32')('relative ts on Windows', () => {
       const files = {
-        'C:\\Test\\foo.ts': 'export type P = { foo: number }',
-        'C:\\Test\\bar.d.ts':
+        'C:\\Test\\FolderA\\foo.ts': 'export type P = { foo: number }',
+        'C:\\Test\\FolderA\\bar.d.ts':
           'type X = { bar: string }; export { X as Y };' +
           // verify that we can parse syntax that is only valid in d.ts
-          'export const baz: boolean'
+          'export const baz: boolean',
+        'C:\\Test\\FolderB\\buz.ts': 'export type Z = { buz: string }'
       }
       const { props, deps } = resolve(
         `
       import { P } from './foo'
       import { Y as PP } from './bar'
-      defineProps<P & PP>()
+      import { Z as PPP } from '../FolderB/buz'
+      defineProps<P & PP & PPP>()
     `,
         files,
         {},
-        'C:\\Test\\Test.vue'
+        'C:\\Test\\FolderA\\Test.vue'
       )
       expect(props).toStrictEqual({
         foo: ['Number'],
-        bar: ['String']
+        bar: ['String'],
+        buz: ['String']
       })
       expect(deps && [...deps].map(normalize)).toStrictEqual(
         Object.keys(files).map(normalize)
index 7f2e96cd8159d7784e4a9350ce2220e666b49e41..898ec38fec264830c064ebfc9bee79c7b1567c1e 100644 (file)
@@ -39,8 +39,9 @@ import { parse as babelParse } from '@babel/parser'
 import { parse } from '../parse'
 import { createCache } from '../cache'
 import type TS from 'typescript'
-import { extname, dirname } from 'path'
+import { extname, dirname, join } from 'path'
 import { minimatch as isMatch } from 'minimatch'
+import * as process from 'process'
 
 /**
  * TypeResolveContext is compatible with ScriptCompileContext
@@ -779,7 +780,12 @@ function importSourceToScope(
 
   let resolved: string | undefined = scope.resolvedImportSources[source]
   if (!resolved) {
-    if (source.startsWith('.')) {
+    if (source.startsWith('..')) {
+      const osSpecificJoinFn = process.platform === 'win32' ? join : joinPaths
+
+      const filename = osSpecificJoinFn(dirname(scope.filename), source)
+      resolved = resolveExt(filename, fs)
+    } else if (source.startsWith('.')) {
       // relative import - fast path
       const filename = joinPaths(dirname(scope.filename), source)
       resolved = resolveExt(filename, fs)