Skip to content

Commit badffaf

Browse files
committed
new ns - cljs.analyzer.utils, make looking at the AST more fun
1 parent eb9a6dc commit badffaf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/clj/cljs/analyzer/utils.clj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(ns cljs.analyzer.utils
2+
(:require [cljs.analyzer :as ana]))
3+
4+
(defn simplify-env [_ {:keys [op] :as ast}]
5+
(let [env (:env ast)
6+
ast (if (= op :fn)
7+
(assoc ast :methods
8+
(map #(simplify-env nil %) (:methods ast)))
9+
ast)]
10+
(assoc (dissoc ast :env)
11+
:env {:context (:context env)})))
12+
13+
(defn elide-children [_ ast]
14+
(dissoc ast :children))
15+
16+
(defn to-ast
17+
([form] (to-ast 'cljs.user form))
18+
([ns form]
19+
(let [env (assoc-in (ana/empty-env) [:ns :name] ns)]
20+
(binding [ana/*passes* [elide-children simplify-env ana/infer-type]]
21+
(ana/analyze env form)))))
22+
23+
(comment
24+
(require '[clojure.pprint :as pp])
25+
(pp/pprint (to-ast '(defn foo [a b] (+ a b))))
26+
)

0 commit comments

Comments
 (0)