diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-18 12:18:42 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-18 12:20:59 -0400 |
commit | 8f0e242f4bfb5df1039c2d18516b4de7e1af7745 (patch) | |
tree | f4287389a439f8adf6c0396fb75baab604e9fbbb /runtime.ts | |
parent | 0a46a3e35bd2a960e66345de83877b4bc3144c48 (diff) |
Display diagnostics on TS error.
Diffstat (limited to 'runtime.ts')
-rw-r--r-- | runtime.ts | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/runtime.ts b/runtime.ts index 1e031e7f7..b805259ca 100644 --- a/runtime.ts +++ b/runtime.ts @@ -10,6 +10,8 @@ import * as util from "./util"; import { log } from "./util"; import * as os from "./os"; +const EOL = "\n"; + // This class represents a module. We call it FileModule to make it explicit // that each module represents a single file. // Access to FileModule instances should only be done thru the static method @@ -151,7 +153,12 @@ class Compiler { .concat(this.service.getSyntacticDiagnostics(fileName)) .concat(this.service.getSemanticDiagnostics(fileName)); if (diagnostics.length > 0) { - throw Error("diagnotics"); + const errMsg = ts.formatDiagnosticsWithColorAndContext( + diagnostics, + formatDiagnosticsHost + ); + console.log(errMsg); + os.exit(1); } util.log("compile output", output); @@ -199,7 +206,6 @@ class TypeScriptHost implements ts.LanguageServiceHost { } getNewLine() { - const EOL = "\n"; return EOL; } @@ -242,3 +248,15 @@ class TypeScriptHost implements ts.LanguageServiceHost { }); } } + +const formatDiagnosticsHost: ts.FormatDiagnosticsHost = { + getCurrentDirectory(): string { + return "."; + }, + getCanonicalFileName(fileName: string): string { + return fileName; + }, + getNewLine(): string { + return EOL; + } +}; |