Description
TypeScript Version: 3.8.0-dev.20200211
Search Terms:
isProgramUpToDate
getScriptFileNames
Code
Full reproduction:
https://github.com/TypeStrong/ts-node-repros/blob/tsIsProgramUpToDate/example.ts
Output:
https://github.com/TypeStrong/ts-node-repros/blob/tsIsProgramUpToDate/output.txt
Briefly, if I create a languageService
and repeatedly ask it for the Program
, it should return the same program instance each time, provided nothing has changed.
//... create LanguageService using a LanguageServiceHost that does not implement getProjectVersion
assert(languageService.getProgram() === languageService.getProgram())
Expected behavior:
Same Program
instance is returned because isProgramUpToDate()
returns true
.
Actual behavior:
New Program
instance is returned each time because isProgramUpToDate()
always returns false
.
I believe this is the culprit:
https://github.com/microsoft/TypeScript/blob/master/src/compiler/program.ts#L586-L589
It asks HostCache
for the version of all program.getSourceFiles()
.
However, the HostCache
only contains host.getScriptFileNames()
host.getScriptFileNames()
contains only root files, for example, the contents of a src
directory.
program.getSourceFiles()
contains things like typescript/lib/lib.es5.d.ts
As far as I know, host.getScriptFileNames()
must never include typescript/lib/lib*.d.ts
Thus isProgramUpToDate()
is doomed to fail every time, as far as I can tell.
Related Issues: