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.
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?
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.
Let’s see if I can find some time to get an initial experimental version out where we can dump typed info to JSON, and we can build on it from there. Easy access to a structured way of working with type info in not just OCaml can hopefully enable some cool innovation.
Yes, for getting AST information.
I was able to solve my use case with the JSON documentation dump.
I needed the exported function names and their input and return type, which I was able to find in the JSON.
Couldn’t we generate a json schema of rescript AST? Then one could use pretty much any tool to work on it, including rescript using rescript-json-schema for example.