Skip to content

Commit

Permalink
Merge pull request #696 from dvingo/dvingo/fix-cljs-dev-start
Browse files Browse the repository at this point in the history
Only call functions from a cljs macro, not other macros
  • Loading branch information
ikitommi committed Apr 27, 2022
2 parents 6751b1d + 56a3cf0 commit f7b4e12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/malli/dev/cljs.cljc
Expand Up @@ -19,7 +19,7 @@
~(mi/-unstrument env nil)

;; register all function schemas and instrument them based on the options
~(mi/-collect-all-ns)
~(mi/-collect-all-ns env)
~(mi/-instrument env options))))

#?(:clj (defmacro start!
Expand All @@ -32,4 +32,4 @@
([] (start!* &env {:report `(pretty/thrower)}))
([options] (start!* &env options))))

#?(:clj (defmacro collect-all! [] (mi/-collect-all-ns)))
#?(:clj (defmacro collect-all! [] (mi/-collect-all-ns &env)))
27 changes: 15 additions & 12 deletions src/malli/instrument/cljs.clj
Expand Up @@ -43,9 +43,21 @@

(defn -sequential [x] (cond (set? x) x (sequential? x) x :else [x]))

(defn -collect!*
[env {:keys [ns]}]
(reduce (fn [acc [var-name var-map]] (let [v (-collect! env var-name var-map)] (cond-> acc v (conj v))))
#{}
(mapcat (fn [n]
(let [ns-sym (cond (symbol? n) n
;; handles (quote ns-name) - quoted symbols passed to cljs macros show up this way.
(list? n) (second n)
:else (symbol (str n)))]
(ana-api/ns-publics ns-sym)))
(-sequential ns))))

;; intended to be called from a cljs macro
(defn -collect-all-ns []
`(collect! {:ns ~(ana-api/all-ns)}))
(defn -collect-all-ns [env]
(-collect!* env {:ns (ana-api/all-ns)}))

;;
;; instrument
Expand Down Expand Up @@ -154,16 +166,7 @@
| `:malli/report` | optional side-effecting function of `key data -> any` to report problems, defaults to `m/-fail!`
| `:malli/gen` | optional value `true` or function of `schema -> schema -> value` to be invoked on the args to get the return value"
([] `(collect! ~{:ns (symbol (str *ns*))}))
([{:keys [ns]}]
(reduce (fn [acc [var-name var-map]] (let [v (-collect! &env var-name var-map)] (cond-> acc v (conj v))))
#{}
(mapcat (fn [n]
(let [ns-sym (cond (symbol? n) n
;; handles (quote ns-name) - quoted symbols passed to cljs macros show up this way.
(list? n) (second n)
:else (symbol (str n)))]
(ana-api/ns-publics ns-sym)))
(-sequential ns)))))
([args-map] (-collect!* &env args-map)))

(defmacro instrument!
"Applies instrumentation for a filtered set of function Vars (e.g. `defn`s).
Expand Down

0 comments on commit f7b4e12

Please sign in to comment.