|
41 | 41 | (defn -replace-variadic-fn [original-fn n s opts] |
42 | 42 | (let [accessor "cljs$core$IFn$_invoke$arity$variadic" |
43 | 43 | arity-fn (g/get original-fn accessor)] |
44 | | - (g/set original-fn "malli$instrument$instrumented?" true) |
45 | | - ;; the shape of the argument in the following apply calls are needed to match the call style of the cljs compiler |
46 | | - ;; so the user's function gets the arguments as expected |
47 | | - (let [max-fixed-arity (-max-fixed-arity original-fn) |
48 | | - instrumented-variadic-fn (m/-instrument opts (fn [& args] |
49 | | - (let [[fixed-args rest-args] (split-at max-fixed-arity (vec args)) |
50 | | - final-args (into (vec fixed-args) [(not-empty rest-args)])] |
51 | | - (apply arity-fn final-args)))) |
52 | | - instrumented-wrapper (fn [& args] |
53 | | - (let [[fixed-args rest-args] (split-at max-fixed-arity (vec args)) |
54 | | - final-args (vec (apply list* (into (vec fixed-args) (not-empty rest-args))))] |
55 | | - (apply instrumented-variadic-fn final-args)))] |
56 | | - (g/set instrumented-wrapper "malli$instrument$original" arity-fn) |
57 | | - (g/set (-get-prop n s) "malli$instrument$instrumented?" true) |
58 | | - (g/set (-get-prop n s) accessor instrumented-wrapper) |
59 | | - (g/set (-get-ns n) s (meta-fn original-fn {:instrumented-symbol (symbol n s)}))))) |
| 44 | + (when arity-fn |
| 45 | + (g/set original-fn "malli$instrument$instrumented?" true) |
| 46 | + ;; the shape of the argument in the following apply calls are needed to match the call style of the cljs compiler |
| 47 | + ;; so the user's function gets the arguments as expected |
| 48 | + (let [max-fixed-arity (-max-fixed-arity original-fn) |
| 49 | + instrumented-variadic-fn (m/-instrument opts (fn [& args] |
| 50 | + (let [[fixed-args rest-args] (split-at max-fixed-arity (vec args)) |
| 51 | + final-args (into (vec fixed-args) [(not-empty rest-args)])] |
| 52 | + (apply arity-fn final-args)))) |
| 53 | + instrumented-wrapper (fn [& args] |
| 54 | + (let [[fixed-args rest-args] (split-at max-fixed-arity (vec args)) |
| 55 | + final-args (vec (apply list* (into (vec fixed-args) (not-empty rest-args))))] |
| 56 | + (apply instrumented-variadic-fn final-args)))] |
| 57 | + (g/set instrumented-wrapper "malli$instrument$original" arity-fn) |
| 58 | + (g/set (-get-prop n s) "malli$instrument$instrumented?" true) |
| 59 | + (g/set (-get-prop n s) accessor instrumented-wrapper) |
| 60 | + (g/set (-get-ns n) s (meta-fn original-fn {:instrumented-symbol (symbol n s)})))))) |
60 | 61 |
|
61 | 62 | (defn -replace-multi-arity [original-fn n s opts] |
62 | 63 | (let [schema (:schema opts)] |
|
66 | 67 | (if (= arity :varargs) |
67 | 68 | (-replace-variadic-fn original-fn n s opts) |
68 | 69 | (let [accessor (str "cljs$core$IFn$_invoke$arity$" arity) |
69 | | - arity-fn (g/get original-fn accessor) |
70 | | - instrumented-fn (m/-instrument (assoc opts :schema f-schema) arity-fn)] |
71 | | - (g/set instrumented-fn "malli$instrument$original" arity-fn) |
72 | | - (g/set instrumented-fn "malli$instrument$instrumented?" true) |
73 | | - (g/set (-get-prop n s) accessor instrumented-fn)))))) |
| 70 | + arity-fn (g/get original-fn accessor)] |
| 71 | + (when arity-fn |
| 72 | + (let [instrumented-fn (m/-instrument (assoc opts :schema f-schema) arity-fn)] |
| 73 | + (g/set instrumented-fn "malli$instrument$original" arity-fn) |
| 74 | + (g/set instrumented-fn "malli$instrument$instrumented?" true) |
| 75 | + (g/set (-get-prop n s) accessor instrumented-fn)))))))) |
74 | 76 |
|
75 | 77 | (defn -replace-fn [original-fn n s opts] |
76 | 78 | (cond |
|
92 | 94 | (case mode |
93 | 95 | :instrument (let [original-fn (or (-original v) v) |
94 | 96 | dgen (as-> (select-keys options [:scope :report :gen]) $ |
95 | | - (cond-> $ report (update :report (fn [r] (fn [t data] (r t (assoc data :fn-name (symbol n s))))))) |
| 97 | + (cond-> $ report (update :report (fn [r] (fn [t data] (r t (assoc data :fn-name (symbol (name n) (name s)))))))) |
96 | 98 | (merge $ d) |
97 | 99 | (cond (and gen (true? (:gen d))) (assoc $ :gen gen) |
98 | 100 | (true? (:gen d)) (dissoc $ :gen) |
99 | 101 | :else $))] |
100 | 102 | (if (and skip-instrumented? (-instrumented? v)) |
101 | 103 | (println "skipping" (symbol n s) "already instrumented") |
102 | | - (do (-replace-fn original-fn n s dgen) |
103 | | - (println "..instrumented" (symbol n s))))) |
| 104 | + (when original-fn |
| 105 | + (-replace-fn original-fn n s dgen) |
| 106 | + (println "..instrumented" (symbol n s))))) |
104 | 107 |
|
105 | 108 | :unstrument (when (-instrumented? v) |
106 | 109 | (let [original-fn (or (-original v) v)] |
|
0 commit comments