@@ -238,14 +238,14 @@ module ts {
238
238
239
239
function addWatchers ( program : Program ) {
240
240
forEach ( program . getSourceFiles ( ) , f => {
241
- var filename = f . filename ;
241
+ var filename = getCanonicalName ( f . filename ) ;
242
242
watchers [ filename ] = sys . watchFile ( filename , fileUpdated ) ;
243
243
} ) ;
244
244
}
245
245
246
246
function removeWatchers ( program : Program ) {
247
247
forEach ( program . getSourceFiles ( ) , f => {
248
- var filename = f . filename ;
248
+ var filename = getCanonicalName ( f . filename ) ;
249
249
if ( hasProperty ( watchers , filename ) ) {
250
250
watchers [ filename ] . close ( ) ;
251
251
}
@@ -257,8 +257,7 @@ module ts {
257
257
// Fired off whenever a file is changed.
258
258
function fileUpdated ( filename : string ) {
259
259
var firstNotification = isEmpty ( updatedFiles ) ;
260
-
261
- updatedFiles [ filename ] = true ;
260
+ updatedFiles [ getCanonicalName ( filename ) ] = true ;
262
261
263
262
// Only start this off when the first file change comes in,
264
263
// so that we can batch up all further changes.
@@ -279,16 +278,21 @@ module ts {
279
278
removeWatchers ( program ) ;
280
279
281
280
// Gets us syntactically correct files from the last compilation.
282
- var getUnmodifiedSourceFile = program . getSourceFile ;
281
+ var oldSourceFiles = arrayToMap ( program . getSourceFiles ( ) , file => getCanonicalName ( file . filename ) ) ;
282
+
283
+ // No longer using the old program.
284
+ program = undefined ;
283
285
284
286
// We create a new compiler host for this compilation cycle.
285
287
// This new host is effectively the same except that 'getSourceFile'
286
288
// will try to reuse the SourceFiles from the last compilation cycle
287
289
// so long as they were not modified.
288
290
var newCompilerHost = clone ( compilerHost ) ;
289
291
newCompilerHost . getSourceFile = ( fileName , languageVersion , onError ) => {
292
+ fileName = getCanonicalName ( fileName ) ;
293
+
290
294
if ( ! hasProperty ( changedFiles , fileName ) ) {
291
- var sourceFile = getUnmodifiedSourceFile ( fileName ) ;
295
+ var sourceFile = lookUp ( oldSourceFiles , fileName ) ;
292
296
if ( sourceFile ) {
293
297
return sourceFile ;
294
298
}
@@ -301,6 +305,10 @@ module ts {
301
305
reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Compilation_complete_Watching_for_file_changes ) ) ;
302
306
addWatchers ( program ) ;
303
307
}
308
+
309
+ function getCanonicalName ( fileName : string ) {
310
+ return compilerHost . getCanonicalFileName ( fileName ) ;
311
+ }
304
312
}
305
313
306
314
function compile ( commandLine : ParsedCommandLine , compilerHost : CompilerHost ) {
0 commit comments