quack
If it looks like a sexpr...
Hi there! Just a question, is there a way that, given a specific clojure code, find all ocurrences of, for example, (js/require...)
and rewrite all of then to something else? Something like walk/postwalk-replace
but using the sexp as argument so I can customize what will be returned....
Heya @mauricio.szabo! Have you tried rewrite-clj.zip/prewalk
and rewrite-clj.zip/postwalk
yet?
@mauricio.szabo are you dealing with s-expressions or rewrite clj nodes? this is pretty easy using normal sexprs outside of rewrite-clj as well
@mauricio.szabo but if you're dealing with rewrite-clj you can simply loop through all nodes and when you encounter the one you are looking for, replace it.
You can "loop" using z/next
Example here (but then removing instead of replacing): https://github.com/borkdude/carve/blob/a3a5b941d4327127e36541bf7322b15b33260386/src/carve/impl.clj#L103-L136
@lee, no, I just saw I was using an old version of rewrite-cljs that didn't have this namespace. Will try it, thanks!
@borkdude I'm dealing with strings so, anything that works is good for me 😆
@mauricio.szabo is this in the context of sci (because you asked something similar in #sci) - i.e. are you going to eval this with sci?
Yes, what I want to test is if it's possible to somehow detect every js/require
that will be sent to SCI, convert it (with webpack's API) to a single file (or a string), and then eval everything in the process
Oh, yeah, there's no rewrite-clj.zip/prewalk
available for ClojureScript 😞