We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eb9a6dc commit badffafCopy full SHA for badffaf
src/clj/cljs/analyzer/utils.clj
@@ -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