Open saghul opened 8 years ago
Babel standalone: https://github.com/Daniel15/babel-standalone
I have this in minisphere for CoffeeScript and TypeScript. If you give it code in either language it transpiles it to JS on the spot by running the correct transpiler script.
See function transpile_to_js()
here:
https://github.com/fatcerberus/minisphere/blob/master/src/engine/transpile.c
It's quite useful because you can skip the build step when testing non-JS code.
:heart:
One important caveat with TypeScript: ts.transpile()
just does a blind conversion without any syntax checking or even type verification. It will never throw an error, will allow you to do stupid things like assigning a string to a number variable, and the transpiled code may be invalid. It's good enough as a starting point, though.
Proper TypeScript support requires implementing a CompilerHost, which I was too lazy to do. :-P
Thanks for the heads up!
Potentially interesting alternative to babel: https://buble.surge.sh/guide/
Investigate introducing builtin transpilers. It would work with a command line flag, which loads the code into the transpiler:
Transpilers: babel and typescript.
Reference: https://github.com/amol-/dukpy