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 > = { } ;
@@ -1918,6 +1886,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1918
1886
processingOtherFiles = undefined ;
1919
1887
}
1920
1888
1889
+ filesWithReferencesProcessed = undefined ;
1890
+
1921
1891
// Release any files we have acquired in the old program but are
1922
1892
// not part of the new program.
1923
1893
if ( oldProgram && host . onReleaseOldSourceFile ) {
@@ -3751,10 +3721,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3751
3721
const originalFileName = fileName ;
3752
3722
if ( filesByName . has ( path ) ) {
3753
3723
const file = filesByName . get ( path ) ;
3754
- addFileIncludeReason ( file || undefined , reason ) ;
3724
+ const addedReason = addFileIncludeReason ( file || undefined , reason , /*checkExisting*/ true ) ;
3755
3725
// try to check if we've already seen this file but with a different casing in path
3756
3726
// NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected
3757
- if ( file && ! ( options . forceConsistentCasingInFileNames === false ) ) {
3727
+ if ( file && addedReason && ! ( options . forceConsistentCasingInFileNames === false ) ) {
3758
3728
const checkedName = file . fileName ;
3759
3729
const isRedirect = toPath ( checkedName ) !== toPath ( fileName ) ;
3760
3730
if ( isRedirect ) {
@@ -3831,7 +3801,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3831
3801
const dupFile = createRedirectedSourceFile ( fileFromPackageId , file ! , fileName , path , toPath ( fileName ) , originalFileName , sourceFileOptions ) ;
3832
3802
redirectTargetsMap . add ( fileFromPackageId . path , fileName ) ;
3833
3803
addFileToFilesByName ( dupFile , path , fileName , redirectedPath ) ;
3834
- addFileIncludeReason ( dupFile , reason ) ;
3804
+ addFileIncludeReason ( dupFile , reason , /*checkExisting*/ false ) ;
3835
3805
sourceFileToPackageName . set ( path , packageIdToPackageName ( packageId ) ) ;
3836
3806
processingOtherFiles ! . push ( dupFile ) ;
3837
3807
return dupFile ;
@@ -3852,7 +3822,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3852
3822
file . originalFileName = originalFileName ;
3853
3823
file . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
3854
3824
file . packageJsonScope = sourceFileOptions . packageJsonScope ;
3855
- addFileIncludeReason ( file , reason ) ;
3825
+ addFileIncludeReason ( file , reason , /*checkExisting*/ false ) ;
3856
3826
3857
3827
if ( host . useCaseSensitiveFileNames ( ) ) {
3858
3828
const pathLowerCase = toFileNameLowerCase ( path ) ;
@@ -3885,17 +3855,17 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3885
3855
else {
3886
3856
processingOtherFiles ! . push ( file ) ;
3887
3857
}
3858
+ ( filesWithReferencesProcessed ??= new Set ( ) ) . add ( file . path ) ;
3888
3859
}
3889
3860
return file ;
3890
3861
}
3891
3862
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
- }
3863
+ function addFileIncludeReason ( file : SourceFile | undefined , reason : FileIncludeReason , checkExisting : boolean ) {
3864
+ if ( file && ( ! checkExisting || ! isReferencedFile ( reason ) || ! filesWithReferencesProcessed ?. has ( reason . file ) ) ) {
3865
+ fileReasons . add ( file . path , reason ) ;
3866
+ return true ;
3898
3867
}
3868
+ return false ;
3899
3869
}
3900
3870
3901
3871
function addFileToFilesByName ( file : SourceFile | undefined , path : Path , fileName : string , redirectedPath : Path | undefined ) {
0 commit comments