Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reflection warning in epsilon util, fixes #230 #237

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ pom.xml.asc
cljs-test-runner-out/
nashorn_code_cache/
/bin/release/
.cache
.calva
54 changes: 22 additions & 32 deletions src/meander/util/epsilon.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
(:require-macros [meander.util.epsilon
:refer [__disj
__dissoc
__nth]])))
__nth]]))
(:import #?(:bb ()
:clj (cljs.tagged_literals JSValue))))

#?(:clj (set! *warn-on-reflection* true))

(defn cljs-env?
"true if compiling ClojureScript or in a ClojureScript setting,
Expand Down Expand Up @@ -717,40 +721,26 @@
(symbol (name (:name cljs-ns)) (name sym)))))
sym)))

#?(:clj
(try
(let [c (Class/forName "cljs.tagged_literals.JSValue")]
(defn js-value? [x]
(instance? c x)))
(catch ClassNotFoundException _
(defn js-value? [x]
false)))
#?(:bb
(defn js-value? [_x] false)
:clj
(defn js-value? [x] (instance? JSValue x))
:cljs
(defn js-value? [x]
false))
(defn js-value? [_x] false))

#?(: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)))
#?(:bb
(defn make-js-value [x] x)
:clj
(defn make-js-value [x] (new JSValue x))
:cljs
(defn make-js-value [x] x))

#?(:clj
(defmacro val-op
{:private true}
[x]
(try
(Class/forName "cljs.tagged_literals.JSValue")
`(.val ^"cljs.tagged_literals.JSValue" ~x)
(catch ClassNotFoundException _
`(.val ~x)))))

#?(:clj
#?(:bb
(defn val-of-js-value [x] x)
:clj
(defn val-of-js-value [x]
(if (js-value? x) (val-op x) x)))
(if (js-value? x)
(.-val ^JSValue x)
x))
:cljs
(defn val-of-js-value [x] x))