Skip to content

script info for external project could be undefined #41736

@kyliau

Description

@kyliau

Angular language service (View Engine version) uses getExternalFiles() to add html templates to the ConfiguredProject. For each file, tsserver will get or create a script info, and attach it to the project.
However, if the file does not exist on disk, no script info will be created, but tsserver does not handle this case.

Specifically,scriptInfo returned by this.projectService.getOrCreateScriptInfoNotOpenedByClient() could be undefined.

TypeScript Version: 4.2.0-dev.20201130

Search Terms:
external file, script info, tsserver

Code
Note the unsafe non-null assertion at the end of line 1191:

inserted => {
const scriptInfo = this.projectService.getOrCreateScriptInfoNotOpenedByClient(inserted, this.currentDirectory, this.directoryStructureHost)!;
scriptInfo.attachToProject(this);
},

Expected behavior:
tsserver does not crash if script info for external file could not be created.

Actual behavior:
tsserver crashes when script info for external file could not be created.

Related Issues:
angular/vscode-ng-language-service#1001

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions