Skip to content

Commit b8fec2f

Browse files
committed
compat
1 parent ecd23bd commit b8fec2f

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ SCI is used in [babashka](https://github.com/babashka/babashka),
1212

1313
## Unreleased
1414

15+
- Add `ns` field to `sci.lang.Var` for compatibility with code that accesses `.ns` on vars
16+
- `copy-var` and `copy-var*` now preserve `:private` metadata
1517
- Add `proxy-super`, `proxy-call-with-super`, `update-proxy` and `proxy-mappings`
1618
- Support functional interface (FI) adaptation for instance targets (e.g. `(let [^Predicate p even?] (.test p 42))`)
1719
- Infer type tags from let binding values to binding names (e.g. `(let [^String s "foo", q s] (.length q))`)

src/sci/core.cljc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@
8282
m# (-> var# meta)
8383
name# (or ~nm (:name m#))
8484
tag# (:tag m#)
85+
private# (:private m#)
8586
new-m# (cond-> {:doc (:doc m#)
8687
:name name#
8788
:arglists (:arglists m#)
8889
:ns ns#}
89-
tag# (assoc :tag tag#))]
90+
tag# (assoc :tag tag#)
91+
private# (assoc :private private#))]
9092
(cond (:dynamic m#)
9193
(new-dynamic-var name# val# new-m#)
9294
(or (:macro m#) (:sci/macro m#))
@@ -102,13 +104,15 @@
102104
arglists (:arglists m)
103105
dynamic (:dynamic m)
104106
macro (:macro m)
107+
private (:private m)
105108
tag (:tag m)
106109
new-m (cond-> {:ns sci-ns
107110
:name nm}
108111
macro (assoc :macro true)
109112
doc (assoc :doc doc)
110113
arglists (assoc :arglists arglists)
111114
dynamic (assoc :dynamic dynamic)
115+
private (assoc :private private)
112116
tag (assoc :tag tag))]
113117
(new-var nm @clojure-var new-m)))
114118

src/sci/impl/copy_vars.cljc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@
5555
:cljs (atom nil))])]
5656
(macros/? :clj #?(:clj (let [m (meta the-var)
5757
dyn (:dynamic m)
58+
private (:private m)
5859
arglists (:arglists m)
5960
tag (:tag m)]
6061
(cond-> (if elide-vars {} {:doc (:doc m)})
6162
dyn (assoc :dynamic dyn)
63+
private (assoc :private private)
6264
(if elide-vars false arglists)
6365
(assoc :arglists (list 'quote (:arglists m)))
6466
tag (assoc :tag tag)

test/sci/core_test.cljc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,12 @@
13211321
(is (= "-------------------------\nfoo/do-twice\n([x])\nMacro\n" do-twice-doc))
13221322
(is (= "-------------------------\nfoo/always-foo\n([& _args])\n" always-foo-doc))))
13231323

1324+
(defn- private-fn [] :private)
1325+
1326+
(deftest copy-var-private-test
1327+
(is (true? (:private (meta (sci/copy-var private-fn (sci/create-ns 'foo)))))
1328+
"copy-var preserves :private metadata"))
1329+
13241330
(defn update-vals*
13251331
"Same as `update-vals` from clojure 1.11 but included here so tests
13261332
can run with older versions of Clojure/Script."

0 commit comments

Comments
 (0)