Incorporating changes from #3780

This commit is contained in:
zhengbli 2015-10-05 16:19:09 -07:00
parent 17f0cce772
commit f7e35d5975
2 changed files with 12 additions and 6 deletions

View file

@ -8,7 +8,7 @@ namespace ts {
write(s: string): void;
readFile(path: string, encoding?: string): string;
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
watchFile?(path: string, callback: (path: string) => void): FileWatcher;
watchFile?(path: string, callback: (path: string, removed?: boolean) => void): FileWatcher;
watchDirectory?(path: string, callback: (path: string) => void, recursive?: boolean): FileWatcher;
resolvePath(path: string): string;
fileExists(path: string): boolean;
@ -23,7 +23,7 @@ namespace ts {
interface WatchedFile {
fileName: string;
callback: (fileName: string) => void;
callback: (fileName: string, removed?: boolean) => void;
mtime: Date;
}
@ -235,7 +235,7 @@ namespace ts {
}
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
watchedFile.mtime = WatchedFileSet.getModifiedTime(watchedFile.fileName);
watchedFile.callback(watchedFile.fileName);
watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
}
});
}
@ -263,7 +263,7 @@ namespace ts {
}, this.interval);
}
addFile(fileName: string, callback: (fileName: string) => void): WatchedFile {
addFile(fileName: string, callback: (fileName: string, removed?: boolean) => void): WatchedFile {
var file: WatchedFile = {
fileName,
callback,

View file

@ -291,7 +291,7 @@ namespace ts {
let sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
if (sourceFile && compilerOptions.watch) {
// Attach a file watcher
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, () => sourceFileChanged(sourceFile));
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed));
}
return sourceFile;
}
@ -313,9 +313,15 @@ namespace ts {
}
// If a source file changes, mark it as unwatched and start the recompilation timer
function sourceFileChanged(sourceFile: SourceFile) {
function sourceFileChanged(sourceFile: SourceFile, removed?: boolean) {
sourceFile.fileWatcher.close();
sourceFile.fileWatcher = undefined;
if (removed) {
var index = rootFileNames.indexOf(sourceFile.fileName);
if (index !== -1) {
rootFileNames.splice(index, 1);
}
}
startTimer();
}