Remix.run Logo
Josh – Standalone JavaScript to pure sh transpiler/interpreter(gist.github.com)
1 points by gaigalas 8 hours ago | 1 comments
gaigalas 8 hours ago | parent [-]

Olá!

This gist is the prototype for josh, a comprehensive (but not complete) JavaScript interpreter that works as a JS-to-sh transpiler.

Here is an example JS program that it is able to run:

https://gist.github.com/alganet/9bdb3be7212e3c2f96cff17984fe...

Some features are intentionally missing, such as try/catch and spreading.

The code is a 2.2KLOC standalone portable shell script (bash, dash, zsh, ksh, busybox, mksh and possibly others) with zero external dependencies (no sed, awk, cat, anything).

It was bundled from modules from the same shell script language toolkit that I previously used to develop c89cc.sh (the pure portable shell c89 compiler). This time, the parser is hand-written, which makes it much smaller and readable.

This is a research endeavour, with potential applications in JS setup and automation tools (replacing the need for a full nodejs in setup scripts and so on).