Skip to content

Commit 76f5b82

Browse files
Port CLJS-2568: clojure.walk now retains metadata when walking lists and seqs
Co-authored-by: Alex Miller <alex.miller@cognitect.com>
1 parent 86d0fb5 commit 76f5b82

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/main/cljs/clojure/walk.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ the sorting function."}
4343
{:added "1.1"}
4444
[inner outer form]
4545
(cond
46-
(list? form) (outer (apply list (map inner form)))
46+
(list? form) (outer (with-meta (apply list (map inner form)) (meta form)))
4747
(map-entry? form)
4848
(outer (MapEntry. (inner (key form)) (inner (val form)) nil))
49-
(seq? form) (outer (doall (map inner form)))
49+
(seq? form) (outer (with-meta (doall (map inner form)) (meta form)))
5050
(record? form) (outer (reduce (fn [r x] (conj r (inner x))) form form))
5151
(coll? form) (outer (into (empty form) (map inner form)))
5252
:else (outer form)))

src/test/cljs/cljs/walk_test.cljs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,14 @@
8080
(let [coll [:html {:a ["b" 1]} ""]
8181
f (fn [e] (if (and (vector? e) (not (map-entry? e))) (apply list e) e))]
8282
(is (= (list :html {:a (list "b" 1)} "") (w/postwalk f coll)))))
83+
84+
(defrecord RM [a])
85+
(deftest retain-meta
86+
(let [m {:foo true}]
87+
(are [o] (= m (meta (w/postwalk identity (with-meta o m))))
88+
'(1 2)
89+
[1 2]
90+
#{1 2}
91+
{1 2}
92+
(map inc (range 3))
93+
(->RM 1))))

0 commit comments

Comments
 (0)