cljs.js/analyze*
function | removed v1.7.28 | added v1.7.10 | Edit |
(analyze* bound-vars source name opts cb)
(defn analyze* [bound-vars source name opts cb]
(let [rdr (rt/indexing-push-back-reader source 1 name)
eof (js-obj)
aenv (ana/empty-env)
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)))]
((fn analyze-loop []
(binding [env/*compiler* (:*compiler* 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 [res (try
{:value (r/read {:eof eof :read-cond :allow :features #{:cljs}} rdr)}
(catch :default cause
(wrap-error
(ana/error aenv
(str "Could not analyze " 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 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 analyze " name) cause))))]
(if (:error res)
(cb res)
(let [ast (:value res)]
(if (= :ns (:op ast))
(ns-side-effects bound-vars aenv ast opts
(fn [res]
(if (:error res)
(cb res)
(analyze-loop))))
(recur)))))
(cb {:value nil}))))))))))