Skip to content

Commit

Permalink
CLJS-1652: Self-host: Avoid alias so cljs.spec loadable
Browse files Browse the repository at this point in the history
  • Loading branch information
mfikes authored and swannodette committed May 29, 2016
1 parent 6544a51 commit 8477f19
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/cljs/cljs/spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
[cljs.spec.impl.gen :as gen]
[clojure.string :as str]))

(alias 'c 'clojure.core)

(defn- ->sym
"Returns a symbol from a symbol or var"
[x]
Expand All @@ -23,7 +21,7 @@
x))

(defn- unfn [expr]
(if (c/and (seq? expr)
(if (clojure.core/and (seq? expr)
(symbol? (first expr))
(= "fn*" (name (first expr))))
(let [[[s] & form] (rest expr)]
Expand All @@ -33,7 +31,7 @@
(defn- res [env form]
(cond
(keyword? form) form
(symbol? form) (c/or (->> form (resolve env) ->sym) form)
(symbol? form) (clojure.core/or (->> form (resolve env) ->sym) form)
(sequential? form) (walk/postwalk #(if (symbol? %) (res env %) %) (unfn form))
:else form))

Expand Down Expand Up @@ -122,7 +120,7 @@
(let [unk #(-> % name keyword)
req-keys (filterv keyword? (flatten req))
req-un-specs (filterv keyword? (flatten req-un))
_ (assert (every? #(c/and (keyword? %) (namespace %)) (concat req-keys req-un-specs opt opt-un))
_ (assert (every? #(clojure.core/and (keyword? %) (namespace %)) (concat req-keys req-un-specs opt opt-un))
"all keys must be namespace-qualified keywords")
req-specs (into req-keys req-un-specs)
req-keys (into req-keys (map unk req-un-specs))
Expand Down Expand Up @@ -163,7 +161,7 @@
keys (mapv first pairs)
pred-forms (mapv second pairs)
pf (mapv #(res &env %) pred-forms)]
(assert (c/and (even? (count key-pred-forms)) (every? keyword? keys)) "spec/or expects k1 p1 k2 p2..., where ks are keywords")
(assert (clojure.core/and (even? (count key-pred-forms)) (every? keyword? keys)) "spec/or expects k1 p1 k2 p2..., where ks are keywords")
`(cljs.spec/or-spec-impl ~keys '~pf ~pred-forms nil)))

(defmacro and
Expand Down Expand Up @@ -206,7 +204,7 @@
keys (mapv first pairs)
pred-forms (mapv second pairs)
pf (mapv #(res &env %) pred-forms)]
(assert (c/and (even? (count key-pred-forms)) (every? keyword? keys)) "alt expects k1 p1 k2 p2..., where ks are keywords")
(assert (clojure.core/and (even? (count key-pred-forms)) (every? keyword? keys)) "alt expects k1 p1 k2 p2..., where ks are keywords")
`(cljs.spec/alt-impl ~keys ~pred-forms '~pf)))

(defmacro cat
Expand All @@ -222,7 +220,7 @@
pred-forms (mapv second pairs)
pf (mapv #(res &env %) pred-forms)]
;;(prn key-pred-forms)
(assert (c/and (even? (count key-pred-forms)) (every? keyword? keys)) "cat expects k1 p1 k2 p2..., where ks are keywords")
(assert (clojure.core/and (even? (count key-pred-forms)) (every? keyword? keys)) "cat expects k1 p1 k2 p2..., where ks are keywords")
`(cljs.spec/cat-impl ~keys ~pred-forms '~pf)))

(defmacro &
Expand Down Expand Up @@ -332,7 +330,7 @@ specified, return speced vars from all namespaces."
(let [env &env
qn (ns-qualify env fn-sym)]
`(do ~@(reduce
(c/fn [defns role]
(clojure.core/fn [defns role]
(if (contains? m role)
(let [s (fn-spec-sym env qn (name role))]
(conj defns `(cljs.spec/def '~s ~(get m role))))
Expand Down

0 comments on commit 8477f19

Please sign in to comment.