fix(language-service): Clear caches when program changes (#21337)
This commit fixes a bug whereby the caches are not cleared when the program changes. This subsequently produces the incorrect error of 'Component ... is not included in a module ...'. PR Close #19405 PR Close #21337
This commit is contained in:

committed by
Alex Eagle

parent
2d44a2ab0d
commit
43e1520260
@ -248,7 +248,7 @@ describe('diagnostics', () => {
|
||||
template: \`
|
||||
<div *ngIf="comps | async; let comps; else loading">
|
||||
</div>
|
||||
<ng-template #loading>Loading comps...</ng-template>
|
||||
<ng-template #loading>Loading comps...</ng-template>
|
||||
\`
|
||||
})
|
||||
export class MyComponent {}
|
||||
|
@ -46,4 +46,20 @@ describe('completions', () => {
|
||||
ngHost = new TypeScriptServiceHost(host, service);
|
||||
expect(() => ngHost.getAnalyzedModules()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should clear the caches if program changes', () => {
|
||||
// First create a TypescriptHost with empty script names
|
||||
host = new MockTypescriptHost([], toh);
|
||||
service = ts.createLanguageService(host);
|
||||
ngHost = new TypeScriptServiceHost(host, service);
|
||||
expect(ngHost.getAnalyzedModules().ngModules).toEqual([]);
|
||||
// Now add a script, this would change the program
|
||||
const fileName = '/app/main.ts';
|
||||
const content = (host as MockTypescriptHost).getFileContent(fileName) !;
|
||||
(host as MockTypescriptHost).addScript(fileName, content);
|
||||
// If the caches are not cleared, we would get back an empty array.
|
||||
// But if the caches are cleared then the analyzed modules will be non-empty.
|
||||
expect(ngHost.getAnalyzedModules().ngModules.length).not.toEqual(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user