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 10561056 (and (empty? (next pre))
10571057 (not (contains? ret :info )))
10581058 (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')))
10601061 (or
10611062 ; ; then check for "static" property
10621063 (resolve-extern (next pre) externs' top
10721073 (assoc ret :resolved []))))
10731074
10741075 (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`
10771079 (let [tag (:tag info')]
10781080 (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
10801084 (assoc ret :resolved []))))
10811085
10821086 ; ; assume static property
Original file line number Diff line number Diff line change 6161 (and (= type :string-lit )
6262 (= " undefined" value)))
6363
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+
6474(defn simplify-texpr
6575 [texpr]
6676 (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))
7081 :pipe (let [[x y] (:children texpr)]
7182 (if (undefined? y)
7283 (simplify-texpr x)
Original file line number Diff line number Diff line change 7575 (is (= '[Console prototype log]
7676 (-> (ana/resolve-extern '[console log] externs) :resolved )))
7777 (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 )))))
7981
8082(comment
8183 (clojure.test/test-vars [#'test-resolve-extern])
You can’t perform that action at this time.
0 commit comments