@@ -245,14 +245,14 @@ module ts {
245245
246246 function addWatchers ( program : Program ) {
247247 forEach ( program . getSourceFiles ( ) , f => {
248- var filename = f . filename ;
248+ var filename = getCanonicalName ( f . filename ) ;
249249 watchers [ filename ] = sys . watchFile ( filename , fileUpdated ) ;
250250 } ) ;
251251 }
252252
253253 function removeWatchers ( program : Program ) {
254254 forEach ( program . getSourceFiles ( ) , f => {
255- var filename = f . filename ;
255+ var filename = getCanonicalName ( f . filename ) ;
256256 if ( hasProperty ( watchers , filename ) ) {
257257 watchers [ filename ] . close ( ) ;
258258 }
@@ -264,8 +264,7 @@ module ts {
264264 // Fired off whenever a file is changed.
265265 function fileUpdated ( filename : string ) {
266266 var firstNotification = isEmpty ( updatedFiles ) ;
267-
268- updatedFiles [ filename ] = true ;
267+ updatedFiles [ getCanonicalName ( filename ) ] = true ;
269268
270269 // Only start this off when the first file change comes in,
271270 // so that we can batch up all further changes.
@@ -285,20 +284,22 @@ module ts {
285284 // specified since the last compilation cycle.
286285 removeWatchers ( program ) ;
287286
288- // Gets us syntactically correct files from the last compilation.
289- var getUnmodifiedSourceFile = program . getSourceFile ;
287+ // Reuse source files from the last compilation so long as they weren't changed.
288+ var oldSourceFiles = arrayToMap (
289+ filter ( program . getSourceFiles ( ) , file => ! hasProperty ( changedFiles , getCanonicalName ( file . filename ) ) ) ,
290+ file => getCanonicalName ( file . filename ) ) ;
290291
291292 // We create a new compiler host for this compilation cycle.
292293 // This new host is effectively the same except that 'getSourceFile'
293294 // will try to reuse the SourceFiles from the last compilation cycle
294295 // so long as they were not modified.
295296 var newCompilerHost = clone ( compilerHost ) ;
296297 newCompilerHost . getSourceFile = ( fileName , languageVersion , onError ) => {
297- if ( ! hasProperty ( changedFiles , fileName ) ) {
298- var sourceFile = getUnmodifiedSourceFile ( fileName ) ;
299- if ( sourceFile ) {
300- return sourceFile ;
301- }
298+ fileName = getCanonicalName ( fileName ) ;
299+
300+ var sourceFile = lookUp ( oldSourceFiles , fileName ) ;
301+ if ( sourceFile ) {
302+ return sourceFile ;
302303 }
303304
304305 return compilerHost . getSourceFile ( fileName , languageVersion , onError ) ;
@@ -308,6 +309,10 @@ module ts {
308309 reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Compilation_complete_Watching_for_file_changes ) ) ;
309310 addWatchers ( program ) ;
310311 }
312+
313+ function getCanonicalName ( fileName : string ) {
314+ return compilerHost . getCanonicalFileName ( fileName ) ;
315+ }
311316 }
312317
313318 function compile ( commandLine : ParsedCommandLine , compilerHost : CompilerHost ) {
0 commit comments