cljs.js/eval-str*
function | removed v1.7.28 | added v1.7.10 | Edit |
(eval-str* bound-vars source name opts cb)
(defn eval-str* [bound-vars source name opts cb]
(let [rdr (rt/indexing-push-back-reader source 1 name)
eof (js-obj)
aenv (ana/empty-env)
sb (StringBuffer.)
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)))]
(when (:verbose opts) (debug-prn "Evaluating" name))
((fn compile-loop [ns]
(binding [env/*compiler* (:*compiler* bound-vars)
*eval-fn* (:*eval-fn* bound-vars)
ana/*cljs-ns* ns
*ns* (create-ns ns)
r/*data-readers* (:*data-readers* bound-vars)
comp/*source-map-data* (:*sm-data* bound-vars)]
(let [res (try
{:value (r/read {:eof eof :read-cond :allow :features #{:cljs}} rdr)}
(catch :default cause
(wrap-error
(ana/error aenv
(str "Could not eval " name) cause))))]
(if (:error res)
(cb res)
(let [form (:value res)]
(if-not (identical? eof form)
(let [aenv (cond-> (assoc aenv :ns (ana/get-namespace 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 " name) cause))))]
(if (:error res)
(cb res)
(let [ast (:value res)
ns' ana/*cljs-ns*]
(if (= :ns (:op ast))
(do
(.append sb
(str "goog.provide(\"" (munge (:name ast)) "\");\n"))
(ns-side-effects true bound-vars aenv ast opts
(fn [res]
(if (:error res)
(cb res)
(compile-loop ns')))))
(do
(.append sb (with-out-str (comp/emit ast)))
(recur ns'))))))
(do
(when (:source-map opts)
(append-source-map env/*compiler*
name source sb @comp/*source-map-data* opts))
(let [js-source (.toString sb)
evalm {:lang :clj
:name name
:path (ns->relpath name)
:source js-source
:cache (get-in env/*compiler* [::ana/namespaces name])}
complete (fn [res]
(if (:error res)
(cb res)
(do
(when (:verbose opts)
(debug-prn js-source))
(let [res (try
{:ns ns :value (*eval-fn* evalm)}
(catch :default cause
(wrap-error (ana/error aenv "ERROR" cause))))]
(cb res)))))]
(if-let [f (:cache-source opts)]
(f evalm complete)
(complete {:value nil}))))))))))
(:*cljs-ns* bound-vars))))