diff --git a/index.ts b/index.ts index 7db70a4..682b5f5 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,7 @@ import fs = require('fs'); import os = require('os'); import path = require('path'); +import assert = require('assert'); import ts = require('typescript'); @@ -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 { diff --git a/test/test.js b/test/test.js index 5fd883a..39d6011 100644 --- a/test/test.js +++ b/test/test.js @@ -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); + }); });