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

fix: error when declaration enabled #86

Merged
merged 1 commit into from
Jul 2, 2017
Merged
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: 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);
});
});