Fork me on GitHub
#clojure-dev
<
2020-02-07
>
denik08:02:45

Is there a clojurescript library that converts the ast returned from the analyzer back to a string?

slipset08:02:37

You mean like to to the source code that the ast represents?

denik16:02:14

Yes. Thanks, I think the video goes beyond my needs. Some of the clojure refactoring tools contain ast->string fns. however, they're quite involved and usually not clojurescript compatible. I was surprised that there weren't a few projects converting an AST to a string. after all that should be easier than going from string to AST.

bronsa16:02:39

tools analyzer has a pass to do that (goes from AST to code, then you can jus pr-str to go to string)

bronsa16:02:57

should be easy to extend it to the cljs specific nodes

denik16:02:06

thanks @bronsa this would return the entire string for the top level form as well as all children if the AST was to be recursed into, right? For my usecase that's problematic, since I'm looking to update the AST (sometimes deeply) and turn it into a string after.

bronsa16:02:41

it works on any AST node

bronsa16:02:58

if you want to stringify just a children node, call it on that

denik16:02:39

Hmm, I think the problem is that form of the parent contains the forms of all children below

bronsa16:02:04

it doesn't use form

bronsa16:02:47

you can update the AST and the emitted code will reflect the current AST, not the original form

denik16:02:02

I'll see if I can port that quickly to CLJS

bronsa16:02:18

is this for self-hosted cljs?

bronsa16:02:58

and extending it like t.a.jvm does for the cljs specific ops