diff --git a/src/compiler/tsbuildPublic.ts b/src/compiler/tsbuildPublic.ts index f11204155c60a..f4baf9145f8b5 100644 --- a/src/compiler/tsbuildPublic.ts +++ b/src/compiler/tsbuildPublic.ts @@ -1811,7 +1811,7 @@ function getUpToDateStatusWorker(state: SolutionBuilderState, project: ParsedCom if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(buildInfoProgram, buildInfoPath!, host); version = buildInfoVersionMap.get(toPath(state, inputFile)); const text = version ? state.readFileWithCache(inputFile) : undefined; - currentVersion = text && getSourceFileVersionAsHashFromText(host, text); + currentVersion = text !== undefined ? getSourceFileVersionAsHashFromText(host, text) : undefined; if (version && version === currentVersion) pseudoInputUpToDate = true; } diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 265f0b6a629aa..e386f748beac6 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -715,7 +715,7 @@ export function createWatchProgram(host: WatchCompiler if (hostSourceFile.version) return hostSourceFile.version; // Read file and get new version const text = readFileWithCache(path); - return text ? getSourceFileVersionAsHashFromText(compilerHost, text) : undefined; + return text !== undefined ? getSourceFileVersionAsHashFromText(compilerHost, text) : undefined; } function onReleaseOldSourceFile(oldSourceFile: SourceFile, _oldOptions: CompilerOptions, hasSourceFileByPath: boolean) { diff --git a/src/testRunner/unittests/tscWatch/watchEnvironment.ts b/src/testRunner/unittests/tscWatch/watchEnvironment.ts index 7659fff6a8130..58af0b242b02e 100644 --- a/src/testRunner/unittests/tscWatch/watchEnvironment.ts +++ b/src/testRunner/unittests/tscWatch/watchEnvironment.ts @@ -717,6 +717,16 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po change: sys => sys.replaceFileText("/user/username/projects/project/main.ts", "Hello", "Hello World"), timeouts: sys => sys.runQueuedTimeoutCallbacks(), }, + { + caption: "receive another change event without modifying the file", + change: sys => sys.invokeFsWatches("/user/username/projects/project/main.ts", "change", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined), + timeouts: sys => sys.runQueuedTimeoutCallbacks(), + }, + { + caption: "change main.ts to empty text", + change: sys => sys.writeFile("/user/username/projects/project/main.ts", ""), + timeouts: sys => sys.runQueuedTimeoutCallbacks(), + }, { caption: "receive another change event without modifying the file", change: sys => sys.invokeFsWatches("/user/username/projects/project/main.ts", "change", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined), diff --git a/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js b/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js index 7f65a4e67bfca..b1d0b494ae270 100644 --- a/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js +++ b/tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js @@ -136,25 +136,11 @@ Output:: >> Screen clear [12:00:36 AM] File change detected. Starting incremental compilation... -[12:00:37 AM] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js' +[12:00:37 AM] Project 'tsconfig.json' is up to date but needs to update timestamps of output files that are older than input files -[12:00:38 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:38 AM] Found 0 errors. Watching for file changes. -[12:00:39 AM] Found 0 errors. Watching for file changes. - - - -Program root files: ["/user/username/projects/myproject/a.js","/user/username/projects/myproject/b.ts"] -Program options: {"allowJs":true,"noEmit":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} -Program structureReused: Not -Program files:: -/a/lib/lib.d.ts -/user/username/projects/myproject/a.js -/user/username/projects/myproject/b.ts - -Semantic diagnostics in builder refreshed for:: -No shapes updated in the builder:: PolledWatches:: @@ -182,13 +168,13 @@ const x = 10; Output:: >> Screen clear -[12:00:43 AM] File change detected. Starting incremental compilation... +[12:00:42 AM] File change detected. Starting incremental compilation... -[12:00:44 AM] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js' +[12:00:43 AM] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js' -[12:00:45 AM] Building project '/user/username/projects/myproject/tsconfig.json'... +[12:00:44 AM] Building project '/user/username/projects/myproject/tsconfig.json'... -[12:00:53 AM] Found 0 errors. Watching for file changes. +[12:00:52 AM] Found 0 errors. Watching for file changes. diff --git a/tests/baselines/reference/tscWatch/watchEnvironment/fsEvent-for-change-is-repeated.js b/tests/baselines/reference/tscWatch/watchEnvironment/fsEvent-for-change-is-repeated.js index 30542faf47a4a..777e659658064 100644 --- a/tests/baselines/reference/tscWatch/watchEnvironment/fsEvent-for-change-is-repeated.js +++ b/tests/baselines/reference/tscWatch/watchEnvironment/fsEvent-for-change-is-repeated.js @@ -121,6 +121,84 @@ var a = "Hello World"; +Change:: receive another change event without modifying the file + +Input:: + +Output:: +FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file +Scheduling update +Elapsed:: *ms FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file +Synchronizing program + + +PolledWatches:: +/user/username/projects/project/node_modules/@types: + {"pollingInterval":500} + +FsWatches:: +/user/username/projects/project/main.ts: + {} +/a/lib/lib.d.ts: + {} + +FsWatchesRecursive:: + +exitCode:: ExitStatus.undefined + + +Change:: change main.ts to empty text + +Input:: +//// [/user/username/projects/project/main.ts] + + + +Output:: +FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file +Scheduling update +Elapsed:: *ms FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file +Synchronizing program +[12:00:34 AM] File change detected. Starting incremental compilation... + +CreatingProgramWith:: + roots: ["main.ts"] + options: {"watch":true,"extendedDiagnostics":true} +[12:00:38 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["main.ts"] +Program options: {"watch":true,"extendedDiagnostics":true} +Program structureReused: Completely +Program files:: +/a/lib/lib.d.ts +main.ts + +Semantic diagnostics in builder refreshed for:: +main.ts + +Shape signatures in builder refreshed for:: +/user/username/projects/project/main.ts (used version) + +PolledWatches:: +/user/username/projects/project/node_modules/@types: + {"pollingInterval":500} + +FsWatches:: +/user/username/projects/project/main.ts: + {} +/a/lib/lib.d.ts: + {} + +FsWatchesRecursive:: + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/project/main.js] + + + Change:: receive another change event without modifying the file Input::