I'm struggling a little with the cljs API. I have a .cljs file containing a series of forms on my classpath and want to obtain the corresponding javascript as a string, without having to write to any kind of filesystem. I can get it through the analyzer, but don't know how to get the javascript emitted:
(with-core-cljs nil (fn []
(analyze-file "us/quartyard/wat.cljs")
(println(all-ns)) ;; prints essentially what I expect.
(now what???)))
I've read the docs and it is by no means obvious what to call after analyze-file.
Edit (adding more information):
There is a function cljs.compiler.api/emit which return some js given an AST node. But the only way I have found to get an AST node is to call (analyze form) where form is a single cljs form.
To analyze a complete file defining a namespace with many forms, the only obvious way use to call analyze-file, which returns nothing and adds the AST for the namespace to the ambient compiler state. But it's not clear how to get that AST back out.
For example:
(with-core-cljs nil (fn []
(analyze-file "us/quartyard/wat.cljs")
(emit (analyze (empty-env) '(println "ok"))))
emits a single line of js that prints "ok", but nothing from my file.
Meanwhile,
(with-core-cljs nil (fn []
(analyze-file "us/quartyard/wat.cljs")
(find-ns 'us.quartyard.wat)))
returns nil, rather than an AST for my namespace.
So what am I missing?
(cljs.compiler.api/emit)- ClojureMostly