Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ? `Line ${d.file.getLineAndCharacterOfPosition(d.start).line}: ${message}`
: message;
}).join(os.EOL);
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -65,22 +65,22 @@ 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./);

});

it('throws an error for ES2016 Array#includes', 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'./);
});
});

Expand Down Expand Up @@ -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 = "/// <reference path='./typings/tsd'/>" + eol
+ "var x: number = 'some string';";
Expand All @@ -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./);
});
});

Expand Down