Skip to content

isProgramUpToDate reports false because it expects HostCache to include typescript/lib/*.d.ts files #36748

Closed
@cspotcode

Description

@cspotcode

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:

#36010

Metadata

Metadata

Assignees

Labels

APIRelates to the public API for TypeScriptBugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions