Hi David,
This has been very helpful in understanding the internals of the ClojureScript compiler and I found it fascinating. Much appreciated.
I am having a bit of trouble understanding the syntax of the user environment map. Is there documentation for this? My goal is to specify multiple requires and multiple locals.
You have defined it as:
(def user-env '{:ns {:name cljs.user} :locals {}})
I have your code running happily in Light Table and I have pasted the following code at the end:
(let [form (read1 "(fn [a b] (+ a b x handler/y hand/z))")]
(with-out-str (c/emit (ana/analyze user-env form))))
This evaluates to:
"(function (a,b){return ((((a + b) + cljs.user.x) + handler.y) + hand.z);\r\n});\r\n"
Now, I want to find a way of altering the environment to something like:
(def user-env '{:ns {:name cljs.user :require [[compojure.handler :as hand]]} :locals {:name x}})
I am only showing one require and one local in this example but the result I would be hoping for is:
"(function (a,b){return ((((a + b) + x) + handler.y) + compojure.handler.z);\r\n});\r\n"
Notice that because handler/y would just compile to handler.y since there is no specific info on what to do in the environment.
When I evaluate using my environment, the JavaScript doesn't change, so what am I doing wrong? Is what I want even possible?
Many thanks,
Gregg.