mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
Handle empty string when getting file version (#51689)
* Test for empty string change * Fix empty string for file versioning
This commit is contained in:
parent
86019fa470
commit
16edc29bc9
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -715,7 +715,7 @@ export function createWatchProgram<T extends BuilderProgram>(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) {
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -136,26 +136,12 @@ Output::
|
||||
>> Screen clear
|
||||
[[90m12:00:36 AM[0m] File change detected. Starting incremental compilation...
|
||||
|
||||
[[90m12:00:37 AM[0m] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js'
|
||||
[[90m12:00:37 AM[0m] Project 'tsconfig.json' is up to date but needs to update timestamps of output files that are older than input files
|
||||
|
||||
[[90m12:00:38 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
|
||||
|
||||
[[90m12:00:39 AM[0m] Found 0 errors. Watching for file changes.
|
||||
[[90m12:00:38 AM[0m] 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::
|
||||
|
||||
FsWatches::
|
||||
@ -182,13 +168,13 @@ const x = 10;
|
||||
|
||||
Output::
|
||||
>> Screen clear
|
||||
[[90m12:00:43 AM[0m] File change detected. Starting incremental compilation...
|
||||
[[90m12:00:42 AM[0m] File change detected. Starting incremental compilation...
|
||||
|
||||
[[90m12:00:44 AM[0m] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js'
|
||||
[[90m12:00:43 AM[0m] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js'
|
||||
|
||||
[[90m12:00:45 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
|
||||
[[90m12:00:44 AM[0m] Building project '/user/username/projects/myproject/tsconfig.json'...
|
||||
|
||||
[[90m12:00:53 AM[0m] Found 0 errors. Watching for file changes.
|
||||
[[90m12:00:52 AM[0m] Found 0 errors. Watching for file changes.
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
[[90m12:00:34 AM[0m] File change detected. Starting incremental compilation...
|
||||
|
||||
CreatingProgramWith::
|
||||
roots: ["main.ts"]
|
||||
options: {"watch":true,"extendedDiagnostics":true}
|
||||
[[90m12:00:38 AM[0m] 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::
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user