This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-20
Channels
- # architecture (1)
- # babashka (5)
- # beginners (46)
- # calva (8)
- # cider (12)
- # clj-kondo (2)
- # cljfx (3)
- # clojure (23)
- # clojure-europe (7)
- # clojure-israel (2)
- # clojure-nl (11)
- # clojure-norway (8)
- # clojure-uk (1)
- # clojurescript (27)
- # conjure (2)
- # cursive (50)
- # data-oriented-programming (1)
- # data-science (1)
- # datahike (1)
- # datascript (12)
- # emacs (3)
- # events (1)
- # fulcro (13)
- # lambdaisland (7)
- # leiningen (4)
- # lsp (102)
- # meander (2)
- # off-topic (19)
- # parinfer (3)
- # reveal (8)
- # rewrite-clj (13)
- # shadow-cljs (3)
- # specter (13)
- # tools-deps (6)
- # vim (12)
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.
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 😞