Skip to content

Commit c5ed864

Browse files
committed
Add test where emit of the file results in invalidating resolution and hence invoking recompile
1 parent 658de7f commit c5ed864

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/compiler/watch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace ts {
2020
// Callbacks to do custom action before creating program and after creating program
2121
beforeCompile(compilerOptions: CompilerOptions): void;
2222
afterCompile(host: DirectoryStructureHost, program: Program, builder: Builder): void;
23+
24+
// Only for testing
25+
maxNumberOfFilesToIterateForInvalidation?: number;
2326
}
2427

2528
const defaultFormatDiagnosticsHost: FormatDiagnosticsHost = sys ? {
@@ -301,6 +304,7 @@ namespace ts {
301304
hasChangedAutomaticTypeDirectiveNames = true;
302305
scheduleProgramUpdate();
303306
},
307+
maxNumberOfFilesToIterateForInvalidation: watchingHost.maxNumberOfFilesToIterateForInvalidation,
304308
writeLog
305309
};
306310
// Cache for the module resolution

src/harness/unittests/tscWatchMode.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ namespace ts.tscWatch {
3030
return ts.parseConfigFile(configFileName, {}, watchingSystemHost.system, watchingSystemHost.reportDiagnostic, watchingSystemHost.reportWatchDiagnostic);
3131
}
3232

33-
function createWatchModeWithConfigFile(configFilePath: string, host: WatchedSystem) {
33+
function createWatchModeWithConfigFile(configFilePath: string, host: WatchedSystem, maxNumberOfFilesToIterateForInvalidation?: number) {
3434
const watchingSystemHost = createWatchingSystemHost(host);
35+
watchingSystemHost.maxNumberOfFilesToIterateForInvalidation = maxNumberOfFilesToIterateForInvalidation;
3536
const configFileResult = parseConfigFile(configFilePath, watchingSystemHost);
3637
return ts.createWatchModeWithConfigFile(configFileResult, {}, watchingSystemHost);
3738
}
@@ -1067,6 +1068,36 @@ namespace ts.tscWatch {
10671068
assert.equal(nowErrors[0].start, intialErrors[0].start - configFileContentComment.length);
10681069
assert.equal(nowErrors[1].start, intialErrors[1].start - configFileContentComment.length);
10691070
});
1071+
1072+
it("should not trigger recompilation because of program emit", () => {
1073+
const proj = "/user/username/projects/myproject";
1074+
const file1: FileOrFolder = {
1075+
path: `${proj}/file1.ts`,
1076+
content: "export const c = 30;"
1077+
};
1078+
const file2: FileOrFolder = {
1079+
path: `${proj}/src/file2.ts`,
1080+
content: `import {c} from "file1"; export const d = 30;`
1081+
};
1082+
const tsconfig: FileOrFolder = {
1083+
path: `${proj}/tsconfig.json`,
1084+
content: JSON.stringify({
1085+
compilerOptions: {
1086+
module: "amd",
1087+
outDir: "build"
1088+
}
1089+
})
1090+
};
1091+
const host = createWatchedSystem([file1, file2, libFile, tsconfig], { currentDirectory: proj });
1092+
const watch = createWatchModeWithConfigFile(tsconfig.path, host, /*maxNumberOfFilesToIterateForInvalidation*/1);
1093+
checkProgramActualFiles(watch(), [file1.path, file2.path, libFile.path]);
1094+
1095+
assert.isTrue(host.fileExists("build/file1.js"));
1096+
assert.isTrue(host.fileExists("build/src/file2.js"));
1097+
1098+
// This should be 0
1099+
host.checkTimeoutQueueLengthAndRun(1);
1100+
});
10701101
});
10711102

10721103
describe("tsc-watch emit with outFile or out setting", () => {

0 commit comments

Comments
 (0)