Fork me on GitHub
#sci
<
2021-02-19
>
mauricio.szabo12:02:12

Hi, @borkdude. I'm trying to do something quite bizarre, so let me check if there's a better way with you here đŸ™‚. I want to use SCI on a CLJS project. The problem is that I'll need to alter the source a little bit before I interpret it. In my case, I want to convert every instance of (js/require "some-filename.js") that appears on my code to a string (specifically, I'll replace to the contents of some-filename.js). Does exist a simple way to do this, to make this transformation?

mauricio.szabo12:02:36

Originally, I was thinking on using rewrite-cljs to make the change, just so you know what are my ideas đŸ˜„

borkdude12:02:27

@mauricio.szabo yes, you can do this quite easily, by using the lower level API, by first parsing the expressions using sci/parse-next, then rewrite them and then evaluating using eval-form.

borkdude12:02:34

@mauricio.szabo I'm doing something similar in grasp, where I parse expressions and only evaluate the namespace forms after a bit of rewriting.

borkdude12:02:20

However, why don't you just use :load-fn so users can use the normal require?

borkdude12:02:56

Ah you are not loading normal CLJS code. Yes, the above approach should then be ok

borkdude12:02:16

Alternatively you can override another function into js/require possibly

mauricio.szabo12:02:28

Yes, and I have to bundle the JS lib too, and other strange things đŸ˜„