The node-go2js is a thin node.js layer on top of go2js native parser to generate an Mozilla AST tree with loc parameter that matches the line in the original golang code. It is currently a server-side solution leveraging the native binaries to produce line to line matching to the generated JS code.


Golang is my choice because of its recent trend of popularity and the power of concurrency. It is a challenging problem because Golang is a compiled language with some functional interface.


go2js managed to match go and js code exactly line by line, so it could output a JS AST tree with loc information to be parsed by Aether for the games. It is also able to output some basic syntax errors if the code does not work. I am reusing go2js's binary parser so it is significantly faster than solutions from generated parsers such as peg.js.

Wrap() and Parse() endpoints are supported for Aether integration. For more details, please checkout

Language Support

It is leveraging most of the core golang features mentioned here:

Not yet implemented: Range with index [startOf, endOf] The multiple assignment has different order of preference than in JS (functionInverse in "testdata/func.go" fails due this issue). Evaluation of constants. Shadow variables in JS. Goroutines. Types int64 and complex.


Since we have the line number matchup, it is possible to have loc information in the JS AST tree matching the native Golang code. Since only the information for line is reliable, the column information is generally irrelevant to Aether but the golang compiler error messages can be used directly to report errors on line:column.

Other Work

I have another potential/sub submission here:

that attempts to take erlang to javascript world. The motivation for supporting erlang is that it is the de-facto standard of concurrency and scalability on the web despite its arcanic syntax. In the end, yes, we can build erlang code and pasrse+wrap them to readable js code, but Erlang AST only understands line number by default. We'd need a lot of hack at the OTP core in order to only get Line+Column information out. Indexed Ofs will be another level of hack. I already contacted some core maintainers on OTP and n2o group (creator of shen). They like the idea of Code Combat. There is a patch with range info coming up. Hopefully erlang-js will be a reality down the road.

Built With

Share this project: