Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

Commit

Permalink
Merge pull request #86 from teppeis/declaration
Browse files Browse the repository at this point in the history
fix: error when declaration enabled
  • Loading branch information
teppeis authored Jul 2, 2017
2 parents 42813fe + 1dacdf6 commit 5c5e9e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 6 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs = require('fs');
import os = require('os');
import path = require('path');
import assert = require('assert');

import ts = require('typescript');

Expand Down Expand Up @@ -171,12 +172,13 @@ namespace tss {
throw new Error(this.formatDiagnostics(allDiagnostics));
}

if (output.outputFiles.length !== 1) {
const names = output.outputFiles.map(_ => _.name);
throw new Error(`Output should be only 1 file, but ${names.length} files: ${names.join(', ')}`);
if (output.outputFiles.length === 0) {
throw new Error('No output files');
}
const file = output.outputFiles[0];
assert(/\.jsx?$/.test(file.name));

return output.outputFiles[0].text;
return file.text;
}

private formatDiagnostics(diagnostics: ts.Diagnostic[]): string {
Expand Down
9 changes: 8 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,17 @@ describe('typescript-simple', function() {
assert.equal(tss.compile(src, path.join('test', 'module.ts')), expected);
});

it('compiles correct source with `types`', function() {
it('compiles source with `types`', function() {
var tss = new TypeScriptSimple({types: ['node']});
var src = "var x: number = 1;";
var expected = 'var x = 1;' + eol;
assert.equal(tss.compile(src), expected);
});

it('compiles source with `declaratoin` enabled', function() {
var tss = new TypeScriptSimple({declaration: true});
var src = "var x: number = 1;";
var expected = 'var x = 1;' + eol;
assert.equal(tss.compile(src), expected);
});
});

0 comments on commit 5c5e9e2

Please sign in to comment.