fix(language-service): do not return external template that does not … · angular/angular@6b6fcd7

File tree

2 files changed

lines changed

  • packages/language-service

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -29,8 +29,16 @@ export function getExternalFiles(project: tss.server.Project): string[] {

2929

return [];

3030

}

3131

const ngLsHost = PROJECT_MAP.get(project);

32-

ngLsHost?.getAnalyzedModules();

33-

return ngLsHost?.getExternalTemplates() || [];

32+

if (ngLsHost === undefined) {

33+

return [];

34+

}

35+

ngLsHost.getAnalyzedModules();

36+

return ngLsHost.getExternalTemplates().filter(fileName => {

37+

// TODO(kyliau): Remove this when the following PR lands on the version of

38+

// TypeScript used in this repo.

39+

// https://github.com/microsoft/TypeScript/pull/41737

40+

return project.fileExists(fileName);

41+

});

3442

}

3543
3644

export function create(info: tss.server.PluginCreateInfo): tss.LanguageService {

Original file line numberDiff line numberDiff line change

@@ -21,6 +21,7 @@ const mockProject = {

2121

},

2222

},

2323

hasRoots: () => true,

24+

fileExists: () => true,

2425

} as any;

2526
2627

describe('plugin', () => {

@@ -136,6 +137,12 @@ describe('plugin', () => {

136137

'/app/test.ng',

137138

]);

138139

});

140+
141+

it('should not return external template that does not exist', () => {

142+

spyOn(mockProject, 'fileExists').and.returnValue(false);

143+

const externalTemplates = getExternalFiles(mockProject);

144+

expect(externalTemplates.length).toBe(0);

145+

});

139146

});

140147
141148

describe(`with config 'angularOnly = true`, () => {