Skip to content
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

fix(defineprops-type): fix importing external ts types from defineProps #10762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import type {
TSTypeReference,
TemplateLiteral,
} from '@babel/types'
import {
DEFAULT_FILENAME,
} from '../parse'
import {
UNKNOWN_TYPE,
createGetCanonicalFileName,
Expand All @@ -46,7 +49,7 @@ import * as process from 'process'
export type SimpleTypeResolveOptions = Partial<
Pick<
SFCScriptCompileOptions,
'globalTypeFiles' | 'fs' | 'babelParserPlugins' | 'isProd'
'globalTypeFiles' | 'fs' | 'babelParserPlugins' | 'isProd' | 'id'
>
>

Expand Down Expand Up @@ -898,14 +901,19 @@ function importSourceToScope(

let resolved: string | undefined = scope.resolvedImportSources[source]
if (!resolved) {
let fullName = scope.filename;
const id = ctx.options.id;
if (id && fullName === DEFAULT_FILENAME){
fullName = id ;
}
if (source.startsWith('..')) {
const osSpecificJoinFn = process.platform === 'win32' ? join : joinPaths

const filename = osSpecificJoinFn(dirname(scope.filename), source)
const filename = osSpecificJoinFn(dirname(fullName), source)
resolved = resolveExt(filename, fs)
} else if (source.startsWith('.')) {
// relative import - fast path
const filename = joinPaths(dirname(scope.filename), source)
const filename = joinPaths(dirname(fullName), source)
resolved = resolveExt(filename, fs)
} else {
// module or aliased import - use full TS resolution, only supported in Node
Expand All @@ -928,7 +936,7 @@ function importSourceToScope(
)
}
}
resolved = resolveWithTS(scope.filename, source, ts, fs)
resolved = resolveWithTS(fullName, source, ts, fs)
}
if (resolved) {
resolved = scope.resolvedImportSources[source] = normalizePath(resolved)
Expand Down