diff --git a/src/implant/dirac/implant.cljs b/src/implant/dirac/implant.cljs index 264ce0915a..61e36497a6 100644 --- a/src/implant/dirac/implant.cljs +++ b/src/implant/dirac/implant.cljs @@ -1,8 +1,10 @@ (ns dirac.implant - (:require-macros [cljs.core.async.macros :refer [go go-loop]]) + (:require-macros [cljs.core.async.macros :refer [go go-loop]] + [cljs.analyzer.macros :refer [no-warn]]) (:require [cljs.core.async :refer [put! js aliases)))) + +(defn get-uses [mapping] + (let [uses (remove-identical-mappings mapping)] + (if-not (empty? uses) + (clj->js uses)))) + +(defn parse-ns-from-source* [source] + (when-let [ns-form (parse-ns-form source)] + (let [ast (analyze-ns ns-form {}) + ns-descriptor #js {:name (str (:name ast)) + :aliases (get-aliases (:requires ast)) + :maliases (get-aliases (:require-macros ast)) + :uses (get-uses (:uses ast)) + :muses (get-uses (:use-macros ast))}] + ;(log "parse-ns-from-source" ns-descriptor (envelope source) (envelope ast)) + ns-descriptor))) + +(defn parse-ns-from-source [source] + (try + (parse-ns-from-source* source) + (catch :default e + (error "Unable to parse namespace from source" (envelope source) "\n" e)))) (defn is-cljs-function-name? [munged-name] (some? (re-matches #"^[^$]+\$[^$]+\$.*$" munged-name))) ; must have at least two dollars but not at the beginning