@@ -28,7 +28,7 @@ namespace ts {
2828 /**
2929 * The map has key by source file's path that has been changed
3030 */
31- changedFilesSet ?: ReadonlyMap < string , true > ;
31+ changedFilesSet ?: ReadonlySet < string > ;
3232 /**
3333 * Set of affected files being iterated
3434 */
@@ -49,7 +49,7 @@ namespace ts {
4949 /**
5050 * True if the semantic diagnostics were copied from the old state
5151 */
52- semanticDiagnosticsFromOldState ?: Map < string , true > ;
52+ semanticDiagnosticsFromOldState ?: Set < string > ;
5353 /**
5454 * program corresponding to this state
5555 */
@@ -93,7 +93,7 @@ namespace ts {
9393 /**
9494 * The map has key by source file's path that has been changed
9595 */
96- changedFilesSet : Map < string , true > ;
96+ changedFilesSet : Set < string > ;
9797 /**
9898 * Set of affected files being iterated
9999 */
@@ -118,15 +118,15 @@ namespace ts {
118118 /**
119119 * Already seen affected files
120120 */
121- seenAffectedFiles : Map < string , true > | undefined ;
121+ seenAffectedFiles : Set < string > | undefined ;
122122 /**
123123 * whether this program has cleaned semantic diagnostics cache for lib files
124124 */
125125 cleanedDiagnosticsOfLibFiles ?: boolean ;
126126 /**
127127 * True if the semantic diagnostics were copied from the old state
128128 */
129- semanticDiagnosticsFromOldState ?: Map < string , true > ;
129+ semanticDiagnosticsFromOldState ?: Set < string > ;
130130 /**
131131 * program corresponding to this state
132132 */
@@ -161,9 +161,9 @@ namespace ts {
161161 programEmitComplete ?: true ;
162162 }
163163
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 {
165165 // 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 ) ) ;
167167 }
168168
169169 /**
@@ -178,7 +178,7 @@ namespace ts {
178178 if ( ! outFile ( compilerOptions ) ) {
179179 state . semanticDiagnosticsPerFile = createMap < readonly Diagnostic [ ] > ( ) ;
180180 }
181- state . changedFilesSet = createMap < true > ( ) ;
181+ state . changedFilesSet = new Set ( ) ;
182182
183183 const useOldState = BuilderState . canReuseOldState ( state . referencedMap , oldState ) ;
184184 const oldCompilerOptions = useOldState ? oldState ! . compilerOptions : undefined ;
@@ -196,14 +196,12 @@ namespace ts {
196196 }
197197
198198 // Copy old state's changed files set
199- if ( changedFilesSet ) {
200- copyEntries ( changedFilesSet , state . changedFilesSet ) ;
201- }
199+ changedFilesSet ?. forEach ( value => state . changedFilesSet . add ( value ) ) ;
202200 if ( ! outFile ( compilerOptions ) && oldState ! . affectedFilesPendingEmit ) {
203201 state . affectedFilesPendingEmit = oldState ! . affectedFilesPendingEmit . slice ( ) ;
204202 state . affectedFilesPendingEmitKind = cloneMapOrUndefined ( oldState ! . affectedFilesPendingEmitKind ) ;
205203 state . affectedFilesPendingEmitIndex = oldState ! . affectedFilesPendingEmitIndex ;
206- state . seenAffectedFiles = createMap ( ) ;
204+ state . seenAffectedFiles = new Set ( ) ;
207205 }
208206 }
209207
@@ -227,7 +225,7 @@ namespace ts {
227225 // Referenced file was deleted in the new program
228226 newReferences && forEachKey ( newReferences , path => ! state . fileInfos . has ( path ) && oldState ! . fileInfos . has ( path ) ) ) {
229227 // 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 ) ;
231229 }
232230 else if ( canCopySemanticDiagnostics ) {
233231 const sourceFile = newProgram . getSourceFileByPath ( sourceFilePath as Path ) ! ;
@@ -240,23 +238,23 @@ namespace ts {
240238 if ( diagnostics ) {
241239 state . semanticDiagnosticsPerFile ! . set ( sourceFilePath , oldState ! . hasReusableDiagnostic ? convertToDiagnostics ( diagnostics as readonly ReusableDiagnostic [ ] , newProgram , getCanonicalFileName ) : diagnostics as readonly Diagnostic [ ] ) ;
242240 if ( ! state . semanticDiagnosticsFromOldState ) {
243- state . semanticDiagnosticsFromOldState = createMap < true > ( ) ;
241+ state . semanticDiagnosticsFromOldState = new Set ( ) ;
244242 }
245- state . semanticDiagnosticsFromOldState . set ( sourceFilePath , true ) ;
243+ state . semanticDiagnosticsFromOldState . add ( sourceFilePath ) ;
246244 }
247245 }
248246 } ) ;
249247
250248 // If the global file is removed, add all files as changed
251249 if ( useOldState && forEachEntry ( oldState ! . fileInfos , ( info , sourceFilePath ) => info . affectsGlobalScope && ! state . fileInfos . has ( sourceFilePath ) ) ) {
252250 BuilderState . getAllFilesExcludingDefaultLibraryFile ( state , newProgram , /*firstSourceFile*/ undefined )
253- . forEach ( file => state . changedFilesSet . set ( file . resolvedPath , true ) ) ;
251+ . forEach ( file => state . changedFilesSet . add ( file . resolvedPath ) ) ;
254252 }
255253 else if ( oldCompilerOptions && ! outFile ( compilerOptions ) && compilerOptionsAffectEmit ( compilerOptions , oldCompilerOptions ) ) {
256254 // Add all files to affectedFilesPendingEmit since emit changed
257255 newProgram . getSourceFiles ( ) . forEach ( f => addToAffectedFilesPendingEmit ( state , f . resolvedPath , BuilderFileEmit . Full ) ) ;
258256 Debug . assert ( ! state . seenAffectedFiles || ! state . seenAffectedFiles . size ) ;
259- state . seenAffectedFiles = state . seenAffectedFiles || createMap < true > ( ) ;
257+ state . seenAffectedFiles = state . seenAffectedFiles || new Set ( ) ;
260258 }
261259
262260 state . buildInfoEmitPending = ! ! state . changedFilesSet . size ;
@@ -308,15 +306,15 @@ namespace ts {
308306 function cloneBuilderProgramState ( state : Readonly < BuilderProgramState > ) : BuilderProgramState {
309307 const newState = BuilderState . clone ( state ) as BuilderProgramState ;
310308 newState . semanticDiagnosticsPerFile = cloneMapOrUndefined ( state . semanticDiagnosticsPerFile ) ;
311- newState . changedFilesSet = cloneMap ( state . changedFilesSet ) ;
309+ newState . changedFilesSet = new Set ( state . changedFilesSet ) ;
312310 newState . affectedFiles = state . affectedFiles ;
313311 newState . affectedFilesIndex = state . affectedFilesIndex ;
314312 newState . currentChangedFilePath = state . currentChangedFilePath ;
315313 newState . currentAffectedFilesSignatures = cloneMapOrUndefined ( state . currentAffectedFilesSignatures ) ;
316314 newState . currentAffectedFilesExportedModulesMap = cloneMapOrUndefined ( state . currentAffectedFilesExportedModulesMap ) ;
317- newState . seenAffectedFiles = cloneMapOrUndefined ( state . seenAffectedFiles ) ;
315+ newState . seenAffectedFiles = state . seenAffectedFiles && new Set ( state . seenAffectedFiles ) ;
318316 newState . cleanedDiagnosticsOfLibFiles = state . cleanedDiagnosticsOfLibFiles ;
319- newState . semanticDiagnosticsFromOldState = cloneMapOrUndefined ( state . semanticDiagnosticsFromOldState ) ;
317+ newState . semanticDiagnosticsFromOldState = state . semanticDiagnosticsFromOldState && new Set ( state . semanticDiagnosticsFromOldState ) ;
320318 newState . program = state . program ;
321319 newState . compilerOptions = state . compilerOptions ;
322320 newState . affectedFilesPendingEmit = state . affectedFilesPendingEmit && state . affectedFilesPendingEmit . slice ( ) ;
@@ -391,7 +389,7 @@ namespace ts {
391389 state . affectedFiles = BuilderState . getFilesAffectedBy ( state , program , nextKey . value as Path , cancellationToken , computeHash , state . currentAffectedFilesSignatures , state . currentAffectedFilesExportedModulesMap ) ;
392390 state . currentChangedFilePath = nextKey . value as Path ;
393391 state . affectedFilesIndex = 0 ;
394- state . seenAffectedFiles = state . seenAffectedFiles || createMap < true > ( ) ;
392+ state . seenAffectedFiles = state . seenAffectedFiles || new Set ( ) ;
395393 }
396394 }
397395
@@ -533,7 +531,7 @@ namespace ts {
533531 }
534532
535533 Debug . assert ( ! ! state . currentAffectedFilesExportedModulesMap ) ;
536- const seenFileAndExportsOfFile = createMap < true > ( ) ;
534+ const seenFileAndExportsOfFile = new Set < string > ( ) ;
537535 // Go through exported modules from cache first
538536 // If exported modules has path, all files referencing file exported from are affected
539537 if ( forEachEntry ( state . currentAffectedFilesExportedModulesMap , ( exportedModules , exportedFromPath ) =>
@@ -555,7 +553,7 @@ namespace ts {
555553 /**
556554 * Iterate on files referencing referencedPath
557555 */
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 ) {
559557 return forEachEntry ( state . referencedMap ! , ( referencesInFile , filePath ) =>
560558 referencesInFile . has ( referencedPath ) && forEachFileAndExportsOfFile ( state , filePath as Path , seenFileAndExportsOfFile , fn )
561559 ) ;
@@ -564,8 +562,8 @@ namespace ts {
564562 /**
565563 * fn on file and iterate on anything that exports this file
566564 */
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 ) ) {
569567 return false ;
570568 }
571569
@@ -622,7 +620,7 @@ namespace ts {
622620 state . programEmitComplete = true ;
623621 }
624622 else {
625- state . seenAffectedFiles ! . set ( ( affected as SourceFile ) . resolvedPath , true ) ;
623+ state . seenAffectedFiles ! . add ( ( affected as SourceFile ) . resolvedPath ) ;
626624 if ( emitKind !== undefined ) {
627625 ( state . seenEmittedFiles || ( state . seenEmittedFiles = createMap ( ) ) ) . set ( ( affected as SourceFile ) . resolvedPath , emitKind ) ;
628626 }
@@ -1149,7 +1147,7 @@ namespace ts {
11491147 // template is undefined, and instead will just exit the loop.
11501148 for ( const key in mapLike ) {
11511149 if ( hasProperty ( mapLike , key ) ) {
1152- map . set ( toPath ( key ) , arrayToSet ( mapLike [ key ] , toPath ) ) ;
1150+ map . set ( toPath ( key ) , new Set ( mapLike [ key ] . map ( toPath ) ) ) ;
11531151 }
11541152 }
11551153 return map ;
0 commit comments