Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace ts {
realpath?(path: string): string;
/*@internal*/ getEnvironmentVariable(name: string): string;
/*@internal*/ tryEnableSourceMapsForHost?(): void;
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
clearTimeout?(timeoutId: any): void;
}

export interface FileWatcher {
Expand Down Expand Up @@ -560,7 +562,9 @@ namespace ts {
catch (e) {
// Could not enable source maps.
}
}
},
setTimeout,
clearTimeout
};
return nodeSystem;
}
Expand Down
20 changes: 14 additions & 6 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ namespace ts {
let compilerOptions: CompilerOptions; // Compiler options for compilation
let compilerHost: CompilerHost; // Compiler host
let hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host
let timerHandleForRecompilation: number; // Handle for 0.25s wait timer to trigger recompilation
let timerHandleForDirectoryChanges: number; // Handle for 0.25s wait timer to trigger directory change handler
let timerHandleForRecompilation: any; // Handle for 0.25s wait timer to trigger recompilation
let timerHandleForDirectoryChanges: any; // Handle for 0.25s wait timer to trigger directory change handler

// This map stores and reuses results of fileExists check that happen inside 'createProgram'
// This allows to save time in module resolution heavy scenarios when existence of the same file might be checked multiple times.
Expand Down Expand Up @@ -503,10 +503,14 @@ namespace ts {
}

function startTimerForHandlingDirectoryChanges() {
if (!sys.setTimeout || !sys.clearTimeout) {
return;
}

if (timerHandleForDirectoryChanges) {
clearTimeout(timerHandleForDirectoryChanges);
sys.clearTimeout(timerHandleForDirectoryChanges);
}
timerHandleForDirectoryChanges = setTimeout(directoryChangeHandler, 250);
timerHandleForDirectoryChanges = sys.setTimeout(directoryChangeHandler, 250);
}

function directoryChangeHandler() {
Expand All @@ -525,10 +529,14 @@ namespace ts {
// operations (such as saving all modified files in an editor) a chance to complete before we kick
// off a new compilation.
function startTimerForRecompilation() {
if (!sys.setTimeout || !sys.clearTimeout) {
return;
}

if (timerHandleForRecompilation) {
clearTimeout(timerHandleForRecompilation);
sys.clearTimeout(timerHandleForRecompilation);
}
timerHandleForRecompilation = setTimeout(recompile, 250);
timerHandleForRecompilation = sys.setTimeout(recompile, 250);
}

function recompile() {
Expand Down