File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 1056
1056
(and (empty? (next pre))
1057
1057
(not (contains? ret :info )))
1058
1058
(assoc :info info'))]
1059
- (if (and (:ctor info') (= 'Function (:tag info')))
1059
+ ; ; handle actual occurrences of types, i.e. `Console`
1060
+ (if (and (or (:ctor info') (:iface info')) (= 'Function (:tag info')))
1060
1061
(or
1061
1062
; ; then check for "static" property
1062
1063
(resolve-extern (next pre) externs' top
1072
1073
(assoc ret :resolved []))))
1073
1074
1074
1075
(or
1075
- ; ; If the tag isn't Function or undefined,
1076
- ; ; try to resolve it similar to the super case above
1076
+ ; ; If the tag of the property isn't Function or undefined,
1077
+ ; ; try to resolve it similar to the super case above,
1078
+ ; ; this handles singleton cases like `console`
1077
1079
(let [tag (:tag info')]
1078
1080
(when (and tag (not (contains? '#{Function undefined} tag)))
1079
- (resolve-extern (into [tag] (next pre)) externs top
1081
+ ; ; check prefix first, during cljs.externs parsing we always generate prefixes
1082
+ ; ; for tags because of types like webCrypto.Crypto
1083
+ (resolve-extern (into (or (-> tag meta :prefix ) [tag]) (next pre)) externs top
1080
1084
(assoc ret :resolved []))))
1081
1085
1082
1086
; ; assume static property
Original file line number Diff line number Diff line change 61
61
(and (= type :string-lit )
62
62
(= " undefined" value)))
63
63
64
+ (defn add-prefix
65
+ " Externs inference uses :prefix meta to both resolve externs as well as generate
66
+ missing externs information. Google Closure Compiler default externs includes
67
+ nested types like webCrypto.Crypto. Add prefix information to the returned symbol to
68
+ simplify resolution later."
69
+ [type-str]
70
+ (with-meta (symbol type-str)
71
+ {:prefix (->> (string/split (name type-str) #"\. " )
72
+ (map symbol) vec)}))
73
+
64
74
(defn simplify-texpr
65
75
[texpr]
66
76
(case (:type texpr)
67
- :string-lit (some-> (:value texpr) symbol)
68
- (:star :qmark ) 'any
69
- :bang (simplify-texpr (-> texpr :children first))
77
+ :string-lit (some-> (:value texpr) add-prefix)
78
+ :star 'any
79
+ ; ; TODO: qmark should probably be #{nil T}
80
+ (:qmark :bang ) (simplify-texpr (-> texpr :children first))
70
81
:pipe (let [[x y] (:children texpr)]
71
82
(if (undefined? y)
72
83
(simplify-texpr x)
Original file line number Diff line number Diff line change 75
75
(is (= '[Console prototype log]
76
76
(-> (ana/resolve-extern '[console log] externs) :resolved )))
77
77
(is (= '[undefined]
78
- (-> (ana/resolve-extern '[undefined] externs) :resolved )))))
78
+ (-> (ana/resolve-extern '[undefined] externs) :resolved )))
79
+ (is (= '[webCrypto Crypto prototype subtle]
80
+ (-> (ana/resolve-extern '[crypto subtle] externs) :resolved )))))
79
81
80
82
(comment
81
83
(clojure.test/test-vars [#'test-resolve-extern])
You can’t perform that action at this time.
0 commit comments