From d84fde78464528a4de7c68c2f649e3d557e2a6f0 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 26 Apr 2017 18:10:08 +0200 Subject: [PATCH 1/2] Flatten chained error messages --- index.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index c7c8229..1bc5f87 100644 --- a/index.ts +++ b/index.ts @@ -178,7 +178,7 @@ namespace tss { throw new Error(this.formatDiagnostics(allDiagnostics)); } - let outDir = 'outDir' in this.options ? this.options.outDir : ''; + let outDir = this.options.outDir != null ? this.options.outDir : ''; let fileNameWithoutRoot = 'rootDir' in this.options ? fileName.replace(new RegExp('^' + this.options.rootDir), '') : fileName; let outputFileName: string; if (this.options.jsx === ts.JsxEmit.Preserve) { @@ -213,11 +213,9 @@ namespace tss { private formatDiagnostics(diagnostics: ts.Diagnostic[]): string { return diagnostics.map((d) => { - if (d.file) { - return 'L' + d.file.getLineAndCharacterOfPosition(d.start).line + ': ' + d.messageText; - } else { - return d.messageText; - } + const message = ts.flattenDiagnosticMessageText(d.messageText, os.EOL); + return d.file ? 'L' + d.file.getLineAndCharacterOfPosition(d.start).line + ': ' + message + : message; }).join(os.EOL); } } From 94d70047114cfc90377149d0c8a11aca92801d9c Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 25 Apr 2017 19:12:22 +0200 Subject: [PATCH 2/2] Better error output --- index.ts | 2 +- test/test.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index.ts b/index.ts index 1bc5f87..2313aaf 100644 --- a/index.ts +++ b/index.ts @@ -214,7 +214,7 @@ namespace tss { private formatDiagnostics(diagnostics: ts.Diagnostic[]): string { return diagnostics.map((d) => { const message = ts.flattenDiagnosticMessageText(d.messageText, os.EOL); - return d.file ? 'L' + d.file.getLineAndCharacterOfPosition(d.start).line + ': ' + message + return d.file ? `Line ${d.file.getLineAndCharacterOfPosition(d.start).line}: ${message}` : message; }).join(os.EOL); } diff --git a/test/test.js b/test/test.js index a423719..177c071 100644 --- a/test/test.js +++ b/test/test.js @@ -51,7 +51,7 @@ describe('typescript-simple', function() { tss(src); // TypeScript 2.1 bug? // }, /^Error: L0: Type 'string' is not assignable to type 'number'./); - }, /^Error: L0: Type '"str"' is not assignable to type 'number'./); + }, /^Error: Line 0: Type '"str"' is not assignable to type 'number'./); }); it('compiles ES2015 "let" to "var"', function() { @@ -65,7 +65,7 @@ describe('typescript-simple', function() { assert.throws(function() { tss(src); // }, /^Error: L0: Cannot find name 'Promise'./); - }, /^Error: L0: 'Promise' only refers to a type, but is being used as a value here./); + }, /^Error: Line 0: 'Promise' only refers to a type, but is being used as a value here./); }); @@ -73,14 +73,14 @@ describe('typescript-simple', function() { var src = "var x = [1, 2, 3].includes(2);"; assert.throws(function() { tss(src); - }, /^Error: L0: Property 'includes' does not exist on type 'number\[]'./); + }, /^Error: Line 0: Property 'includes' does not exist on type 'number\[]'./); }); it('throws an error for ES2017 Object#values', function() { var src = "var x = Object.values({});"; assert.throws(function() { tss(src); - }, /^Error: L0: Property 'values' does not exist on type 'ObjectConstructor'./); + }, /^Error: Line 0: Property 'values' does not exist on type 'ObjectConstructor'./); }); }); @@ -140,7 +140,7 @@ describe('typescript-simple', function() { var expected = "var x = 'some string';" + eol; assert.equal(tss.compile(src), expected); }); - + it('reference imports are ignored', function() { var src = "/// " + eol + "var x: number = 'some string';"; @@ -153,7 +153,7 @@ describe('typescript-simple', function() { var src = "var x = 123 123;"; assert.throws(function() { tss.compile(src); - }, /^Error: L0: ',' expected./); + }, /^Error: Line 0: ',' expected./); }); });