Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLJS-3408: Handle @extends in externs #218

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,10 @@
xmeta (meta x')]
(if (and (= 'Function (:tag xmeta)) (:ctor xmeta))
(or (has-extern?* (into '[prototype] (next pre)) externs' top)
(has-extern?* (next pre) externs' top))
(has-extern?* (next pre) externs' top)
;; check base type if it exists
(when-let [super (:super xmeta)]
(has-extern?* (into [super] (next pre)) externs top)))
(recur (next pre) externs' top))))))))

(defn has-extern?
Expand Down
4 changes: 3 additions & 1 deletion src/main/clojure/cljs/externs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
{:tag (get-tag ty)}
(if (or (.isConstructor info) (.isInterface info))
(let [qname (symbol (.. node getFirstChild getQualifiedName))]
(cond-> {:tag 'Function}
(cond-> (merge {:tag 'Function}
(when (.hasBaseType info)
{:super (get-tag (.getBaseType info))}))
(.isConstructor info) (merge {:ctor qname})
(.isInterface info) (merge {:iface qname})))
(if (or (.hasReturnType info)
Expand Down
11 changes: 11 additions & 0 deletions src/test/clojure/cljs/externs_infer_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,17 @@
["Object.renderInline;"])
res)))))

(deftest test-cljs-3408
(testing "inheritance of JS Types is inferred"
(let [ws (atom [])
res (infer-test-helper
{:forms '[(ns foo.core)
(.querySelectorAll js/document "div")]
:warnings ws
:warn true
:with-core? true})]
(is (empty? @ws)))))

(comment
(binding [ana/*cljs-ns* ana/*cljs-ns*]
(ana/no-warn
Expand Down
13 changes: 12 additions & 1 deletion src/test/clojure/cljs/externs_parsing_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
(:require [cljs.closure :as closure]
[cljs.externs :as externs]
[clojure.java.io :as io]
[clojure.test :as test :refer [deftest is]]))
[clojure.test :as test :refer [deftest is]])
(:import [com.google.javascript.jscomp CommandLineRunner]))

(deftest cljs-3121
(let [externs (externs/parse-externs
Expand All @@ -34,6 +35,16 @@
(is (= 'any (get-in ns [:defs 'get :ret-tag])))
(is (= 'array (get-in ns [:defs 'getKeys :ret-tag])))))

(deftest test-parse-super
(let [info (->
(filter
(fn [s]
(= "externs.zip//w3c_dom2.js" (.getName s)))
(CommandLineRunner/getDefaultExterns))
first externs/parse-externs externs/index-externs
(find 'HTMLDocument) first meta)]
(is (= 'Document (:super info)))))

(comment

(externs/parse-externs
Expand Down
Loading