Hello. How to write a macro which emits code prefixed with js/?
This code
(defmacro log [text]
`(js/console.log ~text))
causes this compiler error:
Error in phase :compile-syntax-check
RuntimeException: No such namespace: js
clojure.lang.Util.runtimeException (Util.java:221)
clojure.lang.Compiler.resolveIn (Compiler.java:7913)
...How are you using that macro?
Is it in a .cljc file, by any chance?
I haven’t tried but can you manually construct the list using something like (list 'js/console.log ~text)
It's the same thing.
then how about manually constructing the symbol ?
It is the same thing. It's not about how the symbol is constructed.
.clj file
I have created an empty js.clj file in my src folder. Compilation ok. But then I get runtime error:
TypeError: (intermediate value).log is not a function@p-himik What would be the solution for a macro in a .cljc file?
Just follow thheller instructions: https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html
Solution:
`(~'js/console.log ~text)
and not calling the macro from a .clj or .cljc file.the solution is not the "new" syntax, it's the same as your initial one
it's about how you declare and use the macro