6
6
append ,
7
7
arrayIsEqualTo ,
8
8
AsExpression ,
9
- AutomaticTypeDirectiveFile ,
10
9
BuilderProgram ,
11
10
CancellationToken ,
12
11
canHaveDecorators ,
@@ -215,7 +214,6 @@ import {
215
214
JsonSourceFile ,
216
215
JsxEmit ,
217
216
length ,
218
- LibFile ,
219
217
libMap ,
220
218
LibResolution ,
221
219
libs ,
@@ -249,7 +247,6 @@ import {
249
247
OperationCanceledException ,
250
248
optionsHaveChanges ,
251
249
PackageId ,
252
- packageIdIsEqual ,
253
250
packageIdToPackageName ,
254
251
packageIdToString ,
255
252
PackageJsonInfoCache ,
@@ -288,7 +285,6 @@ import {
288
285
resolveTypeReferenceDirective ,
289
286
returnFalse ,
290
287
returnUndefined ,
291
- RootFile ,
292
288
SatisfiesExpression ,
293
289
ScriptKind ,
294
290
ScriptTarget ,
@@ -1210,35 +1206,6 @@ interface DiagnosticCache<T extends Diagnostic> {
1210
1206
allDiagnostics ?: readonly T [ ] ;
1211
1207
}
1212
1208
1213
- function fileIncludeReasonIsEqual ( a : FileIncludeReason , b : FileIncludeReason ) : boolean {
1214
- if ( a === b ) return true ;
1215
- if ( a . kind !== b . kind ) return false ;
1216
-
1217
- switch ( a . kind ) {
1218
- case FileIncludeKind . RootFile :
1219
- Debug . type < RootFile > ( b ) ;
1220
- return a . index === b . index ;
1221
- case FileIncludeKind . LibFile :
1222
- Debug . type < LibFile > ( b ) ;
1223
- return a . index === b . index ;
1224
- case FileIncludeKind . SourceFromProjectReference :
1225
- case FileIncludeKind . OutputFromProjectReference :
1226
- Debug . type < ProjectReferenceFile > ( b ) ;
1227
- return a . index === b . index ;
1228
- case FileIncludeKind . Import :
1229
- case FileIncludeKind . ReferenceFile :
1230
- case FileIncludeKind . TypeReferenceDirective :
1231
- case FileIncludeKind . LibReferenceDirective :
1232
- Debug . type < ReferencedFile > ( b ) ;
1233
- return a . file === b . file && a . index === b . index ;
1234
- case FileIncludeKind . AutomaticTypeDirectiveFile :
1235
- Debug . type < AutomaticTypeDirectiveFile > ( b ) ;
1236
- return a . typeReference === b . typeReference && packageIdIsEqual ( a . packageId , b . packageId ) ;
1237
- default :
1238
- return Debug . assertNever ( a ) ;
1239
- }
1240
- }
1241
-
1242
1209
/** @internal */
1243
1210
export function isReferencedFile ( reason : FileIncludeReason | undefined ) : reason is ReferencedFile {
1244
1211
switch ( reason ?. kind ) {
@@ -1617,6 +1584,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1617
1584
let classifiableNames : Set < __String > ;
1618
1585
const ambientModuleNameToUnmodifiedFileName = new Map < string , string > ( ) ;
1619
1586
let fileReasons = createMultiMap < Path , FileIncludeReason > ( ) ;
1587
+ let filesWithReferencesProcessed : Set < Path > | undefined ;
1620
1588
let fileReasonsToChain : Map < Path , FileReasonToChainCache > | undefined ;
1621
1589
let reasonToRelatedInfo : Map < FileIncludeReason , DiagnosticWithLocation | false > | undefined ;
1622
1590
const cachedBindAndCheckDiagnosticsForFile : DiagnosticCache < Diagnostic > = { } ;
@@ -1916,6 +1884,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1916
1884
files = stableSort ( processingDefaultLibFiles , compareDefaultLibFiles ) . concat ( processingOtherFiles ) ;
1917
1885
processingDefaultLibFiles = undefined ;
1918
1886
processingOtherFiles = undefined ;
1887
+ filesWithReferencesProcessed = undefined ;
1919
1888
}
1920
1889
1921
1890
// Release any files we have acquired in the old program but are
@@ -3751,10 +3720,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3751
3720
const originalFileName = fileName ;
3752
3721
if ( filesByName . has ( path ) ) {
3753
3722
const file = filesByName . get ( path ) ;
3754
- addFileIncludeReason ( file || undefined , reason ) ;
3723
+ const addedReason = addFileIncludeReason ( file || undefined , reason , /*checkExisting*/ true ) ;
3755
3724
// try to check if we've already seen this file but with a different casing in path
3756
3725
// NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected
3757
- if ( file && ! ( options . forceConsistentCasingInFileNames === false ) ) {
3726
+ if ( file && addedReason && ! ( options . forceConsistentCasingInFileNames === false ) ) {
3758
3727
const checkedName = file . fileName ;
3759
3728
const isRedirect = toPath ( checkedName ) !== toPath ( fileName ) ;
3760
3729
if ( isRedirect ) {
@@ -3831,7 +3800,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3831
3800
const dupFile = createRedirectedSourceFile ( fileFromPackageId , file ! , fileName , path , toPath ( fileName ) , originalFileName , sourceFileOptions ) ;
3832
3801
redirectTargetsMap . add ( fileFromPackageId . path , fileName ) ;
3833
3802
addFileToFilesByName ( dupFile , path , fileName , redirectedPath ) ;
3834
- addFileIncludeReason ( dupFile , reason ) ;
3803
+ addFileIncludeReason ( dupFile , reason , /*checkExisting*/ false ) ;
3835
3804
sourceFileToPackageName . set ( path , packageIdToPackageName ( packageId ) ) ;
3836
3805
processingOtherFiles ! . push ( dupFile ) ;
3837
3806
return dupFile ;
@@ -3852,7 +3821,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3852
3821
file . originalFileName = originalFileName ;
3853
3822
file . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
3854
3823
file . packageJsonScope = sourceFileOptions . packageJsonScope ;
3855
- addFileIncludeReason ( file , reason ) ;
3824
+ addFileIncludeReason ( file , reason , /*checkExisting*/ false ) ;
3856
3825
3857
3826
if ( host . useCaseSensitiveFileNames ( ) ) {
3858
3827
const pathLowerCase = toFileNameLowerCase ( path ) ;
@@ -3885,17 +3854,17 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3885
3854
else {
3886
3855
processingOtherFiles ! . push ( file ) ;
3887
3856
}
3857
+ ( filesWithReferencesProcessed ??= new Set ( ) ) . add ( file . path ) ;
3888
3858
}
3889
3859
return file ;
3890
3860
}
3891
3861
3892
- function addFileIncludeReason ( file : SourceFile | undefined , reason : FileIncludeReason ) {
3893
- if ( file ) {
3894
- const existing = fileReasons . get ( file . path ) ;
3895
- if ( ! some ( existing , r => fileIncludeReasonIsEqual ( r , reason ) ) ) {
3896
- fileReasons . add ( file . path , reason ) ;
3897
- }
3862
+ function addFileIncludeReason ( file : SourceFile | undefined , reason : FileIncludeReason , checkExisting : boolean ) {
3863
+ if ( file && ( ! checkExisting || ! isReferencedFile ( reason ) || ! filesWithReferencesProcessed ?. has ( reason . file ) ) ) {
3864
+ fileReasons . add ( file . path , reason ) ;
3865
+ return true ;
3898
3866
}
3867
+ return false ;
3899
3868
}
3900
3869
3901
3870
function addFileToFilesByName ( file : SourceFile | undefined , path : Path , fileName : string , redirectedPath : Path | undefined ) {
0 commit comments