File tree 4 files changed +38
-9
lines changed
4 files changed +38
-9
lines changed Original file line number Diff line number Diff line change 3542
3542
(list* '. dot-form) " with classification "
3543
3543
(classify-dot-form dot-form))))))
3544
3544
3545
+ (defn js-global?
3546
+ " Return true if the expr is a JS global"
3547
+ [expr]
3548
+ (and (= 'js (:ns expr))
3549
+ (some? (get-in (get-externs ) [(-> (:name expr) name symbol)]))))
3550
+
3545
3551
(defn analyze-dot [env target field member+ form]
3546
3552
(let [v [target field member+]
3547
3553
{:keys [dot-action target method field args]} (build-dot-form v)
3550
3556
form-meta (meta form)
3551
3557
target-tag (:tag targetexpr)
3552
3558
prop (or field method)
3553
- tag (or (:tag form-meta)
3554
- (and (js-tag? target-tag)
3555
- (vary-meta (normalize-js-tag target-tag)
3556
- update-in [:prefix ] (fnil conj '[Object]) prop))
3557
- nil )]
3559
+ tag (if (js-global? targetexpr)
3560
+ ; ; we have a known global, don't treat as instance of some type
3561
+ (with-meta 'js {:prefix [(-> targetexpr :name name symbol) prop]})
3562
+ (or (:tag form-meta)
3563
+ (and (js-tag? target-tag)
3564
+ (vary-meta (normalize-js-tag target-tag)
3565
+ update-in [:prefix ] (fnil conj '[Object]) prop))
3566
+ nil ))]
3558
3567
(when (and (not= 'constructor prop)
3559
3568
(not (string/starts-with? (str prop) " cljs$" ))
3560
3569
(not (-> prop meta :protocol-prop )))
Original file line number Diff line number Diff line change 641
641
642
642
(defn safe-test? [env e]
643
643
(let [tag (ana/infer-tag env e)]
644
- (or (#{' boolean ' seq} tag) (truthy-constant? e))))
644
+ (or ('#{ boolean seq js/Boolean } tag) (truthy-constant? e))))
645
645
646
646
(defmethod emit* :if
647
647
[{:keys [test then else env unchecked]}]
Original file line number Diff line number Diff line change 432
432
(get 'React)
433
433
(find 'Component) first meta)
434
434
435
+ (info (externs-map ) '[Number])
435
436
(-> (info (externs-map ) '[Number isNaN]) :ret-tag ) ; ; => boolean
436
437
)
Original file line number Diff line number Diff line change 48
48
(find 'HTMLDocument) first meta)]
49
49
(is (= 'Document (:super info)))))
50
50
51
- ; ; TODO:
52
- ; ; analyze (.isNaN js/NaN 1)
53
- ; ; node :tag should be js/Boolean
51
+ (deftest test-number-infer-test
52
+ (let [cenv (env/default-compiler-env )
53
+ aenv (ana/empty-env )]
54
+ (is (= (env/with-compiler-env cenv
55
+ (:tag (ana/analyze aenv '(.isNaN js/Number 1 ))))
56
+ 'js/Boolean))))
57
+
58
+ ; ; TODO: js/subtle.crypto
54
59
55
60
(comment
56
61
62
+ (externs/info
63
+ (::ana/externs @(env/default-compiler-env ))
64
+ '[Number])
65
+
66
+ (externs/info
67
+ (::ana/externs @(env/default-compiler-env ))
68
+ '[Number isNaN])
69
+
57
70
; ; js/Boolean
58
71
(env/with-compiler-env (env/default-compiler-env )
59
72
(ana/js-tag '[Number isNaN] :ret-tag ))
60
73
74
+ ; ; js
75
+ (let [cenv (env/default-compiler-env )
76
+ aenv (ana/empty-env )]
77
+ (->> (env/with-compiler-env cenv
78
+ (:tag (ana/analyze aenv '(.isNaN js/Number 1 ))))))
79
+
61
80
(externs/parse-externs
62
81
(externs/resource->source-file (io/resource " goog/object/object.js" )))
63
82
You can’t perform that action at this time.
0 commit comments