Skip to content

Commit d1b1481

Browse files
committed
export some obviously useful utilities to cljs.analyzer.api
1 parent 78c882f commit d1b1481

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/clj/cljs/analyzer/api.clj

+53
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,59 @@
1212
(:require [cljs.env :as env]
1313
[cljs.analyzer :as ana]))
1414

15+
;; =============================================================================
16+
17+
(defn empty-env
18+
"Creates an empty analysis environment."
19+
[]
20+
(ana/empty-env))
21+
22+
(defn analyze
23+
"Given an environment, a map containing {:locals (mapping of names to bindings), :context
24+
(one of :statement, :expr, :return), :ns (a symbol naming the
25+
compilation ns)}, and form, returns an expression object (a map
26+
containing at least :form, :op and :env keys). If expr has any (immediately)
27+
nested exprs, must have :children [exprs...] entry. This will
28+
facilitate code walking without knowing the details of the op set."
29+
([env form] (ana/analyze env form nil))
30+
([env form name] (ana/analyze env form name nil))
31+
([env form name opts] (ana/analyze env form name opts)))
32+
33+
(defn forms-seq
34+
"Seq of Clojure/ClojureScript forms from rdr, a java.io.Reader. Optionally
35+
accepts a filename argument which will be used in any emitted errors."
36+
([rdr] (ana/forms-seq* rdr nil))
37+
([rdr filename] (ana/forms-seq* rdr filename)))
38+
39+
(defn parse-ns
40+
"Helper for parsing only the essential namespace information from a
41+
ClojureScript source file and returning a cljs.closure/IJavaScript compatible
42+
map _not_ a namespace AST node.
43+
44+
By default does not load macros or perform any analysis of dependencies. If
45+
opts parameter provided :analyze-deps and :load-macros keys their values will
46+
be used for *analyze-deps* and *load-macros* bindings respectively. This
47+
function does _not_ side-effect the ambient compilation environment unless
48+
requested via opts where :restore is false."
49+
([src] (ana/parse-ns src nil nil))
50+
([src opts] (ana/parse-ns src nil opts))
51+
([src dest opts] (ana/parse-ns src dest opts)))
52+
53+
(defn analyze-file
54+
"Given a java.io.File, java.net.URL or a string identifying a resource on the
55+
classpath attempt to analyze it.
56+
57+
This function side-effects the ambient compilation environment
58+
`cljs.env/*compiler*` to aggregate analysis information. opts argument is
59+
compiler options, if :cache-analysis true will cache analysis to
60+
\":output-dir/some/ns/foo.cljs.cache.edn\". This function does not return a
61+
meaningful value."
62+
([f] (ana/analyze-file f nil))
63+
([f opts] (ana/analyze-file f opts)))
64+
65+
;; =============================================================================
66+
;; Main API
67+
1568
(defn resolve
1669
"Given an analysis environment resolve a var. Analogous to
1770
clojure.core/resolve"

0 commit comments

Comments
 (0)