(analyze-file f)
(analyze-file f opts)
(analyze-file f skip-cache opts)
Given a java.io.File, java.net.URL or a string identifying a resource on the
classpath attempt to analyze it.
This function side-effects the ambient compilation environment
`cljs.env/*compiler*` to aggregate analysis information. opts argument is
compiler options, if :cache-analysis true will cache analysis to
":output-dir/some/ns/foo.cljs.cache.edn". This function does not return a
meaningful value.
Source
(defn analyze-file
"Given a java.io.File, java.net.URL or a string identifying a resource on the
classpath attempt to analyze it.
This function side-effects the ambient compilation environment
`cljs.env/*compiler*` to aggregate analysis information. opts argument is
compiler options, if :cache-analysis true will cache analysis to
\":output-dir/some/ns/foo.cljs.cache.edn\". This function does not return a
meaningful value."
([f]
(analyze-file f
(when env/*compiler*
(:options @env/*compiler*))))
([f opts]
(analyze-file f false opts))
([f skip-cache opts]
(binding [*file-defs* (atom #{})
*unchecked-if* false
*unchecked-arrays* false
*cljs-warnings* *cljs-warnings*]
(let [output-dir (util/output-directory opts)
res (cond
(instance? File f) f
(instance? URL f) f
(re-find #"^file://" f) (URL. f)
:else (io/resource f))]
(assert res (str "Can't find " f " in classpath"))
(ensure
(let [ns-info (parse-ns res)
path (if (instance? File res)
(.getPath ^File res)
(.getPath ^URL res))
cache (when (:cache-analysis opts)
(cache-file res ns-info output-dir))]
(when-not (get-in @env/*compiler* [::namespaces (:ns ns-info) :defs])
(if (or skip-cache (not cache) (requires-analysis? res output-dir))
(binding [*cljs-ns* 'cljs.user
*cljs-file* path
reader/*alias-map* (or reader/*alias-map* {})]
(when (or *verbose* (:verbose opts))
(util/debug-prn "Analyzing" (str res)))
(let [env (assoc (empty-env) :build-options opts)
ns (with-open [rdr (io/reader res)]
(loop [ns nil forms (seq (forms-seq* rdr (util/path res)))]
(if forms
(let [form (first forms)
env (assoc env :ns (get-namespace *cljs-ns*))
ast (analyze env form nil opts)]
(cond
(= (:op ast) :ns)
(recur (:name ast) (next forms))
(and (nil? ns) (= (:op ast) :ns*))
(recur (gen-user-ns res) (next forms))
:else
(recur ns (next forms))))
ns)))]
(when (and cache (true? (:cache-analysis opts)))
(write-analysis-cache ns cache res))))
(try
(read-analysis-cache cache res opts)
(catch Throwable e
(analyze-file f true opts)))))))))))