cljs.js/eval*
function | removed v1.7.28 | added v1.7.10 | Edit |
(eval* bound-vars form opts cb)
(defn eval* [bound-vars form opts cb]
(let [the-ns (or (:ns opts) 'cljs.user)
bound-vars (cond-> (merge bound-vars {:*cljs-ns* the-ns})
(:source-map opts) (assoc :*sm-data* (sm-data)))]
(binding [env/*compiler* (:*compiler* bound-vars)
*eval-fn* (:*eval-fn* bound-vars)
ana/*cljs-ns* (:*cljs-ns* bound-vars)
*ns* (create-ns (:*cljs-ns* bound-vars))
r/*data-readers* (:*data-readers* bound-vars)
comp/*source-map-data* (:*sm-data* bound-vars)]
(let [aenv (ana/empty-env)
aenv (cond-> (assoc aenv :ns (ana/get-namespace ana/*cljs-ns*))
(:context opts) (assoc :context (:context opts))
(:def-emits-var opts) (assoc :def-emits-var true))
res (try
{:value (ana/analyze aenv form nil opts)}
(catch :default cause
(wrap-error
(ana/error aenv
(str "Could not eval " form) cause))))]
(if (:error res)
(cb res)
(let [ast (:value res)]
(if (= :ns (:op ast))
(ns-side-effects true bound-vars aenv ast opts
(fn [res]
(if (:error res)
(cb res)
(let [src (str "goog.provide(\"" (munge (:name ast)) "\")")]
(cb (*eval-fn* {:source src}))))))
(let [src (with-out-str (comp/emit ast))]
(cb (*eval-fn* {:source src}))))))))))