Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 72adc86

Browse files
KiaraGrouwstradanbucholtz
authored andcommitted
fix(diagnostics): fix null pointers
1 parent b6c12f5 commit 72adc86

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/highlight/highlight.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function compileLanguage(language: any) {
154154

155155

156156
export function highlightError(htmlInput: string, errorCharStart: number, errorLength: number) {
157-
if (errorCharStart < 0 || errorLength < 1) return htmlInput;
157+
if (errorCharStart < 0 || errorLength < 1 || htmlInput == undefined) return htmlInput;
158158

159159
const chars = htmlInput.split('');
160160
let inTag = false;

src/logger/logger-diagnostics.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ function eachLineHasLeadingWhitespace(lines: PrintLine[], code: 'text'|'html') {
334334
return false;
335335
}
336336
for (var i = 0; i < lines.length; i++) {
337-
if ((<any>lines[i])[code].length < 1) {
337+
if (lines[i][code] == undefined || (<any>lines[i])[code].length < 1) {
338338
return false;
339339
}
340340
var firstChar = (<any>lines[i])[code].charAt(0);

src/logger/logger-typescript.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function loadDiagnostic(context: BuildContext, tsDiagnostic: ts.Diagnostic) {
5353
errorLength: Math.max(tsDiagnostic.length, 1)
5454
};
5555

56-
if (errorLine.html.indexOf('class="hljs') === -1) {
56+
if (errorLine.html && errorLine.html.indexOf('class="hljs') === -1) {
5757
try {
5858
errorLine.html = highlight(d.language, errorLine.text, true).value;
5959
} catch (e) {}
@@ -78,7 +78,7 @@ function loadDiagnostic(context: BuildContext, tsDiagnostic: ts.Diagnostic) {
7878
errorLength: -1
7979
};
8080

81-
if (previousLine.html.indexOf('class="hljs') === -1) {
81+
if (previousLine.html && previousLine.html.indexOf('class="hljs') === -1) {
8282
try {
8383
previousLine.html = highlight(d.language, previousLine.text, true).value;
8484
} catch (e) {}
@@ -97,7 +97,7 @@ function loadDiagnostic(context: BuildContext, tsDiagnostic: ts.Diagnostic) {
9797
errorLength: -1
9898
};
9999

100-
if (nextLine.html.indexOf('class="hljs') === -1) {
100+
if (nextLine.html && nextLine.html.indexOf('class="hljs') === -1) {
101101
try {
102102
nextLine.html = highlight(d.language, nextLine.text, true).value;
103103
} catch (e) {}

0 commit comments

Comments
 (0)