clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
denik 2020-02-07T08:25:45.018400Z

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

slipset 2020-02-07T08:34:37.018800Z

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

slipset 2020-02-07T08:35:16.019100Z

https://www.youtube.com/watch?v=2SGFeegEt9E might be a starting point.

bronsa 2020-02-07T16:20:39.020200Z

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

bronsa 2020-02-07T16:20:57.020900Z

should be easy to extend it to the cljs specific nodes

denik 2020-02-07T16:28:06.023600Z

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.

bronsa 2020-02-07T16:28:41.024100Z

it works on any AST node

bronsa 2020-02-07T16:28:58.024500Z

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

denik 2020-02-07T16:29:39.025300Z

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

bronsa 2020-02-07T16:30:04.026Z

it doesn't use form

bronsa 2020-02-07T16:30:47.026600Z

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

denik 2020-02-07T16:33:02.027900Z

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

bronsa 2020-02-07T16:35:07.028900Z

no

bronsa 2020-02-07T16:35:18.029100Z

is this for self-hosted cljs?

bronsa 2020-02-07T16:36:47.030300Z

(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)

bronsa 2020-02-07T16:36:58.030700Z

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

denik 2020-02-07T16:51:20.031Z

ok thanks @bronsa