@@ -1276,27 +1276,50 @@ namespace ts {
1276
1276
}
1277
1277
1278
1278
function canReuseProjectReferences ( ) : boolean {
1279
- return ! forEachProjectReference (
1280
- oldProgram ! . getProjectReferences ( ) ,
1281
- oldProgram ! . getResolvedProjectReferences ( ) ,
1282
- ( oldResolvedRef , index , parent ) => {
1283
- const newRef = ( parent ? parent . commandLine . projectReferences : projectReferences ) ! [ index ] ;
1284
- const newResolvedRef = parseProjectReferenceConfigFile ( newRef ) ;
1285
- if ( oldResolvedRef ) {
1286
- // Resolved project reference has gone missing or changed
1287
- return ! newResolvedRef || newResolvedRef . sourceFile . version !== oldResolvedRef . sourceFile . version ;
1288
- }
1289
- else {
1290
- // A previously-unresolved reference may be resolved now
1291
- return newResolvedRef !== undefined ;
1292
- }
1293
- } ,
1294
- ( oldProjectReferences , parent ) => {
1295
- // If array of references is changed, we cant resue old program
1296
- const newReferences = parent ? getResolvedProjectReferenceByPath ( parent . sourceFile . path ) ! . commandLine . projectReferences : projectReferences ;
1297
- return ! arrayIsEqualTo ( oldProjectReferences , newReferences , projectReferenceIsEqualTo ) ;
1298
- }
1299
- ) ;
1279
+ let seenResolvedRefs : ResolvedProjectReference [ ] | undefined ;
1280
+ return ! hasChangedReferences ( oldProgram ! . getProjectReferences ( ) , oldProgram ! . getResolvedProjectReferences ( ) , /*parent*/ undefined ) ;
1281
+
1282
+ function hasChangedReferences (
1283
+ oldProjectReferences : readonly ProjectReference [ ] | undefined ,
1284
+ oldResolvedProjectReferences : readonly ( ResolvedProjectReference | undefined ) [ ] | undefined ,
1285
+ parent : ResolvedProjectReference | undefined ,
1286
+ ) : boolean | undefined {
1287
+
1288
+ // Visit project references first
1289
+ const result = hasChangedProjectReferences ( oldProjectReferences , parent ) ;
1290
+ if ( result ) return result ; ;
1291
+
1292
+ return forEach ( oldResolvedProjectReferences , ( oldResolvedRef , index ) => {
1293
+ // ignore recursives
1294
+ if ( contains ( seenResolvedRefs , oldResolvedRef ) ) return undefined ;
1295
+
1296
+ const result = hasChangedResolvedProjectReferences ( oldResolvedRef , index , parent ) ;
1297
+ if ( result ) return result ;
1298
+ if ( ! oldResolvedRef ) return undefined ;
1299
+
1300
+ ( seenResolvedRefs || ( seenResolvedRefs = [ ] ) ) . push ( oldResolvedRef ) ;
1301
+ return hasChangedReferences ( oldResolvedRef . commandLine . projectReferences , oldResolvedRef . references , oldResolvedRef ) ;
1302
+ } ) ;
1303
+ }
1304
+ }
1305
+
1306
+ function hasChangedProjectReferences ( oldProjectReferences : readonly ProjectReference [ ] | undefined , parent : ResolvedProjectReference | undefined ) {
1307
+ // If array of references is changed, we cant resue old program
1308
+ const newReferences = parent ? getResolvedProjectReferenceByPath ( parent . sourceFile . path ) ! . commandLine . projectReferences : projectReferences ;
1309
+ return ! arrayIsEqualTo ( oldProjectReferences , newReferences , projectReferenceIsEqualTo ) ;
1310
+ }
1311
+
1312
+ function hasChangedResolvedProjectReferences ( oldResolvedRef : ResolvedProjectReference | undefined , index : number , parent : ResolvedProjectReference | undefined ) {
1313
+ const newRef = ( parent ? parent . commandLine . projectReferences : projectReferences ) ! [ index ] ;
1314
+ const newResolvedRef = parseProjectReferenceConfigFile ( newRef ) ;
1315
+ if ( oldResolvedRef ) {
1316
+ // Resolved project reference has gone missing or changed
1317
+ return ! newResolvedRef || newResolvedRef . sourceFile . version !== oldResolvedRef . sourceFile . version ;
1318
+ }
1319
+ else {
1320
+ // A previously-unresolved reference may be resolved now
1321
+ return newResolvedRef !== undefined ;
1322
+ }
1300
1323
}
1301
1324
1302
1325
function tryReuseStructureFromOldProgram ( ) : StructureIsReused {
0 commit comments