fix(language-service): use host.error() instead of console.error() (#34114)

`host.error()` would log to file, and makes error messages much easier
to inspect because entries are time-stamped.

PR Close #34114
This commit is contained in:
Keen Yee Liau 2019-11-27 16:03:20 -08:00 committed by Miško Hevery
parent 39722df41e
commit 99320e1ffc
1 changed files with 4 additions and 11 deletions

View File

@ -53,13 +53,6 @@ function missingDirective(name: string, isComponent: boolean) {
'available inside a template. Consider adding it to a NgModule declaration.';
}
/**
* Logs an error for an impossible state with a certain message.
*/
function logImpossibleState(message: string) {
console.error(`Impossible state: ${message}`);
}
/**
* Performs a variety diagnostics on directive declarations.
*
@ -85,14 +78,14 @@ export function getDeclarationDiagnostics(
const sf = host.getSourceFile(type.filePath);
if (!sf) {
logImpossibleState(`directive ${type.name} exists but has no source file`);
host.error(`directive ${type.name} exists but has no source file`);
return [];
}
// TypeScript identifier of the directive declaration annotation (e.g. "Component" or
// "Directive") on a directive class.
const directiveIdentifier = findTightestNode(sf, declarationSpan.start);
if (!directiveIdentifier) {
logImpossibleState(`directive ${type.name} exists but has no identifier`);
host.error(`directive ${type.name} exists but has no identifier`);
return [];
}
@ -138,7 +131,7 @@ export function getDeclarationDiagnostics(
const templateUrlNode = findPropertyValueOfType(
directiveIdentifier.parent, 'templateUrl', ts.isLiteralExpression);
if (!templateUrlNode) {
logImpossibleState(`templateUrl ${templateUrl} exists but its TypeScript node doesn't`);
host.error(`templateUrl ${templateUrl} exists but its TypeScript node doesn't`);
return [];
}
@ -151,7 +144,7 @@ export function getDeclarationDiagnostics(
const styleUrlsNode = findPropertyValueOfType(
directiveIdentifier.parent, 'styleUrls', ts.isArrayLiteralExpression);
if (!styleUrlsNode) {
logImpossibleState(`styleUrls property exists but its TypeScript node doesn't'`);
host.error(`styleUrls property exists but its TypeScript node doesn't'`);
return [];
}