Skip to content

Commit 358e563

Browse files
mfikesswannodette
authored andcommitted
CLJS-1611: Function arity dispatch returns arity
Variadic and multi-arity defn forms expand to code that perform the needed def, followed by some side-effecting code. Instead of returning the value of the last side-effecting form, conditionally return a var for the name if :def-emits-vars is true, otherwise nil (which gets elided from compiled JavaScript.)
1 parent fc5a45b commit 358e563

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/clojure/cljs/core.cljc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@
27732773
(.push ~dest (aget (js-arguments) i#))
27742774
(recur (inc i#))))))
27752775

2776-
(core/defn- variadic-fn [name meta [[arglist & body :as method] :as fdecl]]
2776+
(core/defn- variadic-fn [name meta [[arglist & body :as method] :as fdecl] emit-var?]
27772777
(core/letfn [(dest-args [c]
27782778
(map (core/fn [n] `(aget (js-arguments) ~n))
27792779
(range c)))]
@@ -2797,7 +2797,8 @@
27972797
(.slice args# ~c-1) 0 nil))]
27982798
(. ~rname
27992799
(~'cljs$core$IFn$_invoke$arity$variadic ~@(dest-args c-1) argseq#))))))
2800-
~(variadic-fn* rname method)))))
2800+
~(variadic-fn* rname method)
2801+
~(core/when emit-var? `(var ~name))))))
28012802

28022803
(core/comment
28032804
(require '[clojure.pprint :as pp])
@@ -2807,7 +2808,7 @@
28072808
(pp/pprint (variadic-fn 'foo {} '(([a [b & cs] & xs] xs))))
28082809
)
28092810

2810-
(core/defn- multi-arity-fn [name meta fdecl]
2811+
(core/defn- multi-arity-fn [name meta fdecl emit-var?]
28112812
(core/letfn [(dest-args [c]
28122813
(map (core/fn [n] `(aget (js-arguments) ~n))
28132814
(range c)))
@@ -2863,7 +2864,8 @@
28632864
(str "Invalid arity: " (alength ~args-sym))))))))))
28642865
~@(map fn-method fdecl)
28652866
;; optimization properties
2866-
(set! (. ~name ~'-cljs$lang$maxFixedArity) ~maxfa)))))
2867+
(set! (. ~name ~'-cljs$lang$maxFixedArity) ~maxfa)
2868+
~(core/when emit-var? `(var ~name))))))
28672869

28682870
(core/comment
28692871
(require '[clojure.pprint :as pp])
@@ -2932,13 +2934,13 @@
29322934
(multi-arity-fn name
29332935
(if (comp/checking-types?)
29342936
(update-in m [:jsdoc] conj "@param {...*} var_args")
2935-
m) fdecl)
2937+
m) fdecl (:def-emits-var &env))
29362938

29372939
(variadic-fn? fdecl)
29382940
(variadic-fn name
29392941
(if (comp/checking-types?)
29402942
(update-in m [:jsdoc] conj "@param {...*} var_args")
2941-
m) fdecl)
2943+
m) fdecl (:def-emits-var &env))
29422944

29432945
:else
29442946
(core/list 'def (with-meta name m)

0 commit comments

Comments
 (0)