Skip to content

Commit

Permalink
fix(language-service): use host.error() instead of console.error() (#…
Browse files Browse the repository at this point in the history
…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
Keen Yee Liau authored and mhevery committed Dec 2, 2019
1 parent 29de8d3 commit 7a7e999
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/language-service/src/diagnostics.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ function missingDirective(name: string, isComponent: boolean) {
'available inside a template. Consider adding it to a NgModule declaration.'; '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. * Performs a variety diagnostics on directive declarations.
* *
Expand All @@ -85,14 +78,14 @@ export function getDeclarationDiagnostics(


const sf = host.getSourceFile(type.filePath); const sf = host.getSourceFile(type.filePath);
if (!sf) { if (!sf) {
logImpossibleState(`directive ${type.name} exists but has no source file`); host.error(`directive ${type.name} exists but has no source file`);
return []; return [];
} }
// TypeScript identifier of the directive declaration annotation (e.g. "Component" or // TypeScript identifier of the directive declaration annotation (e.g. "Component" or
// "Directive") on a directive class. // "Directive") on a directive class.
const directiveIdentifier = findTightestNode(sf, declarationSpan.start); const directiveIdentifier = findTightestNode(sf, declarationSpan.start);
if (!directiveIdentifier) { if (!directiveIdentifier) {
logImpossibleState(`directive ${type.name} exists but has no identifier`); host.error(`directive ${type.name} exists but has no identifier`);
return []; return [];
} }


Expand Down Expand Up @@ -138,7 +131,7 @@ export function getDeclarationDiagnostics(
const templateUrlNode = findPropertyValueOfType( const templateUrlNode = findPropertyValueOfType(
directiveIdentifier.parent, 'templateUrl', ts.isLiteralExpression); directiveIdentifier.parent, 'templateUrl', ts.isLiteralExpression);
if (!templateUrlNode) { if (!templateUrlNode) {
logImpossibleState(`templateUrl ${templateUrl} exists but its TypeScript node doesn't`); host.error(`templateUrl ${templateUrl} exists but its TypeScript node doesn't`);
return []; return [];
} }


Expand All @@ -151,7 +144,7 @@ export function getDeclarationDiagnostics(
const styleUrlsNode = findPropertyValueOfType( const styleUrlsNode = findPropertyValueOfType(
directiveIdentifier.parent, 'styleUrls', ts.isArrayLiteralExpression); directiveIdentifier.parent, 'styleUrls', ts.isArrayLiteralExpression);
if (!styleUrlsNode) { if (!styleUrlsNode) {
logImpossibleState(`styleUrls property exists but its TypeScript node doesn't'`); host.error(`styleUrls property exists but its TypeScript node doesn't'`);
return []; return [];
} }


Expand Down

0 comments on commit 7a7e999

Please sign in to comment.