Skip to content

Commit 9c4c2e5

Browse files
authored
fix(compiler-sfc): skip circular tsconfig project reference (#11680)
Co-authored-by: cluezhang <[email protected]> close #11382
1 parent ac9e7e8 commit 9c4c2e5

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Diff for: packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts

+43
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,49 @@ describe('resolveType', () => {
11851185
expect(deps && [...deps]).toStrictEqual(['/user.ts'])
11861186
})
11871187

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+
11881231
test('ts module resolve w/ path aliased vue file', () => {
11891232
const files = {
11901233
'/tsconfig.json': JSON.stringify({

Diff for: packages/compiler-sfc/src/script/resolveType.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ function loadTSConfig(
10701070
configPath: string,
10711071
ts: typeof TS,
10721072
fs: FS,
1073+
visited = new Set<string>(),
10731074
): TS.ParsedCommandLine[] {
10741075
// The only case where `fs` is NOT `ts.sys` is during tests.
10751076
// parse config host requires an extra `readDirectory` method
@@ -1089,14 +1090,15 @@ function loadTSConfig(
10891090
configPath,
10901091
)
10911092
const res = [config]
1093+
visited.add(configPath)
10921094
if (config.projectReferences) {
10931095
for (const ref of config.projectReferences) {
10941096
const refPath = ts.resolveProjectReferencePath(ref)
1095-
if (!fs.fileExists(refPath)) {
1097+
if (visited.has(refPath) || !fs.fileExists(refPath)) {
10961098
continue
10971099
}
10981100
tsConfigRefMap.set(refPath, configPath)
1099-
res.unshift(...loadTSConfig(refPath, ts, fs))
1101+
res.unshift(...loadTSConfig(refPath, ts, fs, visited))
11001102
}
11011103
}
11021104
return res

0 commit comments

Comments
 (0)