From b23844d5fb1b0edbd8a2eff96524f740366e3700 Mon Sep 17 00:00:00 2001 From: Paul Rutledge Date: Sun, 23 Jul 2023 17:37:51 -0500 Subject: [PATCH] fix reflection warning without breaking ability to load meander.util.epsilon without clojurescript on the classpath --- .gitignore | 2 ++ src/meander/util/epsilon.cljc | 52 +++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index bf537d5a..e65bb61d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ nashorn_code_cache/ /bin/release/ .cache .calva +.idea/ +*.iml \ No newline at end of file diff --git a/src/meander/util/epsilon.cljc b/src/meander/util/epsilon.cljc index 5495fd8e..d45732ff 100644 --- a/src/meander/util/epsilon.cljc +++ b/src/meander/util/epsilon.cljc @@ -5,9 +5,7 @@ (:require-macros [meander.util.epsilon :refer [__disj __dissoc - __nth]])) - (:import #?(:bb () - :clj (cljs.tagged_literals JSValue)))) + __nth]]))) #?(:clj (set! *warn-on-reflection* true)) @@ -721,26 +719,40 @@ (symbol (name (:name cljs-ns)) (name sym))))) sym))) -#?(:bb - (defn js-value? [_x] false) - :clj - (defn js-value? [x] (instance? JSValue x)) +#?(:clj + (try + (let [c (Class/forName "cljs.tagged_literals.JSValue")] + (defn js-value? [x] + (instance? c x))) + (catch ClassNotFoundException _ + (defn js-value? [x] + false))) :cljs - (defn js-value? [_x] false)) + (defn js-value? [x] + false)) -#?(:bb - (defn make-js-value [x] x) - :clj - (defn make-js-value [x] (new JSValue x)) +#?(:clj + (try + (let [c (Class/forName "cljs.tagged_literals.JSValue") + s 'cljs.tagged_literals.JSValue] + (defn make-js-value [x] + (eval `(new ~s ~x)))) + (catch ClassNotFoundException _ + (defn make-js-value [x] + x))) :cljs (defn make-js-value [x] x)) -#?(:bb - (defn val-of-js-value [x] x) - :clj +#?(:clj + (defmacro val-op + {:private true} + [x] + (try + (Class/forName "cljs.tagged_literals.JSValue") + `(.val ^"cljs.tagged_literals.JSValue" ~x) + (catch ClassNotFoundException _ + nil)))) + +#?(:clj (defn val-of-js-value [x] - (if (js-value? x) - (.-val ^JSValue x) - x)) - :cljs - (defn val-of-js-value [x] x)) + (if (js-value? x) (val-op x) x)))