feat(language-service): provide diagnostic for invalid templateUrls (#32586)

`templateUrls` that do not point to actual files are now diagnosed as such
by the Language Service. Support for `styleUrls` will come in a next PR.

This introduces a utility method `getPropertyValueOfType` that scans
TypeScript ASTs until a property assignment whose initializer of a
certain type is found. This PR also notices a couple of things that
could be improved in the language-service implementation, such as
enumerating directive properties and unifying common logic, that will be
fixed in future PRs.

Part of #32564.

PR Close #32586
This commit is contained in:
ayazhafiz
2019-09-10 10:55:12 -05:00
committed by Kara Erickson
parent 88c28ce208
commit adeee0fa7f
4 changed files with 145 additions and 9 deletions

View File

@ -37,6 +37,7 @@ class LanguageServiceImpl implements LanguageService {
const analyzedModules = this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
const results: Diagnostic[] = [];
const templates = this.host.getTemplates(fileName);
for (const template of templates) {
const astOrDiagnostic = this.host.getTemplateAst(template);
if (isAstResult(astOrDiagnostic)) {
@ -45,10 +46,12 @@ class LanguageServiceImpl implements LanguageService {
results.push(astOrDiagnostic);
}
}
const declarations = this.host.getDeclarations(fileName);
if (declarations && declarations.length) {
results.push(...getDeclarationDiagnostics(declarations, analyzedModules));
results.push(...getDeclarationDiagnostics(declarations, analyzedModules, this.host));
}
const sourceFile = fileName.endsWith('.ts') ? this.host.getSourceFile(fileName) : undefined;
return uniqueBySpan(results).map(d => ngDiagnosticToTsDiagnostic(d, sourceFile));
}