File tree 2 files changed +47
-2
lines changed
2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -1185,6 +1185,49 @@ describe('resolveType', () => {
1185
1185
expect ( deps && [ ...deps ] ) . toStrictEqual ( [ '/user.ts' ] )
1186
1186
} )
1187
1187
1188
+ // #11382
1189
+ test ( 'ts module resolve circular project reference' , ( ) => {
1190
+ const files = {
1191
+ '/tsconfig.json' : JSON . stringify ( {
1192
+ exclude : [ '**/*.ts' , '**/*.vue' ] ,
1193
+ references : [
1194
+ {
1195
+ path : './tsconfig.web.json' ,
1196
+ } ,
1197
+ ] ,
1198
+ } ) ,
1199
+ '/tsconfig.web.json' : JSON . stringify ( {
1200
+ include : [ '**/*.ts' , '**/*.vue' ] ,
1201
+ compilerOptions : {
1202
+ composite : true ,
1203
+ paths : {
1204
+ user : [ './user.ts' ] ,
1205
+ } ,
1206
+ } ,
1207
+ references : [
1208
+ {
1209
+ // circular reference
1210
+ path : './tsconfig.json' ,
1211
+ } ,
1212
+ ] ,
1213
+ } ) ,
1214
+ '/user.ts' : 'export type User = { bar: string }' ,
1215
+ }
1216
+
1217
+ const { props, deps } = resolve (
1218
+ `
1219
+ import { User } from 'user'
1220
+ defineProps<User>()
1221
+ ` ,
1222
+ files ,
1223
+ )
1224
+
1225
+ expect ( props ) . toStrictEqual ( {
1226
+ bar : [ 'String' ] ,
1227
+ } )
1228
+ expect ( deps && [ ...deps ] ) . toStrictEqual ( [ '/user.ts' ] )
1229
+ } )
1230
+
1188
1231
test ( 'ts module resolve w/ path aliased vue file' , ( ) => {
1189
1232
const files = {
1190
1233
'/tsconfig.json' : JSON . stringify ( {
Original file line number Diff line number Diff line change @@ -1070,6 +1070,7 @@ function loadTSConfig(
1070
1070
configPath : string ,
1071
1071
ts : typeof TS ,
1072
1072
fs : FS ,
1073
+ visited = new Set < string > ( ) ,
1073
1074
) : TS . ParsedCommandLine [ ] {
1074
1075
// The only case where `fs` is NOT `ts.sys` is during tests.
1075
1076
// parse config host requires an extra `readDirectory` method
@@ -1089,14 +1090,15 @@ function loadTSConfig(
1089
1090
configPath ,
1090
1091
)
1091
1092
const res = [ config ]
1093
+ visited . add ( configPath )
1092
1094
if ( config . projectReferences ) {
1093
1095
for ( const ref of config . projectReferences ) {
1094
1096
const refPath = ts . resolveProjectReferencePath ( ref )
1095
- if ( ! fs . fileExists ( refPath ) ) {
1097
+ if ( visited . has ( refPath ) || ! fs . fileExists ( refPath ) ) {
1096
1098
continue
1097
1099
}
1098
1100
tsConfigRefMap . set ( refPath , configPath )
1099
- res . unshift ( ...loadTSConfig ( refPath , ts , fs ) )
1101
+ res . unshift ( ...loadTSConfig ( refPath , ts , fs , visited ) )
1100
1102
}
1101
1103
}
1102
1104
return res
You can’t perform that action at this time.
0 commit comments