Skip to content

Commit 82c3e07

Browse files
committed
* wip
1 parent 5e31004 commit 82c3e07

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

src/main/clojure/cljs/analyzer.cljc

+28-12
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,7 @@
982982
(if-not (= 'js x)
983983
(with-meta 'js
984984
{:prefix (conj (->> (string/split (name x) #"\.")
985-
(map symbol) vec)
986-
'prototype)})
985+
(map symbol) vec))})
987986
x))
988987

989988
(defn ->type-set
@@ -1030,7 +1029,9 @@
10301029
boolean Boolean
10311030
symbol Symbol})
10321031

1033-
(defn extern-var-info
1032+
(defn resolve-extern
1033+
"Given a foreign js property list, return a resolved js property list and the
1034+
extern var info"
10341035
([pre externs]
10351036
(let [pre (if-some [me (find
10361037
(get-in externs '[Window prototype])
@@ -1039,10 +1040,10 @@
10391040
(into [tag 'prototype] (next pre))
10401041
pre)
10411042
pre)]
1042-
(extern-var-info pre externs externs nil)))
1043-
([pre externs top info]
1043+
(resolve-extern pre externs externs {:resolved [] :info nil})))
1044+
([pre externs top ret]
10441045
(cond
1045-
(empty? pre) info
1046+
(empty? pre) ret
10461047
:else
10471048
(let [x (first pre)
10481049
me (find externs x)]
@@ -1052,16 +1053,31 @@
10521053
(let [[x' externs'] me
10531054
info' (meta x')]
10541055
(if (and (= 'Function (:tag info')) (:ctor info'))
1055-
(or (extern-var-info (into '[prototype] (next pre)) externs' top nil)
1056-
(extern-var-info (next pre) externs' top info')
1057-
;; check base type if it exists
1056+
(or
1057+
;; first look for a property on the prototype
1058+
(resolve-extern (into '[prototype] (next pre)) externs' top
1059+
(-> ret
1060+
(update :resolved conj 'prototype)
1061+
(assoc :info nil)))
1062+
;; then check for "static" property
1063+
(resolve-extern (next pre) externs' top
1064+
(-> ret
1065+
(update :resolved conj x)
1066+
(assoc :info info')))
1067+
;; finally check the super class if there is one
10581068
(when-let [super (:super info')]
1059-
(extern-var-info (into [super] (next pre)) externs top nil)))
1060-
(recur (next pre) externs' top info'))))))))
1069+
(resolve-extern (into [super] (next pre)) externs top
1070+
(-> ret
1071+
(update :resolved conj x)
1072+
(assoc :info nil)))))
1073+
(recur (next pre) externs' top
1074+
(-> ret
1075+
(update :resolved conj x)
1076+
(assoc :info info'))))))))))
10611077

10621078
(defn has-extern?*
10631079
[pre externs]
1064-
(boolean (extern-var-info pre externs)))
1080+
(boolean (resolve-extern pre externs)))
10651081

10661082
(defn has-extern?
10671083
([pre]

src/test/clojure/cljs/externs_infer_tests.clj

+10-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
"goog.isArrayLike;" "Java.type;" "Object.out;" "Object.out.println;"
2424
"Object.error;" "Object.error.println;"])
2525

26+
(deftest test-resolve-extern
27+
(let [externs
28+
(externs/externs-map
29+
(closure/load-externs
30+
{:externs ["src/test/externs/test.js"]
31+
:use-only-custom-externs true}))]
32+
(is (some? (ana/resolve-extern '[baz] externs)))
33+
(is (nil? (ana/resolve-extern '[Foo gozMethod] externs)))))
34+
2635
(deftest test-has-extern?-basic
2736
(let [externs (externs/externs-map
2837
(closure/load-externs
@@ -37,19 +46,12 @@
3746

3847
(comment
3948

40-
(def externs
41-
(externs/externs-map
42-
(closure/load-externs
43-
{:externs ["src/test/externs/test.js"]
44-
:use-only-custom-externs true})))
49+
(clojure.test/test-vars [#'test-resolve-extern])
4550

4651
;; working
4752
(externs/info externs '[baz])
4853
(externs/info externs '[Foo gozMethod])
4954

50-
(ana/extern-var-info '[baz] externs)
51-
(ana/extern-var-info '[Foo gozMethod] externs)
52-
5355
(ana/has-extern? '[Foo] externs)
5456

5557
)

0 commit comments

Comments
 (0)