@@ -860,13 +860,13 @@ function resolveFS(ctx: TypeResolveContext): FS | undefined {
860
860
}
861
861
return ( ctx . fs = {
862
862
fileExists ( file ) {
863
- if ( file . endsWith ( '.vue.ts' ) ) {
863
+ if ( file . endsWith ( '.vue.ts' ) && ! file . endsWith ( '.d.vue.ts' ) ) {
864
864
file = file . replace ( / \. t s $ / , '' )
865
865
}
866
866
return fs . fileExists ( file )
867
867
} ,
868
868
readFile ( file ) {
869
- if ( file . endsWith ( '.vue.ts' ) ) {
869
+ if ( file . endsWith ( '.vue.ts' ) && ! file . endsWith ( '.d.vue.ts' ) ) {
870
870
file = file . replace ( / \. t s $ / , '' )
871
871
}
872
872
return fs . readFile ( file )
@@ -1059,7 +1059,7 @@ function resolveWithTS(
1059
1059
1060
1060
if ( res . resolvedModule ) {
1061
1061
let filename = res . resolvedModule . resolvedFileName
1062
- if ( filename . endsWith ( '.vue.ts' ) ) {
1062
+ if ( filename . endsWith ( '.vue.ts' ) && ! filename . endsWith ( '.d.vue.ts' ) ) {
1063
1063
filename = filename . replace ( / \. t s $ / , '' )
1064
1064
}
1065
1065
return fs . realpath ? fs . realpath ( filename ) : filename
@@ -1129,7 +1129,7 @@ export function fileToScope(
1129
1129
// fs should be guaranteed to exist here
1130
1130
const fs = resolveFS ( ctx ) !
1131
1131
const source = fs . readFile ( filename ) || ''
1132
- const body = parseFile ( filename , source , ctx . options . babelParserPlugins )
1132
+ const body = parseFile ( filename , source , fs , ctx . options . babelParserPlugins )
1133
1133
const scope = new TypeScope ( filename , source , 0 , recordImports ( body ) )
1134
1134
recordTypes ( ctx , body , scope , asGlobal )
1135
1135
fileToScopeCache . set ( filename , scope )
@@ -1139,6 +1139,7 @@ export function fileToScope(
1139
1139
function parseFile (
1140
1140
filename : string ,
1141
1141
content : string ,
1142
+ fs : FS ,
1142
1143
parserPlugins ?: SFCScriptCompileOptions [ 'babelParserPlugins' ] ,
1143
1144
) : Statement [ ] {
1144
1145
const ext = extname ( filename )
@@ -1151,7 +1152,21 @@ function parseFile(
1151
1152
) ,
1152
1153
sourceType : 'module' ,
1153
1154
} ) . program . body
1154
- } else if ( ext === '.vue' ) {
1155
+ }
1156
+
1157
+ // simulate `allowArbitraryExtensions` on TypeScript >= 5.0
1158
+ const isUnknownTypeSource = ! / \. [ c m ] ? [ t j ] s x ? $ / . test ( filename )
1159
+ const arbitraryTypeSource = `${ filename . slice ( 0 , - ext . length ) } .d${ ext } .ts`
1160
+ const hasArbitraryTypeDeclaration =
1161
+ isUnknownTypeSource && fs . fileExists ( arbitraryTypeSource )
1162
+ if ( hasArbitraryTypeDeclaration ) {
1163
+ return babelParse ( fs . readFile ( arbitraryTypeSource ) ! , {
1164
+ plugins : resolveParserPlugins ( 'ts' , parserPlugins , true ) ,
1165
+ sourceType : 'module' ,
1166
+ } ) . program . body
1167
+ }
1168
+
1169
+ if ( ext === '.vue' ) {
1155
1170
const {
1156
1171
descriptor : { script, scriptSetup } ,
1157
1172
} = parse ( content )
0 commit comments