1

I'd love to have a function somewhere in my code that takes a typescript string as argument, and outputs javascript string on return. I'm thinking about wiring tsc compiler onto V8 provided by ClearScript, but that thing isn't very well documented, and I guess I'm looking for a shortcut in a form of a nuget package. Any advice?

Gleno
  • 15,466
  • 11
  • 59
  • 81

1 Answers1

1

The typescript compiler is simply a command line executable, tsc.exe. You could accomplish this by doing the following:

// write text to temporary .ts file ...

var startInfo = new ProcessStartInfo {;
    FileName = "\path\to\tsc.exe",
    Arguments = args   // parameters to pass to tsc, including .ts
};
Process.Start(startInfo);

// read text from newly created .js file
Andy W
  • 209
  • 1
  • 9
  • This would be acceptable, however since I already am using V8 for other things in my app, it seems less intrusive to let the javascript version of the compiler process the source file. – Gleno Oct 26 '13 at 20:19
  • There is another question and answer here that attempts to do that: [http://stackoverflow.com/q/19023498/704628]. The answer isn't complete in that case, but you may find it helpful. You can also look at the typescript playground site, [http://www.typescriptlang.org/playground/] which compiles ts code to js in a live page. Looking at the source of that page, there is a comment that says "Compilation logic" - it looks like the getEmitOutput is the method that does the work. – Andy W Oct 29 '13 at 07:04