@@ -144,13 +144,14 @@ namespace ts {
144144
145145 function compileWatchedProgram ( host : DirectoryStructureHost , program : Program , builder : Builder ) {
146146 // First get and report any syntactic errors.
147- let diagnostics = program . getSyntacticDiagnostics ( ) . slice ( ) ;
147+ const diagnostics = program . getSyntacticDiagnostics ( ) . slice ( ) ;
148148 let reportSemanticDiagnostics = false ;
149149
150150 // If we didn't have any syntactic errors, then also try getting the global and
151151 // semantic errors.
152152 if ( diagnostics . length === 0 ) {
153- diagnostics = program . getOptionsDiagnostics ( ) . concat ( program . getGlobalDiagnostics ( ) ) ;
153+ addRange ( diagnostics , program . getOptionsDiagnostics ( ) ) ;
154+ addRange ( diagnostics , program . getGlobalDiagnostics ( ) ) ;
154155
155156 if ( diagnostics . length === 0 ) {
156157 reportSemanticDiagnostics = true ;
@@ -162,7 +163,7 @@ namespace ts {
162163 let sourceMaps : SourceMapData [ ] ;
163164 let emitSkipped : boolean ;
164165
165- const result = builder . emitChangedFiles ( program ) ;
166+ const result = builder . emitChangedFiles ( program , writeFile ) ;
166167 if ( result . length === 0 ) {
167168 emitSkipped = true ;
168169 }
@@ -171,14 +172,13 @@ namespace ts {
171172 if ( emitOutput . emitSkipped ) {
172173 emitSkipped = true ;
173174 }
174- diagnostics = concatenate ( diagnostics , emitOutput . diagnostics ) ;
175+ addRange ( diagnostics , emitOutput . diagnostics ) ;
175176 sourceMaps = concatenate ( sourceMaps , emitOutput . sourceMaps ) ;
176- writeOutputFiles ( emitOutput . outputFiles ) ;
177177 }
178178 }
179179
180180 if ( reportSemanticDiagnostics ) {
181- diagnostics = diagnostics . concat ( builder . getSemanticDiagnostics ( program ) ) ;
181+ addRange ( diagnostics , builder . getSemanticDiagnostics ( program ) ) ;
182182 }
183183 return handleEmitOutputAndReportErrors ( host , program , emittedFiles , emitSkipped ,
184184 diagnostics , reportDiagnostic ) ;
@@ -191,31 +191,23 @@ namespace ts {
191191 }
192192 }
193193
194- function writeFile ( fileName : string , data : string , writeByteOrderMark : boolean ) {
194+ function writeFile ( fileName : string , text : string , writeByteOrderMark : boolean , onError : ( message : string ) => void ) {
195195 try {
196196 performance . mark ( "beforeIOWrite" ) ;
197197 ensureDirectoriesExist ( getDirectoryPath ( normalizePath ( fileName ) ) ) ;
198198
199- host . writeFile ( fileName , data , writeByteOrderMark ) ;
199+ host . writeFile ( fileName , text , writeByteOrderMark ) ;
200200
201201 performance . mark ( "afterIOWrite" ) ;
202202 performance . measure ( "I/O Write" , "beforeIOWrite" , "afterIOWrite" ) ;
203+
204+ if ( emittedFiles ) {
205+ emittedFiles . push ( fileName ) ;
206+ }
203207 }
204208 catch ( e ) {
205- return createCompilerDiagnostic ( Diagnostics . Could_not_write_file_0_Colon_1 , fileName , e ) ;
206- }
207- }
208-
209- function writeOutputFiles ( outputFiles : OutputFile [ ] ) {
210- if ( outputFiles ) {
211- for ( const outputFile of outputFiles ) {
212- const error = writeFile ( outputFile . name , outputFile . text , outputFile . writeByteOrderMark ) ;
213- if ( error ) {
214- diagnostics . push ( error ) ;
215- }
216- if ( emittedFiles ) {
217- emittedFiles . push ( outputFile . name ) ;
218- }
209+ if ( onError ) {
210+ onError ( e . message ) ;
219211 }
220212 }
221213 }
@@ -308,7 +300,7 @@ namespace ts {
308300 getCurrentDirectory ( )
309301 ) ;
310302 // There is no extra check needed since we can just rely on the program to decide emit
311- const builder = createBuilder ( { getCanonicalFileName, getEmitOutput : getFileEmitOutput , computeHash, shouldEmitFile : ( ) => true } ) ;
303+ const builder = createBuilder ( { getCanonicalFileName, computeHash } ) ;
312304
313305 synchronizeProgram ( ) ;
314306
0 commit comments