Skip to content

Commit

Permalink
* change inference to that constructors return themselves as the type…
Browse files Browse the repository at this point in the history
… not js/Function

* add corresponding js-tag test
  • Loading branch information
swannodette committed Jan 26, 2025
1 parent 9609c26 commit 37eed58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,16 @@
(js-tag pre tag-type externs externs))
([pre tag-type externs top]
(when-let [[p externs' :as me] (find externs (first pre))]
(let [tag (-> p meta tag-type)]
(let [info (meta p)
tag (get info tag-type)]
(if (= (count pre) 1)
(when tag (symbol "js" (str (alias->type tag tag))))
(when tag
;; If we have a JS constructor don't return the type as
;; js/Function as this isn't useful in type inference
;; instead just return the constructor
(if-let [ctor (:ctor info)]
(symbol "js" (str ctor))
(symbol "js" (str (alias->type tag tag)))))
(or (js-tag (next pre) tag-type externs' top)
(js-tag (into '[prototype] (next pre)) tag-type (get top tag) top)))))))

Expand Down
3 changes: 2 additions & 1 deletion src/test/clojure/cljs/externs_infer_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
(is (= 'js/Console (ana/js-tag '[console] :tag externs)))
(is (= 'js/Function (ana/js-tag '[console log] :tag externs)))
(is (= 'js/Boolean (ana/js-tag '[Number isNaN] :ret-tag externs)))
(is (= 'js/Foo (ana/js-tag '[baz] :ret-tag externs)))))
(is (= 'js/Foo (ana/js-tag '[baz] :ret-tag externs)))
(is (= 'js/Number (ana/js-tag '[Number] :tag externs)))))

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

0 comments on commit 37eed58

Please sign in to comment.