File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6161 (symbol (str ana/*cljs-ns*) (str s))))
6262
6363(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."
6768 [k spec-form]
6869 (let [k (if (symbol? k) (ns-qualify &env k) k)
6970 form (res &env spec-form)]
Original file line number Diff line number Diff line change 294294 " Do not call this directly, use 'def'"
295295 [k form spec]
296296 (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 )
302304
303305(defn registry
304306 " returns the registry map, prefer 'get-spec' to lookup a spec by name"
Original file line number Diff line number Diff line change 307307(deftest keys-explain-pred
308308 (is (= 'cljs.core/map? (-> (s/explain-data (s/keys :req [::x ]) :a ) ::s/problems first :pred ))))
309309
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+
310315(s/fdef foo.bar/cljs-2275
311316 :args (s/cat :k keyword?)
312317 :ret string?)
You can’t perform that action at this time.
0 commit comments