From 99320e1ffca78eefddcf3b944fe85b07662572d5 Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Wed, 27 Nov 2019 16:03:20 -0800 Subject: [PATCH] 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 --- packages/language-service/src/diagnostics.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/language-service/src/diagnostics.ts b/packages/language-service/src/diagnostics.ts index d60b014068..e229bf496f 100644 --- a/packages/language-service/src/diagnostics.ts +++ b/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 []; }