Skip to content

Commit 40f7f6b

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

2 files changed

Lines changed: 14 additions & 3 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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;; You must not remove this notice, or any other, from this software.
88

99
(ns cljs.walk-test
10-
(:require [cljs.test :refer-macros [deftest testing is]]
10+
(:require [cljs.test :refer-macros [deftest testing is are]]
1111
[clojure.walk :as w]))
1212

1313
(deftest t-prewalk-replace
@@ -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)