Skip to content

Commit afc57a7

Browse files
committed
CLJS-1405: type resolution needs to handle modifiers like leading !, trailing =, object syntax
punting on function & record syntax for now
1 parent 9b54d4d commit afc57a7

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,38 @@
475475
(emits "(function(){throw " throw "})()")
476476
(emitln "throw " throw ";")))
477477

478-
(defn resolve-type [env t]
479-
(str (:name (ana/resolve-var env (symbol t)))))
478+
(def base-types
479+
#{"boolean" "Boolean"
480+
"string" "String"
481+
"number" "Number"
482+
"array" "Array"
483+
"object" "Object"
484+
"RegExp"
485+
"Date"})
486+
487+
(defn resolve-type [env ^String t]
488+
(cond
489+
(get base-types t) t
490+
491+
#?(:clj (.startsWith t "!")
492+
:cljs (gstring/startsWith t "!")) t
493+
494+
#?(:clj (.startsWith t "{")
495+
:cljs (gstring/startsWith t "{")) t
496+
497+
#?(:clj (.startsWith t "function")
498+
:cljs (gstring/startsWith t "function")) t
499+
500+
:else
501+
(let [optional? #?(:clj (.endsWith t "=")
502+
:cljs (gstring/endsWith t "="))
503+
t (if optional?
504+
(subs t 0 (dec (count t)))
505+
t)
506+
ret (str (:name (ana/resolve-var env (symbol t))))]
507+
(if optional?
508+
(str ret "=")
509+
ret))))
480510

481511
(defn resolve-types [env ts]
482512
(let [ts (-> ts string/trim (subs 1 (dec (count ts))))

0 commit comments

Comments
 (0)