@@ -248,7 +248,6 @@ namespace ts {
248248 let timerToUpdateProgram : any ; // timer callback to recompile the program
249249
250250 const sourceFilesCache = createMap < HostFileInfo | string > ( ) ; // Cache that stores the source file and version info
251- let changedFilePaths : Path [ ] = [ ] ;
252251
253252 let host : System ;
254253 if ( configFileName ) {
@@ -262,7 +261,7 @@ namespace ts {
262261 const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ) ;
263262
264263 // There is no extra check needed since we can just rely on the program to decide emit
265- const builder = createBuilder ( getCanonicalFileName , getDetailedEmitOutput , computeHash , _sourceFile => true ) ;
264+ const builder = createBuilder ( getCanonicalFileName , getFileEmitOutput , computeHash , _sourceFile => true ) ;
266265
267266 if ( compilerOptions . pretty ) {
268267 reportDiagnosticWorker = reportDiagnosticWithColorAndContext ;
@@ -352,51 +351,44 @@ namespace ts {
352351
353352 function emitWithBuilder ( program : Program ) : EmitResult {
354353 builder . onProgramUpdateGraph ( program ) ;
355- const filesPendingToEmit = changedFilePaths ;
356- changedFilePaths = [ ] ;
357-
358- const seenFiles = createMap < true > ( ) ;
359-
360- let emitSkipped : boolean ;
361- const diagnostics : Diagnostic [ ] = [ ] ;
362354 const emittedFiles : string [ ] = program . getCompilerOptions ( ) . listEmittedFiles ? [ ] : undefined ;
363355 let sourceMaps : SourceMapData [ ] ;
364- while ( filesPendingToEmit . length ) {
365- const filePath = filesPendingToEmit . pop ( ) ;
366- const affectedFiles = builder . getFilesAffectedBy ( program , filePath ) ;
367- for ( const file of affectedFiles ) {
368- if ( ! seenFiles . has ( file ) ) {
369- seenFiles . set ( file , true ) ;
370- const sourceFile = program . getSourceFile ( file ) ;
371- if ( sourceFile ) {
372- writeFiles ( < EmitOutputDetailed > builder . emitFile ( program , sourceFile . path ) ) ;
356+ let emitSkipped : boolean ;
357+ let diagnostics : Diagnostic [ ] ;
358+
359+ const result = builder . emitChangedFiles ( program ) ;
360+ switch ( result . length ) {
361+ case 0 :
362+ emitSkipped = true ;
363+ break ;
364+ case 1 :
365+ const emitOutput = result [ 0 ] ;
366+ ( { diagnostics, sourceMaps, emitSkipped } = emitOutput ) ;
367+ writeOutputFiles ( emitOutput . outputFiles ) ;
368+ break ;
369+ default :
370+ for ( const emitOutput of result ) {
371+ if ( emitOutput . emitSkipped ) {
372+ emitSkipped = true ;
373373 }
374+ diagnostics = concatenate ( diagnostics , emitOutput . diagnostics ) ;
375+ sourceMaps = concatenate ( sourceMaps , emitOutput . sourceMaps ) ;
376+ writeOutputFiles ( emitOutput . outputFiles ) ;
374377 }
375- }
376378 }
377379
378- return { emitSkipped, diagnostics, emittedFiles, sourceMaps } ;
379-
380- function writeFiles ( emitOutput : EmitOutputDetailed ) {
381- if ( emitOutput . emitSkipped ) {
382- emitSkipped = true ;
383- }
380+ return { emitSkipped, diagnostics : diagnostics || [ ] , emittedFiles, sourceMaps } ;
384381
385- diagnostics . push ( ...emitOutput . diagnostics ) ;
386- sourceMaps = concatenate ( sourceMaps , emitOutput . sourceMaps ) ;
387- // If it emitted more than one source files, just mark all those source files as seen
388- if ( emitOutput . emittedSourceFiles && emitOutput . emittedSourceFiles . length > 1 ) {
389- for ( const file of emitOutput . emittedSourceFiles ) {
390- seenFiles . set ( file . fileName , true ) ;
391- }
392- }
393- for ( const outputFile of emitOutput . outputFiles ) {
394- const error = writeFile ( outputFile . name , outputFile . text , outputFile . writeByteOrderMark ) ;
395- if ( error ) {
396- diagnostics . push ( error ) ;
397- }
398- if ( emittedFiles ) {
399- emittedFiles . push ( outputFile . name ) ;
382+ function writeOutputFiles ( outputFiles : OutputFile [ ] ) {
383+ if ( outputFiles ) {
384+ for ( const outputFile of outputFiles ) {
385+ const error = writeFile ( outputFile . name , outputFile . text , outputFile . writeByteOrderMark ) ;
386+ if ( error ) {
387+ diagnostics . push ( error ) ;
388+ }
389+ if ( emittedFiles ) {
390+ emittedFiles . push ( outputFile . name ) ;
391+ }
400392 }
401393 }
402394 }
@@ -430,8 +422,6 @@ namespace ts {
430422
431423 // Create new source file if requested or the versions dont match
432424 if ( ! hostSourceFile || shouldCreateNewSourceFile || hostSourceFile . version . toString ( ) !== hostSourceFile . sourceFile . version ) {
433- changedFilePaths . push ( path ) ;
434-
435425 const sourceFile = getNewSourceFile ( ) ;
436426 if ( hostSourceFile ) {
437427 if ( shouldCreateNewSourceFile ) {
0 commit comments