File tree Expand file tree Collapse file tree 2 files changed +24
-9
lines changed Expand file tree Collapse file tree 2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change 60
60
(ana/resolve-var env s)))
61
61
(symbol (str ana/*cljs-ns*) (str s))))
62
62
63
+ (defonce ^:private _speced_vars (atom #{}))
64
+
65
+ (defn speced-vars []
66
+ @_speced_vars )
67
+
63
68
(defmacro def
64
69
" Given a namespace-qualified keyword or resolveable symbol k, and a
65
70
spec, spec-name, predicate or regex-op makes an entry in the
66
71
registry mapping k to the spec. Use nil to remove an entry in
67
72
the registry for k."
68
73
[k spec-form]
69
- (let [k (if (symbol? k) (ns-qualify &env k) k)
74
+ (let [k (if (symbol? k)
75
+ (let [sym (ns-qualify &env k)]
76
+ (swap! _speced_vars conj
77
+ (vary-meta sym assoc :fdef-ns (-> &env :ns :name )))
78
+ sym)
79
+ k)
70
80
form (res &env spec-form)]
71
81
(swap! registry-ref (fn [r]
72
82
(if (nil? form)
403
413
(clojure.core/assert (not (empty? preds)))
404
414
`(tuple-impl '~(mapv #(res &env %) preds) ~(vec preds)))
405
415
406
- (defonce ^:private _speced_vars (atom #{}))
407
-
408
- (defn speced-vars []
409
- @_speced_vars )
410
-
411
416
(defmacro fdef
412
417
" Takes a symbol naming a function, and one or more of the following:
413
418
441
446
:sym symbol?)
442
447
:ret symbol?)"
443
448
[fn-sym & specs]
444
- (swap! _speced_vars conj
445
- (vary-meta (ns-qualify &env fn-sym)
446
- assoc :fdef-ns (-> &env :ns :name )))
447
449
`(cljs.spec.alpha/def ~fn-sym (fspec ~@specs)))
448
450
449
451
(defmacro keys*
Original file line number Diff line number Diff line change 455
455
(is (thrown? js/Error (defk :foo 1 )))
456
456
(is (= [:foo " bar" ] (defk :foo " bar" ))))
457
457
458
+ (s/def ::add-spec
459
+ (s/fspec :args (s/cat :n pos?)
460
+ :ret number?))
461
+
462
+ (s/def add2 ::add-spec )
463
+ (defn add2 [n]
464
+ (+ n 2 ))
465
+
466
+ (st/instrument `add2)
467
+
468
+ (deftest cljs-3137
469
+ (is (thrown? js/Error (add2 0 ))))
470
+
458
471
(comment
459
472
460
473
(run-tests )
You can’t perform that action at this time.
0 commit comments