Skip to content

Commit 0516951

Browse files
frenchy64bronsa
authored andcommitted
TANAL-134 remove :init from :def's :children when absent
1 parent 5b79134 commit 0516951

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Changelog
22
========================================
3+
* Unreleased
4+
* TANAL-134: Remove :init from :def's :children when absent
35
* Release 1.0.0 on 18 Feb 2020
46
* Fixed docstrings
57
* Release 0.7.0 on 10 Dec 2018

src/main/clojure/clojure/tools/analyzer/passes/elide_meta.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@
7373
(if (= new-meta (:form meta))
7474
ast
7575
(assoc ast :meta (replace-meta meta new-meta)))
76-
(assoc (dissoc ast :meta) :children [:init]))
76+
(let [ast (dissoc ast :meta)]
77+
(if-let [new-children (not-empty (filterv (complement #{:meta}) (:children ast)))]
78+
(assoc ast :children new-children)
79+
(dissoc ast :children))))
7780
ast)))
7881

7982
(defn elide-meta

src/test/clojure/clojure/tools/analyzer/core_test.clj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,20 @@
183183
(let [i-ast (ast (1 2))]
184184
(is (= :invoke (-> i-ast :op)))
185185
(is (= 1 (-> i-ast :fn :form)))
186-
(is (= [2] (->> i-ast :args (mapv :form))))))
186+
(is (= [2] (->> i-ast :args (mapv :form)))))
187+
188+
(let [def-ast (ast (def a))]
189+
(is (= :def (-> def-ast :op)))
190+
(is (empty? (-> def-ast :children)))
191+
(is (nil? (:init def-ast))))
192+
193+
(let [def-ast (ast (def a nil))]
194+
(is (= :def (-> def-ast :op)))
195+
(is (= [:init] (:children def-ast)))
196+
(is (= :const (-> def-ast :init :op))))
197+
198+
(let [def-ast (ast (def a "doc" nil))]
199+
(is (= :def (-> def-ast :op)))
200+
(is (= [:meta :init] (:children def-ast)))
201+
(is (= "doc" (-> def-ast :doc)))
202+
(is (= :const (-> def-ast :init :op)))))

0 commit comments

Comments
 (0)