Skip to content

Commit

Permalink
new ns - cljs.analyzer.utils, make looking at the AST more fun
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Nov 25, 2013
1 parent eb9a6dc commit badffaf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/clj/cljs/analyzer/utils.clj
@@ -0,0 +1,26 @@
(ns cljs.analyzer.utils
(:require [cljs.analyzer :as ana]))

(defn simplify-env [_ {:keys [op] :as ast}]
(let [env (:env ast)
ast (if (= op :fn)
(assoc ast :methods
(map #(simplify-env nil %) (:methods ast)))
ast)]
(assoc (dissoc ast :env)
:env {:context (:context env)})))

(defn elide-children [_ ast]
(dissoc ast :children))

(defn to-ast
([form] (to-ast 'cljs.user form))
([ns form]
(let [env (assoc-in (ana/empty-env) [:ns :name] ns)]
(binding [ana/*passes* [elide-children simplify-env ana/infer-type]]
(ana/analyze env form)))))

(comment
(require '[clojure.pprint :as pp])
(pp/pprint (to-ast '(defn foo [a b] (+ a b))))
)

0 comments on commit badffaf

Please sign in to comment.