Is there a clojurescript library that converts the ast returned from the analyzer back to a string?
You mean like to to the source code that the ast represents?
https://www.youtube.com/watch?v=2SGFeegEt9E might be a starting point.
tools analyzer has a pass to do that (goes from AST to code, then you can jus pr-str to go to string)
should be easy to extend it to the cljs specific nodes
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.
it works on any AST node
if you want to stringify just a children node, call it on that
Hmm, I think the problem is that form
of the parent contains the form
s of all children below
it doesn't use form
you can update the AST and the emitted code will reflect the current AST, not the original form
Ah perfect! Was mistaken by only looking at https://github.com/clojure/tools.analyzer.jvm/blob/master/src/main/clojure/clojure/tools/analyzer/passes/jvm/emit_form.clj#L17
I'll see if I can port that quickly to CLJS
@bronsa do you foresee issues in CLJS around the quoting https://github.com/clojure/tools.analyzer.jvm/blob/master/src/main/clojure/clojure/tools/analyzer/passes/jvm/emit_form.clj#L71-L77 and splicing https://github.com/clojure/tools.analyzer.jvm/blob/master/src/main/clojure/clojure/tools/analyzer/passes/jvm/emit_form.clj#L120-L123
no
is this for self-hosted cljs?
(for context, this is the pass you should be using https://github.com/clojure/tools.analyzer/blob/master/src/main/clojure/clojure/tools/analyzer/passes/emit_form.clj)
and extending it like t.a.jvm does for the cljs specific ops
ok thanks @bronsa