saghul / sjs

Skookum JS: a JavaScript runtime
http://sjs.saghul.net
MIT License
98 stars 13 forks source link

misc: builtin transpilers? #5

Open saghul opened 8 years ago

saghul commented 8 years ago

Investigate introducing builtin transpilers. It would work with a command line flag, which loads the code into the transpiler:

sjs --transpiler=babel code.js

Transpilers: babel and typescript.

Reference: https://github.com/amol-/dukpy

saghul commented 8 years ago

Babel standalone: https://github.com/Daniel15/babel-standalone

fatcerberus commented 8 years ago

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.

saghul commented 8 years ago

:heart:

fatcerberus commented 8 years ago

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

saghul commented 8 years ago

Thanks for the heads up!

saghul commented 8 years ago

Potentially interesting alternative to babel: https://buble.surge.sh/guide/