(function() {
  'use strict';
  var ts = require('typescript-api');
  var compiler = new ts.TypeScriptCompiler();

  /**
   * Compile a string of TypeScript, return as a string of JavaScript
   *
   * @param {String} input - TypeScript to compile
   * @return {String} JavaScript output, or null on error
   */
  exports.compile = function(input) {
    var snapshot = ts.ScriptSnapshot.fromString(input);
    compiler.addFile('debugger.ts', snapshot);

    var it = compiler.compile();
    it.moveNext();

    var output = it.current().outputFiles[0];
    return !!output ? output.text : null;
  };

})();

@@ -23,16 +23,17 @@
 trict';%0A
+%0A
   var ts
@@ -72,46 +72,34 @@
 var 
-compiler = new ts.TypeScriptCompiler()
+filename = 'typestring.ts'
 ;%0A%0A 
@@ -272,20 +272,40 @@
 tput
-, or null on
+%0A   * @throws TypeScript compile
  err
@@ -351,16 +351,65 @@
 nput) %7B%0A
+    var compiler = new ts.TypeScriptCompiler();%0A%0A
     var 
@@ -481,21 +481,16 @@
 ile(
-'debugger.ts'
+filename
 , sn
@@ -509,16 +509,18 @@
   var it
+er
  = compi
@@ -540,16 +540,18 @@
 ;%0A    it
+er
 .moveNex
@@ -552,24 +552,172 @@
 oveNext();%0A%0A
+    var diagnostics = compiler.getSemanticDiagnostics(filename);%0A    if (diagnostics.length) %7B%0A      throw new Error(diagnostics%5B0%5D.text());%0A    %7D%0A%0A
     var outp
@@ -723,16 +723,18 @@
 put = it
+er
 .current
@@ -792,12 +792,10 @@
 t : 
-null
+''
 ;%0A  

Throw on TypeScript compile error