Skip to content

Commit 99320e1

Browse files
Keen Yee Liaumhevery
authored andcommitted
fix(language-service): use host.error() instead of console.error() (angular#34114)
`host.error()` would log to file, and makes error messages much easier to inspect because entries are time-stamped. PR Close angular#34114
1 parent 39722df commit 99320e1

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

packages/language-service/src/diagnostics.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ function missingDirective(name: string, isComponent: boolean) {
5353
'available inside a template. Consider adding it to a NgModule declaration.';
5454
}
5555

56-
/**
57-
* Logs an error for an impossible state with a certain message.
58-
*/
59-
function logImpossibleState(message: string) {
60-
console.error(`Impossible state: ${message}`);
61-
}
62-
6356
/**
6457
* Performs a variety diagnostics on directive declarations.
6558
*
@@ -85,14 +78,14 @@ export function getDeclarationDiagnostics(
8578

8679
const sf = host.getSourceFile(type.filePath);
8780
if (!sf) {
88-
logImpossibleState(`directive ${type.name} exists but has no source file`);
81+
host.error(`directive ${type.name} exists but has no source file`);
8982
return [];
9083
}
9184
// TypeScript identifier of the directive declaration annotation (e.g. "Component" or
9285
// "Directive") on a directive class.
9386
const directiveIdentifier = findTightestNode(sf, declarationSpan.start);
9487
if (!directiveIdentifier) {
95-
logImpossibleState(`directive ${type.name} exists but has no identifier`);
88+
host.error(`directive ${type.name} exists but has no identifier`);
9689
return [];
9790
}
9891

@@ -138,7 +131,7 @@ export function getDeclarationDiagnostics(
138131
const templateUrlNode = findPropertyValueOfType(
139132
directiveIdentifier.parent, 'templateUrl', ts.isLiteralExpression);
140133
if (!templateUrlNode) {
141-
logImpossibleState(`templateUrl ${templateUrl} exists but its TypeScript node doesn't`);
134+
host.error(`templateUrl ${templateUrl} exists but its TypeScript node doesn't`);
142135
return [];
143136
}
144137

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

0 commit comments

Comments
 (0)