@@ -245,14 +245,14 @@ module ts {
245
245
246
246
function addWatchers ( program : Program ) {
247
247
forEach ( program . getSourceFiles ( ) , f => {
248
- var filename = f . filename ;
248
+ var filename = getCanonicalName ( f . filename ) ;
249
249
watchers [ filename ] = sys . watchFile ( filename , fileUpdated ) ;
250
250
} ) ;
251
251
}
252
252
253
253
function removeWatchers ( program : Program ) {
254
254
forEach ( program . getSourceFiles ( ) , f => {
255
- var filename = f . filename ;
255
+ var filename = getCanonicalName ( f . filename ) ;
256
256
if ( hasProperty ( watchers , filename ) ) {
257
257
watchers [ filename ] . close ( ) ;
258
258
}
@@ -264,8 +264,7 @@ module ts {
264
264
// Fired off whenever a file is changed.
265
265
function fileUpdated ( filename : string ) {
266
266
var firstNotification = isEmpty ( updatedFiles ) ;
267
-
268
- updatedFiles [ filename ] = true ;
267
+ updatedFiles [ getCanonicalName ( filename ) ] = true ;
269
268
270
269
// Only start this off when the first file change comes in,
271
270
// so that we can batch up all further changes.
@@ -285,20 +284,22 @@ module ts {
285
284
// specified since the last compilation cycle.
286
285
removeWatchers ( program ) ;
287
286
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 ) ) ;
290
291
291
292
// We create a new compiler host for this compilation cycle.
292
293
// This new host is effectively the same except that 'getSourceFile'
293
294
// will try to reuse the SourceFiles from the last compilation cycle
294
295
// so long as they were not modified.
295
296
var newCompilerHost = clone ( compilerHost ) ;
296
297
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 ;
302
303
}
303
304
304
305
return compilerHost . getSourceFile ( fileName , languageVersion , onError ) ;
@@ -308,6 +309,10 @@ module ts {
308
309
reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Compilation_complete_Watching_for_file_changes ) ) ;
309
310
addWatchers ( program ) ;
310
311
}
312
+
313
+ function getCanonicalName ( fileName : string ) {
314
+ return compilerHost . getCanonicalFileName ( fileName ) ;
315
+ }
311
316
}
312
317
313
318
function compile ( commandLine : ParsedCommandLine , compilerHost : CompilerHost ) {
0 commit comments