@@ -28,7 +28,7 @@ namespace ts {
28
28
/**
29
29
* The map has key by source file's path that has been changed
30
30
*/
31
- changedFilesSet ?: ReadonlyMap < string , true > ;
31
+ changedFilesSet ?: ReadonlySet < string > ;
32
32
/**
33
33
* Set of affected files being iterated
34
34
*/
@@ -49,7 +49,7 @@ namespace ts {
49
49
/**
50
50
* True if the semantic diagnostics were copied from the old state
51
51
*/
52
- semanticDiagnosticsFromOldState ?: Map < string , true > ;
52
+ semanticDiagnosticsFromOldState ?: Set < string > ;
53
53
/**
54
54
* program corresponding to this state
55
55
*/
@@ -93,7 +93,7 @@ namespace ts {
93
93
/**
94
94
* The map has key by source file's path that has been changed
95
95
*/
96
- changedFilesSet : Map < string , true > ;
96
+ changedFilesSet : Set < string > ;
97
97
/**
98
98
* Set of affected files being iterated
99
99
*/
@@ -118,15 +118,15 @@ namespace ts {
118
118
/**
119
119
* Already seen affected files
120
120
*/
121
- seenAffectedFiles : Map < string , true > | undefined ;
121
+ seenAffectedFiles : Set < string > | undefined ;
122
122
/**
123
123
* whether this program has cleaned semantic diagnostics cache for lib files
124
124
*/
125
125
cleanedDiagnosticsOfLibFiles ?: boolean ;
126
126
/**
127
127
* True if the semantic diagnostics were copied from the old state
128
128
*/
129
- semanticDiagnosticsFromOldState ?: Map < string , true > ;
129
+ semanticDiagnosticsFromOldState ?: Set < string > ;
130
130
/**
131
131
* program corresponding to this state
132
132
*/
@@ -161,9 +161,9 @@ namespace ts {
161
161
programEmitComplete ?: true ;
162
162
}
163
163
164
- function hasSameKeys < T , U > ( map1 : ReadonlyMap < string , T > | undefined , map2 : ReadonlyMap < string , U > | undefined ) : boolean {
164
+ function hasSameKeys ( map1 : ReadonlyCollection < string > | undefined , map2 : ReadonlyCollection < string > | undefined ) : boolean {
165
165
// Has same size and every key is present in both maps
166
- return map1 as ReadonlyMap < string , T | U > === map2 || map1 !== undefined && map2 !== undefined && map1 . size === map2 . size && ! forEachKey ( map1 , key => ! map2 . has ( key ) ) ;
166
+ return map1 === map2 || map1 !== undefined && map2 !== undefined && map1 . size === map2 . size && ! forEachKey ( map1 , key => ! map2 . has ( key ) ) ;
167
167
}
168
168
169
169
/**
@@ -178,7 +178,7 @@ namespace ts {
178
178
if ( ! outFile ( compilerOptions ) ) {
179
179
state . semanticDiagnosticsPerFile = createMap < readonly Diagnostic [ ] > ( ) ;
180
180
}
181
- state . changedFilesSet = createMap < true > ( ) ;
181
+ state . changedFilesSet = new Set ( ) ;
182
182
183
183
const useOldState = BuilderState . canReuseOldState ( state . referencedMap , oldState ) ;
184
184
const oldCompilerOptions = useOldState ? oldState ! . compilerOptions : undefined ;
@@ -196,14 +196,12 @@ namespace ts {
196
196
}
197
197
198
198
// Copy old state's changed files set
199
- if ( changedFilesSet ) {
200
- copyEntries ( changedFilesSet , state . changedFilesSet ) ;
201
- }
199
+ changedFilesSet ?. forEach ( value => state . changedFilesSet . add ( value ) ) ;
202
200
if ( ! outFile ( compilerOptions ) && oldState ! . affectedFilesPendingEmit ) {
203
201
state . affectedFilesPendingEmit = oldState ! . affectedFilesPendingEmit . slice ( ) ;
204
202
state . affectedFilesPendingEmitKind = cloneMapOrUndefined ( oldState ! . affectedFilesPendingEmitKind ) ;
205
203
state . affectedFilesPendingEmitIndex = oldState ! . affectedFilesPendingEmitIndex ;
206
- state . seenAffectedFiles = createMap ( ) ;
204
+ state . seenAffectedFiles = new Set ( ) ;
207
205
}
208
206
}
209
207
@@ -227,7 +225,7 @@ namespace ts {
227
225
// Referenced file was deleted in the new program
228
226
newReferences && forEachKey ( newReferences , path => ! state . fileInfos . has ( path ) && oldState ! . fileInfos . has ( path ) ) ) {
229
227
// Register file as changed file and do not copy semantic diagnostics, since all changed files need to be re-evaluated
230
- state . changedFilesSet . set ( sourceFilePath , true ) ;
228
+ state . changedFilesSet . add ( sourceFilePath ) ;
231
229
}
232
230
else if ( canCopySemanticDiagnostics ) {
233
231
const sourceFile = newProgram . getSourceFileByPath ( sourceFilePath as Path ) ! ;
@@ -240,23 +238,23 @@ namespace ts {
240
238
if ( diagnostics ) {
241
239
state . semanticDiagnosticsPerFile ! . set ( sourceFilePath , oldState ! . hasReusableDiagnostic ? convertToDiagnostics ( diagnostics as readonly ReusableDiagnostic [ ] , newProgram , getCanonicalFileName ) : diagnostics as readonly Diagnostic [ ] ) ;
242
240
if ( ! state . semanticDiagnosticsFromOldState ) {
243
- state . semanticDiagnosticsFromOldState = createMap < true > ( ) ;
241
+ state . semanticDiagnosticsFromOldState = new Set ( ) ;
244
242
}
245
- state . semanticDiagnosticsFromOldState . set ( sourceFilePath , true ) ;
243
+ state . semanticDiagnosticsFromOldState . add ( sourceFilePath ) ;
246
244
}
247
245
}
248
246
} ) ;
249
247
250
248
// If the global file is removed, add all files as changed
251
249
if ( useOldState && forEachEntry ( oldState ! . fileInfos , ( info , sourceFilePath ) => info . affectsGlobalScope && ! state . fileInfos . has ( sourceFilePath ) ) ) {
252
250
BuilderState . getAllFilesExcludingDefaultLibraryFile ( state , newProgram , /*firstSourceFile*/ undefined )
253
- . forEach ( file => state . changedFilesSet . set ( file . resolvedPath , true ) ) ;
251
+ . forEach ( file => state . changedFilesSet . add ( file . resolvedPath ) ) ;
254
252
}
255
253
else if ( oldCompilerOptions && ! outFile ( compilerOptions ) && compilerOptionsAffectEmit ( compilerOptions , oldCompilerOptions ) ) {
256
254
// Add all files to affectedFilesPendingEmit since emit changed
257
255
newProgram . getSourceFiles ( ) . forEach ( f => addToAffectedFilesPendingEmit ( state , f . resolvedPath , BuilderFileEmit . Full ) ) ;
258
256
Debug . assert ( ! state . seenAffectedFiles || ! state . seenAffectedFiles . size ) ;
259
- state . seenAffectedFiles = state . seenAffectedFiles || createMap < true > ( ) ;
257
+ state . seenAffectedFiles = state . seenAffectedFiles || new Set ( ) ;
260
258
}
261
259
262
260
state . buildInfoEmitPending = ! ! state . changedFilesSet . size ;
@@ -308,15 +306,15 @@ namespace ts {
308
306
function cloneBuilderProgramState ( state : Readonly < BuilderProgramState > ) : BuilderProgramState {
309
307
const newState = BuilderState . clone ( state ) as BuilderProgramState ;
310
308
newState . semanticDiagnosticsPerFile = cloneMapOrUndefined ( state . semanticDiagnosticsPerFile ) ;
311
- newState . changedFilesSet = cloneMap ( state . changedFilesSet ) ;
309
+ newState . changedFilesSet = new Set ( state . changedFilesSet ) ;
312
310
newState . affectedFiles = state . affectedFiles ;
313
311
newState . affectedFilesIndex = state . affectedFilesIndex ;
314
312
newState . currentChangedFilePath = state . currentChangedFilePath ;
315
313
newState . currentAffectedFilesSignatures = cloneMapOrUndefined ( state . currentAffectedFilesSignatures ) ;
316
314
newState . currentAffectedFilesExportedModulesMap = cloneMapOrUndefined ( state . currentAffectedFilesExportedModulesMap ) ;
317
- newState . seenAffectedFiles = cloneMapOrUndefined ( state . seenAffectedFiles ) ;
315
+ newState . seenAffectedFiles = state . seenAffectedFiles && new Set ( state . seenAffectedFiles ) ;
318
316
newState . cleanedDiagnosticsOfLibFiles = state . cleanedDiagnosticsOfLibFiles ;
319
- newState . semanticDiagnosticsFromOldState = cloneMapOrUndefined ( state . semanticDiagnosticsFromOldState ) ;
317
+ newState . semanticDiagnosticsFromOldState = state . semanticDiagnosticsFromOldState && new Set ( state . semanticDiagnosticsFromOldState ) ;
320
318
newState . program = state . program ;
321
319
newState . compilerOptions = state . compilerOptions ;
322
320
newState . affectedFilesPendingEmit = state . affectedFilesPendingEmit && state . affectedFilesPendingEmit . slice ( ) ;
@@ -391,7 +389,7 @@ namespace ts {
391
389
state . affectedFiles = BuilderState . getFilesAffectedBy ( state , program , nextKey . value as Path , cancellationToken , computeHash , state . currentAffectedFilesSignatures , state . currentAffectedFilesExportedModulesMap ) ;
392
390
state . currentChangedFilePath = nextKey . value as Path ;
393
391
state . affectedFilesIndex = 0 ;
394
- state . seenAffectedFiles = state . seenAffectedFiles || createMap < true > ( ) ;
392
+ state . seenAffectedFiles = state . seenAffectedFiles || new Set ( ) ;
395
393
}
396
394
}
397
395
@@ -533,7 +531,7 @@ namespace ts {
533
531
}
534
532
535
533
Debug . assert ( ! ! state . currentAffectedFilesExportedModulesMap ) ;
536
- const seenFileAndExportsOfFile = createMap < true > ( ) ;
534
+ const seenFileAndExportsOfFile = new Set < string > ( ) ;
537
535
// Go through exported modules from cache first
538
536
// If exported modules has path, all files referencing file exported from are affected
539
537
if ( forEachEntry ( state . currentAffectedFilesExportedModulesMap , ( exportedModules , exportedFromPath ) =>
@@ -555,7 +553,7 @@ namespace ts {
555
553
/**
556
554
* Iterate on files referencing referencedPath
557
555
*/
558
- function forEachFilesReferencingPath ( state : BuilderProgramState , referencedPath : Path , seenFileAndExportsOfFile : Map < string , true > , fn : ( state : BuilderProgramState , filePath : Path ) => boolean ) {
556
+ function forEachFilesReferencingPath ( state : BuilderProgramState , referencedPath : Path , seenFileAndExportsOfFile : Set < string > , fn : ( state : BuilderProgramState , filePath : Path ) => boolean ) {
559
557
return forEachEntry ( state . referencedMap ! , ( referencesInFile , filePath ) =>
560
558
referencesInFile . has ( referencedPath ) && forEachFileAndExportsOfFile ( state , filePath as Path , seenFileAndExportsOfFile , fn )
561
559
) ;
@@ -564,8 +562,8 @@ namespace ts {
564
562
/**
565
563
* fn on file and iterate on anything that exports this file
566
564
*/
567
- function forEachFileAndExportsOfFile ( state : BuilderProgramState , filePath : Path , seenFileAndExportsOfFile : Map < string , true > , fn : ( state : BuilderProgramState , filePath : Path ) => boolean ) : boolean {
568
- if ( ! addToSeen ( seenFileAndExportsOfFile , filePath ) ) {
565
+ function forEachFileAndExportsOfFile ( state : BuilderProgramState , filePath : Path , seenFileAndExportsOfFile : Set < string > , fn : ( state : BuilderProgramState , filePath : Path ) => boolean ) : boolean {
566
+ if ( ! tryAddToSet ( seenFileAndExportsOfFile , filePath ) ) {
569
567
return false ;
570
568
}
571
569
@@ -622,7 +620,7 @@ namespace ts {
622
620
state . programEmitComplete = true ;
623
621
}
624
622
else {
625
- state . seenAffectedFiles ! . set ( ( affected as SourceFile ) . resolvedPath , true ) ;
623
+ state . seenAffectedFiles ! . add ( ( affected as SourceFile ) . resolvedPath ) ;
626
624
if ( emitKind !== undefined ) {
627
625
( state . seenEmittedFiles || ( state . seenEmittedFiles = createMap ( ) ) ) . set ( ( affected as SourceFile ) . resolvedPath , emitKind ) ;
628
626
}
@@ -1149,7 +1147,7 @@ namespace ts {
1149
1147
// template is undefined, and instead will just exit the loop.
1150
1148
for ( const key in mapLike ) {
1151
1149
if ( hasProperty ( mapLike , key ) ) {
1152
- map . set ( toPath ( key ) , arrayToSet ( mapLike [ key ] , toPath ) ) ;
1150
+ map . set ( toPath ( key ) , new Set ( mapLike [ key ] . map ( toPath ) ) ) ;
1153
1151
}
1154
1152
}
1155
1153
return map ;
0 commit comments