Skip to content

Commit

Permalink
CLJS-1434: clojure.walk no longer preserves meta on vectors
Browse files Browse the repository at this point in the history
Remove redundant IMapEntry case which was capturing vectors and not preserving meta. Instead rely on coll?
  • Loading branch information
swannodette committed Aug 29, 2015
1 parent 961a25f commit 1e626dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/main/cljs/clojure/walk.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ the sorting function."}
{:added "1.1"}
[inner outer form]
(cond
(list? form) (outer (apply list (map inner form)))
(satisfies? IMapEntry form) (outer (vec (map inner form)))
(seq? form) (outer (doall (map inner form)))
(satisfies? IRecord form)
(outer (reduce (fn [r x] (conj r (inner x))) form form))
(coll? form) (outer (into (empty form) (map inner form)))
:else (outer form)))
(list? form) (outer (apply list (map inner form)))
(seq? form) (outer (doall (map inner form)))
(record? form) (outer (reduce (fn [r x] (conj r (inner x))) form form))
(coll? form) (outer (into (empty form) (map inner form)))
:else (outer form)))

(defn postwalk
"Performs a depth-first, post-order traversal of form. Calls f on
Expand Down
9 changes: 8 additions & 1 deletion src/test/cljs/clojure/walk_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@
(w/prewalk #(if (keyword? %) (str %) %) (Rec1. 1)))
"Mirror Clojure behavior")))


(deftest test-preserves-meta
(testing "Test preserves meta"
(is (= (-> (w/prewalk identity [1 (with-meta [1 2] {:foo 3})])
(nth 1) meta)
{:foo 3}))
(is (= (-> (w/postwalk identity [1 (with-meta [1 2] {:foo 3})])
(nth 1) meta)
{:foo 3}))))

0 comments on commit 1e626dd

Please sign in to comment.