fix(41736): tsserver should not crash if external file does not exist (#41737)

If a file does not exist, `projectService.getOrCreateScriptInfoNotOpenedByClient()`
will return `undefined`, but tsserver does not handle this case.

Fix https://github.com/microsoft/TypeScript/issues/41736
This commit is contained in:
Keen Yee Liau
2020-11-30 16:37:40 -08:00
committed by GitHub
parent 0c76803854
commit cf4df4e472
2 changed files with 41 additions and 2 deletions

View File

@@ -1188,8 +1188,8 @@ namespace ts.server {
// by the host for files in the program when the program is retrieved above but
// the program doesn't contain external files so this must be done explicitly.
inserted => {
const scriptInfo = this.projectService.getOrCreateScriptInfoNotOpenedByClient(inserted, this.currentDirectory, this.directoryStructureHost)!;
scriptInfo.attachToProject(this);
const scriptInfo = this.projectService.getOrCreateScriptInfoNotOpenedByClient(inserted, this.currentDirectory, this.directoryStructureHost);
scriptInfo?.attachToProject(this);
},
removed => this.detachScriptInfoFromProject(removed)
);