Skip to content

Commit fc0467f

Browse files
committed
* goog.string/contains does work, add test
* remove hint from NaN? * FIXME note about re-matches
1 parent 979715c commit fc0467f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12273,7 +12273,7 @@ reduces them without incurring seq initialization"
1227312273
(when (nil? NS_CACHE)
1227412274
(set! NS_CACHE (atom {})))
1227512275
(let [ns-str (str_ ns)
12276-
ns (if (not ^boolean (gstring/contains ns-str "$macros"))
12276+
ns (if (not (gstring/contains ns-str "$macros"))
1227712277
(symbol (str_ ns-str "$macros"))
1227812278
ns)
1227912279
the-ns (get @NS_CACHE ns)]
@@ -12297,7 +12297,7 @@ reduces them without incurring seq initialization"
1229712297
[x]
1229812298
(instance? goog.Uri x))
1229912299

12300-
(defn ^boolean NaN?
12300+
(defn NaN?
1230112301
"Returns true if num is NaN, else false"
1230212302
[val]
1230312303
(js/isNaN val))
@@ -12326,6 +12326,7 @@ reduces them without incurring seq initialization"
1232612326
[s]
1232712327
(if (string? s)
1232812328
(cond
12329+
;; FIXME: another cases worth thinking about
1232912330
^boolean (re-matches #"[\x00-\x20]*[+-]?NaN[\x00-\x20]*" s) ##NaN
1233012331
^boolean (re-matches
1233112332
#"[\x00-\x20]*[+-]?(Infinity|((\d+\.?\d*|\.\d+)([eE][+-]?\d+)?)[dDfF]?)[\x00-\x20]*"

src/test/clojure/cljs/compiler_tests.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@
382382
'[(if (.isNaN js/Number 1) true false)]))]
383383
(is (nil? (re-find #"truth_" code))))))
384384

385+
(deftest test-goog-lib-infer-boolean
386+
(testing "Can infer goog.string/contains returns boolean"
387+
(let [code (env/with-compiler-env (env/default-compiler-env)
388+
(compile-form-seq
389+
'[(ns test.foo
390+
(:require [goog.string :as gstring]))
391+
(if (gstring/contain "foobar" "foo") true false)]))]
392+
(is (nil? (re-find #"truth_" code))))))
393+
385394
;; CLJS-1225
386395

387396
(comment

src/test/clojure/cljs/type_inference_tests.clj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,22 @@
395395
(Html5History.)]
396396
{} true))))))
397397

398-
;; FIXME: infers any instead of boolean, nothing wrong w/ the externs parsing
399-
;; but this definitely does not work at the moment
400-
#_(deftest test-goog-infer
398+
(deftest test-goog-infer
401399
(is (= 'boolean
400+
(:tag (env/with-compiler-env (env/default-compiler-env)
401+
(ana/analyze-form-seq
402+
'[(ns test.foo
403+
(:require [goog.string :as gstring]))
404+
(gstring/contains "foobar" "foo")]
405+
{} true)))))
406+
;; FIXME: infers any instead of boolean, nothing wrong w/ the externs parsing
407+
;; but this definitely does not work at the moment
408+
#_(is (= 'boolean
402409
(:tag
403410
(env/with-compiler-env (env/default-compiler-env)
404411
(ana/analyze-form-seq
405412
'[(ns test.foo
406413
(:require [goog.object :as gobject]))
407414
(gobject/containsKey (js-object) "foo")]
408415
{} true))))))
416+

0 commit comments

Comments
 (0)