From 72adc86224512433436fa46feb139260e71a3f37 Mon Sep 17 00:00:00 2001 From: Tycho Grouwstra Date: Tue, 13 Dec 2016 03:28:28 +0800 Subject: [PATCH] fix(diagnostics): fix null pointers --- src/highlight/highlight.ts | 2 +- src/logger/logger-diagnostics.ts | 2 +- src/logger/logger-typescript.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/highlight/highlight.ts b/src/highlight/highlight.ts index 90c22b2c..5427f81f 100644 --- a/src/highlight/highlight.ts +++ b/src/highlight/highlight.ts @@ -154,7 +154,7 @@ function compileLanguage(language: any) { export function highlightError(htmlInput: string, errorCharStart: number, errorLength: number) { - if (errorCharStart < 0 || errorLength < 1) return htmlInput; + if (errorCharStart < 0 || errorLength < 1 || htmlInput == undefined) return htmlInput; const chars = htmlInput.split(''); let inTag = false; diff --git a/src/logger/logger-diagnostics.ts b/src/logger/logger-diagnostics.ts index e6290572..72f82711 100644 --- a/src/logger/logger-diagnostics.ts +++ b/src/logger/logger-diagnostics.ts @@ -334,7 +334,7 @@ function eachLineHasLeadingWhitespace(lines: PrintLine[], code: 'text'|'html') { return false; } for (var i = 0; i < lines.length; i++) { - if ((lines[i])[code].length < 1) { + if (lines[i][code] == undefined || (lines[i])[code].length < 1) { return false; } var firstChar = (lines[i])[code].charAt(0); diff --git a/src/logger/logger-typescript.ts b/src/logger/logger-typescript.ts index cd513b1a..79c92da7 100644 --- a/src/logger/logger-typescript.ts +++ b/src/logger/logger-typescript.ts @@ -53,7 +53,7 @@ function loadDiagnostic(context: BuildContext, tsDiagnostic: ts.Diagnostic) { errorLength: Math.max(tsDiagnostic.length, 1) }; - if (errorLine.html.indexOf('class="hljs') === -1) { + if (errorLine.html && errorLine.html.indexOf('class="hljs') === -1) { try { errorLine.html = highlight(d.language, errorLine.text, true).value; } catch (e) {} @@ -78,7 +78,7 @@ function loadDiagnostic(context: BuildContext, tsDiagnostic: ts.Diagnostic) { errorLength: -1 }; - if (previousLine.html.indexOf('class="hljs') === -1) { + if (previousLine.html && previousLine.html.indexOf('class="hljs') === -1) { try { previousLine.html = highlight(d.language, previousLine.text, true).value; } catch (e) {} @@ -97,7 +97,7 @@ function loadDiagnostic(context: BuildContext, tsDiagnostic: ts.Diagnostic) { errorLength: -1 }; - if (nextLine.html.indexOf('class="hljs') === -1) { + if (nextLine.html && nextLine.html.indexOf('class="hljs') === -1) { try { nextLine.html = highlight(d.language, nextLine.text, true).value; } catch (e) {}