@@ -265,11 +265,11 @@ namespace ts {
265
265
const { affectedFilesPendingEmit } = state ;
266
266
if ( affectedFilesPendingEmit ) {
267
267
const seenEmittedFiles = state . seenEmittedFiles || ( state . seenEmittedFiles = createMap ( ) ) ;
268
- for ( let affectedFilesIndex = state . affectedFilesPendingEmitIndex ! ; affectedFilesIndex < affectedFilesPendingEmit . length ; affectedFilesIndex ++ ) {
269
- const affectedFile = Debug . assertDefined ( state . program ) . getSourceFileByPath ( affectedFilesPendingEmit [ affectedFilesIndex ] ) ;
268
+ for ( let i = state . affectedFilesPendingEmitIndex ! ; i < affectedFilesPendingEmit . length ; i ++ ) {
269
+ const affectedFile = Debug . assertDefined ( state . program ) . getSourceFileByPath ( affectedFilesPendingEmit [ i ] ) ;
270
270
if ( affectedFile && ! seenEmittedFiles . has ( affectedFile . path ) ) {
271
271
// emit this file
272
- state . affectedFilesPendingEmitIndex = affectedFilesIndex ;
272
+ state . affectedFilesPendingEmitIndex = i ;
273
273
return affectedFile ;
274
274
}
275
275
}
@@ -695,6 +695,10 @@ namespace ts {
695
695
// In case of emit builder, cache the files to be emitted
696
696
if ( affectedFilesPendingEmit ) {
697
697
state . affectedFilesPendingEmit = concatenate ( state . affectedFilesPendingEmit , affectedFilesPendingEmit ) ;
698
+ // affectedFilesPendingEmitIndex === undefined
699
+ // - means the emit state.affectedFilesPendingEmit was undefined before adding current affected files
700
+ // so start from 0 as array would be affectedFilesPendingEmit
701
+ // else, continue to iterate from existing index, the current set is appended to existing files
698
702
if ( state . affectedFilesPendingEmitIndex === undefined ) {
699
703
state . affectedFilesPendingEmitIndex = 0 ;
700
704
}
0 commit comments