Skip to content

Commit 2f7c578

Browse files
committed
Check if diagnostic.file is defined in NormalizedMessage.createFromDiagnostic
1 parent b53a7d5 commit 2f7c578

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/NormalizedMessage.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,24 @@ class NormalizedMessage {
4444
// message types
4545
static createFromDiagnostic(diagnostic: tsTypes.Diagnostic) {
4646
const ts: typeof tsTypes = require('typescript');
47-
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
47+
let file: string;
48+
let line: number;
49+
let character: number;
50+
if (diagnostic.file) {
51+
file = diagnostic.file.fileName;
52+
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
53+
line = position.line + 1;
54+
character = position.character + 1;
55+
}
4856

4957
return new NormalizedMessage({
5058
type: NormalizedMessage.TYPE_DIAGNOSTIC,
5159
code: diagnostic.code,
5260
severity: ts.DiagnosticCategory[diagnostic.category].toLowerCase() as Severity,
5361
content: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
54-
file: diagnostic.file.fileName,
55-
line: position.line + 1,
56-
character: position.character + 1
62+
file: file,
63+
line: line,
64+
character: character
5765
});
5866
}
5967

0 commit comments

Comments
 (0)