File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 61
61
(symbol (str ana/*cljs-ns*) (str s))))
62
62
63
63
(defmacro def
64
- " Given a namespace-qualified keyword or resolveable symbol k, and a spec,
65
- spec-name, predicate or regex-op makes an entry in the registry mapping k to
66
- the spec"
64
+ " Given a namespace-qualified keyword or resolveable symbol k, and a
65
+ spec, spec-name, predicate or regex-op makes an entry in the
66
+ registry mapping k to the spec. Use nil to remove an entry in
67
+ the registry for k."
67
68
[k spec-form]
68
69
(let [k (if (symbol? k) (ns-qualify &env k) k)
69
70
form (res &env spec-form)]
Original file line number Diff line number Diff line change 294
294
" Do not call this directly, use 'def'"
295
295
[k form spec]
296
296
(assert (c/and (ident? k) (namespace k)) " k must be namespaced keyword or resolveable symbol" )
297
- (let [spec (if (c/or (spec? spec) (regex? spec) (get @registry-ref spec))
298
- spec
299
- (spec-impl form spec nil nil ))]
300
- (swap! registry-ref assoc k (with-name spec k))
301
- k))
297
+ (if (nil? spec)
298
+ (swap! registry-ref dissoc k)
299
+ (let [spec (if (c/or (spec? spec) (regex? spec) (get @registry-ref spec))
300
+ spec
301
+ (spec-impl form spec nil nil ))]
302
+ (swap! registry-ref assoc k (with-name spec k))))
303
+ k )
302
304
303
305
(defn registry
304
306
" returns the registry map, prefer 'get-spec' to lookup a spec by name"
Original file line number Diff line number Diff line change 307
307
(deftest keys-explain-pred
308
308
(is (= 'cljs.core/map? (-> (s/explain-data (s/keys :req [::x ]) :a ) ::s/problems first :pred ))))
309
309
310
+ (deftest remove-def
311
+ (is (= ::ABC (s/def ::ABC string? )))
312
+ (is (= ::ABC (s/def ::ABC nil )))
313
+ (is (nil? (s/get-spec ::ABC ))))
314
+
310
315
(s/fdef foo.bar/cljs-2275
311
316
:args (s/cat :k keyword?)
312
317
:ret string?)
You can’t perform that action at this time.
0 commit comments