Skip to content

Commit 9510d0a

Browse files
committed
support function types
1 parent 12be5ea commit 9510d0a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,18 @@
502502
:cljs (gstring/startsWith t "{")) t
503503

504504
#?(:clj (.startsWith t "function")
505-
:cljs (gstring/startsWith t "function")) t
505+
:cljs (gstring/startsWith t "function"))
506+
(let [idx (.lastIndexOf t ":")
507+
[fstr rstr] (if-not (== -1 idx)
508+
[(subs t 0 idx) (subs t (inc idx) (count t))]
509+
[t nil])
510+
ret-t (when rstr (resolve-type env rstr))
511+
axstr (subs fstr 9 (dec (count fstr)))
512+
args-ts (when-not (string/blank? axstr)
513+
(map (comp #(resolve-type env %) string/trim)
514+
(string/split axstr #",")))]
515+
(cond-> (str "function(" (string/join "," args-ts) ")")
516+
ret-t (str ":" ret-t)))
506517

507518
#?(:clj (.endsWith t "=")
508519
:cljs (gstring/endsWith t "="))

0 commit comments

Comments
 (0)