Fork me on GitHub
#rewrite-clj
<
2021-02-20
>
borkdude15:02:49

If it looks like a sexpr...

mauricio.szabo19:02:00

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....

lread19:02:42

Heya @mauricio.szabo! Have you tried rewrite-clj.zip/prewalk and rewrite-clj.zip/postwalk yet?

borkdude19:02:09

@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

borkdude19:02:49

@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.

borkdude19:02:41

You can "loop" using z/next

mauricio.szabo21:02:44

@lee, no, I just saw I was using an old version of rewrite-cljs that didn't have this namespace. Will try it, thanks!

mauricio.szabo21:02:30

@borkdude I'm dealing with strings so, anything that works is good for me 😆

borkdude21:02:06

@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?

mauricio.szabo23:02:42

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

mauricio.szabo23:02:56

Oh, yeah, there's no rewrite-clj.zip/prewalk available for ClojureScript 😞