Get typed AST from Rescript file

I believe I want to do the reverse of How do I extract the rescript AST?

I have a Rescript file and I want to inspect the (typed) AST of a file.
How can I do this? I don’t really know any ocaml, so if I can just dump something to json that would be ideal. But if that is not possible, some ocaml pointers would do as well.

Getting the typed AST isn’t possible without OCaml, but there are some loose plans to expose a subset of the relevant parts of the typed AST as JSON via the @rescript/tools package.

A hack, but what you can try today is running the doc command from @rescript/tools on your file: rescript-vscode/tools/ at master · rescript-lang/rescript-vscode · GitHub

That will dump out JSON using the typed AST for that file. It’s intended for driving doc generation, but you might find what you need in there already.

Thanks! That would be something like npx rescript-tools doc src/CreateOrder.res right?
This isn’t doing anything right now, so I probably missing something?

I installed sudo apt install musl and this started working.
That json does (more or less) contain what I need.
Thanks a bunch @zth!

Related shower thought: maybe producing some web assembly binary (assuming that is easy in OCAML) that exposes this could be an interesting route to explore.