fix cljs compilation broken in 0.19.3

This commit is contained in:
Imre Kószó 2022-08-05 20:45:21 +02:00
parent bf6e6c4413
commit 1c209146bf
5 changed files with 77 additions and 57 deletions

1
.gitignore vendored
View file

@ -17,5 +17,6 @@ pom.xml.asc
.nrepl-port .nrepl-port
.cpcache/ .cpcache/
.clj-kondo/*/ .clj-kondo/*/
/cljs-test-runner-out/
# End of https://www.toptal.com/developers/gitignore/api/clojure # End of https://www.toptal.com/developers/gitignore/api/clojure

33
bb.edn
View file

@ -2,29 +2,48 @@
:paths ["src" "test"] :paths ["src" "test"]
:tasks :tasks
{:init {:requires ([clojure.string :as str])
:init
(do (do
(defn kaocha [alias args] (defn kaocha [alias args]
(apply shell "bin/kaocha" alias args))) (apply shell "bin/kaocha" alias args))
test-9 (defn test-cljs [alias args]
(apply clojure (str/join ["-M:test:cljs-test-runner" alias]) args)))
test-clj-9
{:task (kaocha :clj-1-9 *command-line-args*)} {:task (kaocha :clj-1-9 *command-line-args*)}
test-10 test-clj-10
{:task (kaocha :clj-1-10 *command-line-args*)} {:task (kaocha :clj-1-10 *command-line-args*)}
test-11 test-clj-11
{:task (kaocha :clj-1-11 *command-line-args*)} {:task (kaocha :clj-1-11 *command-line-args*)}
test-clj test-clj
{:task (doseq [alias [:clj-1-9 :clj-1-10 :clj-1-11]] {:depends [test-clj-9 test-clj-10 test-clj-11]}
(kaocha alias *command-line-args*))}
test-cljs-9
{:task (test-cljs :clj-1-9 *command-line-args*)}
test-cljs-10
{:task (test-cljs :clj-1-10 *command-line-args*)}
test-cljs-11
{:task (test-cljs :clj-1-11 *command-line-args*)}
test-cljs
{:depends [#_test-cljs-9 test-cljs-10 test-cljs-11]}
test-bb test-bb
{:requires ([clojure.test :as t] {:requires ([clojure.test :as t]
[net.cgrand.xforms-test]) [net.cgrand.xforms-test])
:task (t/run-tests 'net.cgrand.xforms-test)} :task (t/run-tests 'net.cgrand.xforms-test)}
test-all
{:depends [test-bb test-clj test-cljs]}
perf-bb perf-bb
{:requires ([net.cgrand.xforms :as x]) {:requires ([net.cgrand.xforms :as x])
:task :task

View file

@ -25,4 +25,8 @@
:kaocha :kaocha
{:extra-deps {lambdaisland/kaocha {:mvn/version "1.69.1069"}} {:extra-deps {lambdaisland/kaocha {:mvn/version "1.69.1069"}}
:main-opts ["-m" "kaocha.runner"]}}} :main-opts ["-m" "kaocha.runner"]}
:cljs-test-runner
{:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}}
:main-opts ["-m" "cljs-test-runner.main"]}}}

View file

@ -7,12 +7,18 @@
:clj (:require [net.cgrand.macrovich :as macros])) :clj (:require [net.cgrand.macrovich :as macros]))
(:refer-clojure :exclude [some reduce reductions into count for partition (:refer-clojure :exclude [some reduce reductions into count for partition
str last keys vals min max drop-last take-last str last keys vals min max drop-last take-last
sort sort-by time satisfies?]) sort sort-by time #?@(:bb [] :clj [satisfies?])])
(:require [#?(:clj clojure.core :cljs cljs.core) :as core] (:require [#?(:clj clojure.core :cljs cljs.core) :as core]
[net.cgrand.xforms.rfs :as rf] [net.cgrand.xforms.rfs :as rf]
#?(:clj [clojure.core.protocols])) #?(:clj [clojure.core.protocols]))
#?(:cljs (:import [goog.structs Queue]))) #?(:cljs (:import [goog.structs Queue])))
(defn- pair? [x] (and (vector? x) (= 2 (core/count x))))
(let [kw-or-& #(or (keyword? %) (= '& %))]
(defn destructuring-pair? [x]
(and (pair? x)
(not (kw-or-& (first x))))))
(macros/deftime (macros/deftime
(defn- no-user-meta? [x] (defn- no-user-meta? [x]
@ -28,12 +34,6 @@
x# x#
(unreduced-> (-> x# ~expr) ~@exprs))))) (unreduced-> (-> x# ~expr) ~@exprs)))))
(defn- pair? [x] (and (vector? x) (= 2 (core/count x))))
(let [kw-or-& #(or (keyword? %) (= '& %))]
(defn- destructuring-pair? [x]
(and (pair? x)
(not (kw-or-& (first x))))))
(defmacro for (defmacro for
"Like clojure.core/for with the first expression being replaced by % (or _). Returns a transducer. "Like clojure.core/for with the first expression being replaced by % (or _). Returns a transducer.
When the first expression is not % (or _) returns an eduction." When the first expression is not % (or _) returns an eduction."
@ -130,12 +130,7 @@
;; Workaround clojure.core/satisfies? being slow in Clojure ;; Workaround clojure.core/satisfies? being slow in Clojure
;; see https://ask.clojure.org/index.php/3304/make-satisfies-as-fast-as-a-protocol-method-call ;; see https://ask.clojure.org/index.php/3304/make-satisfies-as-fast-as-a-protocol-method-call
#?(:cljs #?(:bb nil
(def satisfies? core/satisfies?)
:bb
(def satisfies? core/satisfies?)
:clj :clj
(defn fast-satisfies?-fn (defn fast-satisfies?-fn
"Ported from https://github.com/clj-commons/manifold/blob/37658e91f836047a630586a909a2e22debfbbfc6/src/manifold/utils.clj#L77-L89" "Ported from https://github.com/clj-commons/manifold/blob/37658e91f836047a630586a909a2e22debfbbfc6/src/manifold/utils.clj#L77-L89"
@ -155,7 +150,7 @@
#?(:cljs #?(:cljs
(defn kvreducible? [coll] (defn kvreducible? [coll]
(satisfies? core/IKVReduce coll)) (satisfies? IKVReduce coll))
:clj :clj
(let [satisfies-ikvreduce? #?(:bb #(satisfies? clojure.core.protocols/IKVReduce %) (let [satisfies-ikvreduce? #?(:bb #(satisfies? clojure.core.protocols/IKVReduce %)

View file

@ -97,41 +97,42 @@
#?(:bb nil ;; babashka doesn't currently support calling iterator on range type #?(:bb nil ;; babashka doesn't currently support calling iterator on range type
:clj :clj
(deftest iterator (do
(is (true? (.hasNext (x/iterator x/count (.iterator ^java.lang.Iterable (range 5)))))) (deftest iterator
(is (is (= [5] (iterator-seq (x/iterator x/count (.iterator ^java.lang.Iterable (range 5))))))) (is (true? (.hasNext (x/iterator x/count (.iterator ^java.lang.Iterable (range 5))))))
(is (= [[0 1] [1 2] [2 3] [3 4] [4]] (iterator-seq (x/iterator (x/partition 2 1 nil) (.iterator ^java.lang.Iterable (range 5))))))) (is (is (= [5] (iterator-seq (x/iterator x/count (.iterator ^java.lang.Iterable (range 5)))))))
(is (= [[0 1] [1 2] [2 3] [3 4] [4]] (iterator-seq (x/iterator (x/partition 2 1 nil) (.iterator ^java.lang.Iterable (range 5)))))))
(deftest window-by-time
(is (= (into (deftest window-by-time
[] (is (= (into
(x/window-by-time :ts 4 []
(fn (x/window-by-time :ts 4
([] clojure.lang.PersistentQueue/EMPTY) (fn
([q] (vec q)) ([] clojure.lang.PersistentQueue/EMPTY)
([q x] (conj q x))) ([q] (vec q))
(fn [q _] (pop q))) ([q x] (conj q x)))
(map (fn [x] {:ts x}) (concat (range 0 2 0.5) (range 3 5 0.25)))) (fn [q _] (pop q)))
[[{:ts 0}] ; t = 0 (map (fn [x] {:ts x}) (concat (range 0 2 0.5) (range 3 5 0.25))))
[{:ts 0}] ; t = 0.25 [[{:ts 0}] ; t = 0
[{:ts 0} {:ts 0.5}] ; t = 0.5 [{:ts 0}] ; t = 0.25
[{:ts 0} {:ts 0.5}] ; t = 0.75 [{:ts 0} {:ts 0.5}] ; t = 0.5
[{:ts 0.5} {:ts 1.0}] ; t = 1.0 [{:ts 0} {:ts 0.5}] ; t = 0.75
[{:ts 0.5} {:ts 1.0}] ; t = 1.25 [{:ts 0.5} {:ts 1.0}] ; t = 1.0
[{:ts 1.0} {:ts 1.5}] ; t = 1.5 [{:ts 0.5} {:ts 1.0}] ; t = 1.25
[{:ts 1.0} {:ts 1.5}] ; t = 1.75 [{:ts 1.0} {:ts 1.5}] ; t = 1.5
[{:ts 1.5}] ; t = 2.0 [{:ts 1.0} {:ts 1.5}] ; t = 1.75
[{:ts 1.5}] ; t = 2.25 [{:ts 1.5}] ; t = 2.0
[] ; t = 2.5 [{:ts 1.5}] ; t = 2.25
[] ; t = 2.75 [] ; t = 2.5
[{:ts 3}] ; t = 3.0 [] ; t = 2.75
[{:ts 3} {:ts 3.25}] ; t = 3.25 [{:ts 3}] ; t = 3.0
[{:ts 3} {:ts 3.25} {:ts 3.5}] ; t = 3.5 [{:ts 3} {:ts 3.25}] ; t = 3.25
[{:ts 3} {:ts 3.25} {:ts 3.5} {:ts 3.75}] ; t = 3.75 [{:ts 3} {:ts 3.25} {:ts 3.5}] ; t = 3.5
[{:ts 3.25} {:ts 3.5} {:ts 3.75} {:ts 4.0}] ; t = 4.0 [{:ts 3} {:ts 3.25} {:ts 3.5} {:ts 3.75}] ; t = 3.75
[{:ts 3.5} {:ts 3.75} {:ts 4.0} {:ts 4.25}] ; t = 4.25 [{:ts 3.25} {:ts 3.5} {:ts 3.75} {:ts 4.0}] ; t = 4.0
[{:ts 3.75} {:ts 4.0} {:ts 4.25} {:ts 4.5}] ; t = 4.5 [{:ts 3.5} {:ts 3.75} {:ts 4.0} {:ts 4.25}] ; t = 4.25
[{:ts 4.0} {:ts 4.25} {:ts 4.5} {:ts 4.75}]])))) ; t = 4.75 [{:ts 3.75} {:ts 4.0} {:ts 4.25} {:ts 4.5}] ; t = 4.5
[{:ts 4.0} {:ts 4.25} {:ts 4.5} {:ts 4.75}]]))))) ; t = 4.75
(deftest do-not-kvreduce-vectors (deftest do-not-kvreduce-vectors
(is (= {0 nil 1 nil} (x/into {} (x/for [[k v] %] [k v]) [[0] [1]]))) (is (= {0 nil 1 nil} (x/into {} (x/for [[k v] %] [k v]) [[0] [1]])))