Skip to content

Commit 516564e

Browse files
committed
* split number? into js-number? and bigint? checks
* emit BigInt as JS * switch to js/Number.isNaN instead of js/isNaN
1 parent df04ee2 commit 516564e

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@
251251
(instance? js/Array x)))
252252

253253
(defn ^boolean number?
254-
"Returns true if x is a JavaScript number."
254+
"Returns true if x is a JavaScript Number or BigInt"
255255
[x]
256-
(cljs.core/number? x))
256+
(or (cljs.core/js-number? x)
257+
(cljs.core/bigint? x)))
257258

258259
(defn not
259260
"Returns true if x is logical false, false otherwise."
@@ -2313,7 +2314,7 @@ reduces them without incurring seq initialization"
23132314
"Returns true if n is a JavaScript number with no decimal part."
23142315
[n]
23152316
(and (number? n)
2316-
(not ^boolean (js/isNaN n))
2317+
(not ^boolean (js/Number.isNaN n))
23172318
(not (identical? n js/Infinity))
23182319
(== (js/parseFloat n) (js/parseInt n 10))))
23192320

@@ -10509,10 +10510,10 @@ reduces them without incurring seq initialization"
1050910510
(number? obj)
1051010511
(-write writer
1051110512
(cond
10512-
^boolean (js/isNaN obj) "##NaN"
10513+
^boolean (js/Number.isNaN obj) "##NaN"
1051310514
(identical? obj js/Number.POSITIVE_INFINITY) "##Inf"
1051410515
(identical? obj js/Number.NEGATIVE_INFINITY) "##-Inf"
10515-
:else (str obj)))
10516+
:else (str obj (when (bigint? obj) "N"))))
1051610517

1051710518
(object? obj)
1051810519
(do
@@ -12211,7 +12212,7 @@ reduces them without incurring seq initialization"
1221112212
(defn ^boolean NaN?
1221212213
"Returns true if num is NaN, else false"
1221312214
[val]
12214-
(js/isNaN val))
12215+
(js/Number.isNaN val))
1221512216

1221612217
(defn ^:private parsing-err
1221712218
"Construct message for parsing for non-string parsing error"

src/main/clojure/cljs/compiler.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@
345345
(defmethod emit-constant* BigDecimal [x] (emits (.doubleValue ^BigDecimal x))))
346346

347347
#?(:clj
348-
(defmethod emit-constant* clojure.lang.BigInt [x] (emits (.doubleValue ^clojure.lang.BigInt x))))
348+
(defmethod emit-constant* clojure.lang.BigInt [x]
349+
(emits "(" (.toString ^clojure.lang.BigInt x) "n)")))
349350

350351
(defmethod emit-constant* #?(:clj String :cljs js/String) [x]
351352
(emits (wrap-in-double-quotes (escape-string x))))

src/main/clojure/cljs/core.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,12 @@
10071007
`(let [c# ~c x# ~x]
10081008
(~'js* "(~{} instanceof ~{})" x# c#)))))
10091009

1010-
(core/defmacro number? [x]
1010+
(core/defmacro js-number? [x]
10111011
(bool-expr (core/list 'js* "typeof ~{} === 'number'" x)))
10121012

1013+
(core/defmacro bigint? [x]
1014+
(bool-expr (core/list 'js* "typeof ~{} === 'bigint'" x)))
1015+
10131016
(core/defmacro symbol? [x]
10141017
(bool-expr `(instance? Symbol ~x)))
10151018

0 commit comments

Comments
 (0)