Skip to content
Permalink
Browse files

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
  • Loading branch information
kyliau authored and mhevery committed Nov 28, 2019
1 parent 29de8d3 commit 7a7e999fb512354a98a70355c7f95fa59e0cdc5d
Showing with 4 additions and 11 deletions.
  1. +4 −11 packages/language-service/src/diagnostics.ts
@@ -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 [];
}

0 comments on commit 7a7e999

Please sign in to comment.
You can’t perform that action at this time.