r/Compilers • • Oct 25 '26

i made a go to javascript transpiler in go

i’ve been working on this for a while and it’s finally at a point where i can show it. it’s called go2js, it takes go code and spits out javascript you can run in node or the browser.

it handles goroutines and channels, generics, defer/panic/recover, multi package projects with go.mod, and a decent chunk of the standard library (fmt, json, time, net/http and some more). there’s also a go2js test command that runs your normal _test.go files.

the way i test it is pretty simple, every test runs the same program once with real go and once as the compiled js, and the output has to match exactly. that’s basically my definition of done.

there’s a playground too, it runs the compiler as wasm in your browser. fair warning it only does the language core, no imports, so no fmt in there.

some honest stuff: it’s v0.1, it’s experimental, goroutines are cooperative so timing won’t match real go, and the generated js is not tiny because the runtime comes along with it. also the readme, comments and most of the tests were written with ai and then edited by me, i put that in the readme so nobody has to guess.

i know gopherjs exists, i’m not claiming this is better, i just wanted to see how far i could push it, and i wanted the output to stay readable.

repo: https://github.com/zenobiatranoss/go2js
playground: https://zenobiatranoss.github.io/go2js/

if you try it on some real code and it breaks, please tell me, that’s the most useful thing right now.

0 Upvotes

12 comments sorted by

7

u/[deleted] Oct 25 '26

[removed] — view removed comment

-7

u/Shoddy-Swim-511 Oct 25 '26

is there any problem with using Claude ?

8

u/[deleted] Oct 25 '26

[removed] — view removed comment

-4

u/Shoddy-Swim-511 Oct 25 '26

you dump the readme already says which parts: most of the tests, and all the comments and docs, were written with ai and lightly edited by me. the design, the decisions and the final say are mine. a contributor name only shows a commit trailer, it doesn’t tell you who did what. and using a tool doesn’t mean nobody worked on it, otherwise nobody who uses an editor, a compiler or a linter wrote their own code. read the readme and the tests, they’re public.

1

u/[deleted] Oct 25 '26

otherwise nobody who uses an editor, a compiler or a linter wrote their own code

Actually I write my own editors, compilers and other tools (as well as using only my own languages!).

But even if I didn't, those would be dumb tools. It would like writing your program on paper, and then giving it to another human to hand-convert into an executable.

What you're doing, IIUC, is like writing some rough specification to hand to that human, who then writes the program for you. You just review the output and refine your spec.

That's fine if the endpoint is simply the product (it probably happens all the time now).

But in this sub a more hands-on approach seems to be favoured. Otherwise you're just advertising a product.

1

u/Shoddy-Swim-511 Oct 26 '26

fair that this sub likes hands-on stuff. but it’s not like that here: only the tests, the code comments and the readme were written with ai, and i said so in the readme. the compiler, the runtime and the design are my own code. it’s all public, read it and tell me which part you think isn’t mine.

5

u/[deleted] Oct 25 '26

[removed] — view removed comment

-4

u/Shoddy-Swim-511 Oct 25 '26

you sound like the skids who only care how code was made, not how it performs. the design and decisions are mine, the code is public, run it and judge.

5

u/[deleted] Oct 25 '26

[removed] — view removed comment

-1

u/Shoddy-Swim-511 Oct 25 '26

call it whatever you want , what matters is it works

-1

u/[deleted] Oct 25 '26

[removed] — view removed comment

1

u/Shoddy-Swim-511 Oct 25 '26

good point, thanks. you’re right that byte for byte only makes sense when the output is deterministic. for the concurrent ones i’ll compare things that don’t depend on order (sorted results, counts, everything finished, channel closed) instead. and the bug report template is a nice idea, i’ll add one asking for the go source, the go output and the js output.