Skip to content

Commit 20b08fe

Browse files
mfikesswannodette
authored andcommitted
CLJS-1720: Qualify symbols and namespaced keywords in spec macros
There are currently a few symbols and namespaced keywords in the cljs.spec macros namespace that either need to be qualified for proper operation, or should be. The symbols fall into the category of calls to runtime functions in the cljs.spec namespace, and need qualification in order to avoid the $macros suffix. These comprise with-gen and gen. In terms of keywords, an example that causes a failure is ::kvs->map in keys*: It resolves to :cljs.spec$macros/kvs->map which doesn't match the :cljs.spec/kvs->map spec registered near the bottom of the cljs.spec runtime namespace. An example that doesn't cause an outright failure, but arguably inhibits its proper use by client code is ::nil and ::pred in the nilable macro. Ideally these would resolve to :cljs.spec/nil and :cljs.spec/pred so that client code can rely on these namespaced symbols identifying the branches. Given the nilable example, you could argue that the intent is that all namespaced keywords in the cljs.spec macro namespace that employ :: resolve in :cljs.spec so that they can be used not simply as unique identifiers (the intent is not simply to avoid potential collisions), but so that they can be used as stable identifiers. The set of keywords that should be qualified comprises: ::kind-form, ::kfn, ::conform-all, ::kvs->map, ::nil, and ::pred
1 parent eaba75c commit 20b08fe

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/main/cljs/cljs/spec.cljc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
See also - coll-of, every-kv
224224
"
225225
[pred & {:keys [into kind count max-count min-count distinct gen-max gen-into gen] :as opts}]
226-
(let [nopts (-> opts (dissoc :gen) (assoc ::kind-form `'~(res &env (:kind opts))))]
226+
(let [nopts (-> opts (dissoc :gen) (assoc :cljs.spec/kind-form `'~(res &env (:kind opts))))]
227227
`(cljs.spec/every-impl '~pred ~pred ~nopts ~gen)))
228228

229229
(defmacro every-kv
@@ -234,7 +234,7 @@
234234
See also - map-of"
235235

236236
[kpred vpred & opts]
237-
`(every (tuple ~kpred ~vpred) ::kfn (fn [i# v#] (nth v# 0)) :into {} ~@opts))
237+
`(every (tuple ~kpred ~vpred) :cljs.spec/kfn (fn [i# v#] (nth v# 0)) :into {} ~@opts))
238238

239239
(defmacro coll-of
240240
"Returns a spec for a collection of items satisfying pred. Unlike
@@ -248,7 +248,7 @@
248248
249249
See also - every, map-of"
250250
[pred & opts]
251-
`(every ~pred ::conform-all true ~@opts))
251+
`(every ~pred :cljs.spec/conform-all true ~@opts))
252252

253253
(defmacro map-of
254254
"Returns a spec for a map whose keys satisfy kpred and vals satisfy
@@ -261,7 +261,7 @@
261261
262262
See also - every-kv"
263263
[kpred vpred & opts]
264-
`(every-kv ~kpred ~vpred ::conform-all true :kind map? ~@opts))
264+
`(every-kv ~kpred ~vpred :cljs.spec/conform-all true :kind map? ~@opts))
265265

266266
(defmacro *
267267
"Returns a regex op that matches zero or more values matching
@@ -415,13 +415,13 @@
415415
{:i1 42, :m {:a 1, :c 2, :d 4}, :i2 99}"
416416
[& kspecs]
417417
`(let [mspec# (keys ~@kspecs)]
418-
(with-gen (cljs.spec/& (* (cat ::k keyword? ::v cljs.core/any?)) ::kvs->map mspec#)
419-
(fn [] (gen/fmap (fn [m#] (apply concat m#)) (gen mspec#))))))
418+
(cljs.spec/with-gen (cljs.spec/& (* (cat :cljs.spec/k keyword? :cljs.spec/v cljs.core/any?)) :cljs.spec/kvs->map mspec#)
419+
(fn [] (gen/fmap (fn [m#] (apply concat m#)) (cljs.spec/gen mspec#))))))
420420

421421
(defmacro nilable
422422
"returns a spec that accepts nil and values satisfiying pred"
423423
[pred]
424-
`(and (or ::nil nil? ::pred ~pred) (conformer second)))
424+
`(and (or :cljs.spec/nil nil? :cljs.spec/pred ~pred) (conformer second)))
425425

426426
(defmacro inst-in
427427
"Returns a spec that validates insts in the range from start
@@ -466,4 +466,4 @@
466466
fspec)
467467
f# ~sym]
468468
(for [args# (gen/sample (gen (:args fspec#)) ~n)]
469-
[args# (apply f# args#)]))))
469+
[args# (apply f# args#)]))))

0 commit comments

Comments
 (0)