Skip to content

Commit 3f234f2

Browse files
authored
Move setTimeout to sys (#11746)
1 parent aabfcfb commit 3f234f2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/compiler/sys.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ namespace ts {
3434
realpath?(path: string): string;
3535
/*@internal*/ getEnvironmentVariable(name: string): string;
3636
/*@internal*/ tryEnableSourceMapsForHost?(): void;
37+
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
38+
clearTimeout?(timeoutId: any): void;
3739
}
3840

3941
export interface FileWatcher {
@@ -560,7 +562,9 @@ namespace ts {
560562
catch (e) {
561563
// Could not enable source maps.
562564
}
563-
}
565+
},
566+
setTimeout,
567+
clearTimeout
564568
};
565569
return nodeSystem;
566570
}

src/compiler/tsc.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ namespace ts {
250250
let compilerOptions: CompilerOptions; // Compiler options for compilation
251251
let compilerHost: CompilerHost; // Compiler host
252252
let hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host
253-
let timerHandleForRecompilation: number; // Handle for 0.25s wait timer to trigger recompilation
254-
let timerHandleForDirectoryChanges: number; // Handle for 0.25s wait timer to trigger directory change handler
253+
let timerHandleForRecompilation: any; // Handle for 0.25s wait timer to trigger recompilation
254+
let timerHandleForDirectoryChanges: any; // Handle for 0.25s wait timer to trigger directory change handler
255255

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

505505
function startTimerForHandlingDirectoryChanges() {
506+
if (!sys.setTimeout || !sys.clearTimeout) {
507+
return;
508+
}
509+
506510
if (timerHandleForDirectoryChanges) {
507-
clearTimeout(timerHandleForDirectoryChanges);
511+
sys.clearTimeout(timerHandleForDirectoryChanges);
508512
}
509-
timerHandleForDirectoryChanges = setTimeout(directoryChangeHandler, 250);
513+
timerHandleForDirectoryChanges = sys.setTimeout(directoryChangeHandler, 250);
510514
}
511515

512516
function directoryChangeHandler() {
@@ -525,10 +529,14 @@ namespace ts {
525529
// operations (such as saving all modified files in an editor) a chance to complete before we kick
526530
// off a new compilation.
527531
function startTimerForRecompilation() {
532+
if (!sys.setTimeout || !sys.clearTimeout) {
533+
return;
534+
}
535+
528536
if (timerHandleForRecompilation) {
529-
clearTimeout(timerHandleForRecompilation);
537+
sys.clearTimeout(timerHandleForRecompilation);
530538
}
531-
timerHandleForRecompilation = setTimeout(recompile, 250);
539+
timerHandleForRecompilation = sys.setTimeout(recompile, 250);
532540
}
533541

534542
function recompile() {

0 commit comments

Comments
 (0)