Skip to content

Commit 37eed58

Browse files
committedJan 26, 2025
* change inference to that constructors return themselves as the type not js/Function
* add corresponding js-tag test
1 parent 9609c26 commit 37eed58

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
 

‎src/main/clojure/cljs/analyzer.cljc

+9-2
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,16 @@
10791079
(js-tag pre tag-type externs externs))
10801080
([pre tag-type externs top]
10811081
(when-let [[p externs' :as me] (find externs (first pre))]
1082-
(let [tag (-> p meta tag-type)]
1082+
(let [info (meta p)
1083+
tag (get info tag-type)]
10831084
(if (= (count pre) 1)
1084-
(when tag (symbol "js" (str (alias->type tag tag))))
1085+
(when tag
1086+
;; If we have a JS constructor don't return the type as
1087+
;; js/Function as this isn't useful in type inference
1088+
;; instead just return the constructor
1089+
(if-let [ctor (:ctor info)]
1090+
(symbol "js" (str ctor))
1091+
(symbol "js" (str (alias->type tag tag)))))
10851092
(or (js-tag (next pre) tag-type externs' top)
10861093
(js-tag (into '[prototype] (next pre)) tag-type (get top tag) top)))))))
10871094

‎src/test/clojure/cljs/externs_infer_tests.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
(is (= 'js/Console (ana/js-tag '[console] :tag externs)))
4949
(is (= 'js/Function (ana/js-tag '[console log] :tag externs)))
5050
(is (= 'js/Boolean (ana/js-tag '[Number isNaN] :ret-tag externs)))
51-
(is (= 'js/Foo (ana/js-tag '[baz] :ret-tag externs)))))
51+
(is (= 'js/Foo (ana/js-tag '[baz] :ret-tag externs)))
52+
(is (= 'js/Number (ana/js-tag '[Number] :tag externs)))))
5253

5354
(defn infer-test-helper
5455
[{:keys [forms externs warnings warn js-dependency-index node-module-index with-core? opts]}]

0 commit comments

Comments
 (0)
Failed to load comments.