|
1229 | 1229 | (defn ns->relpath [s] |
1230 | 1230 | (str (string/replace (munge s) \. \/) ".cljs")) |
1231 | 1231 |
|
1232 | | -(declare analyze-file) |
| 1232 | +(declare analyze-files) |
1233 | 1233 |
|
1234 | 1234 | (defn analyze-deps [deps] |
1235 | 1235 | (doseq [dep deps] |
1236 | 1236 | (when-not (:defs (@namespaces dep)) |
1237 | 1237 | (let [relpath (ns->relpath dep)] |
1238 | 1238 | (when (io/resource relpath) |
1239 | | - (analyze-file relpath)))))) |
| 1239 | + (analyze-files [relpath])))))) |
1240 | 1240 |
|
1241 | 1241 | (defmethod parse 'ns |
1242 | 1242 | [_ env [_ name & args :as form] _] |
|
1597 | 1597 | (set? form) (analyze-set env form name) |
1598 | 1598 | :else {:op :constant :env env :form form})))) |
1599 | 1599 |
|
1600 | | -(defn analyze-file |
1601 | | - ([f others] |
1602 | | - (let [res (if (= \/ (first f)) f (io/resource f))] |
1603 | | - (assert res (str "Can't find " f " in classpath")) |
1604 | | - (binding [*cljs-ns* 'cljs.user |
1605 | | - *cljs-file* (.getPath ^java.net.URL res)] |
1606 | | - (with-open [r (io/reader res)] |
1607 | | - (let [env {:ns (@namespaces *cljs-ns*) :context :statement :locals {}} |
1608 | | - pbr (clojure.lang.LineNumberingPushbackReader. r) |
1609 | | - eof (Object.)] |
1610 | | - (loop [asts [] |
1611 | | - r (read pbr false eof false) |
1612 | | - others others] |
1613 | | - (let [env (assoc env :ns (@namespaces *cljs-ns*))] |
1614 | | - (if (identical? eof r) |
1615 | | - (if (seq others) |
1616 | | - (recur (conj asts (analyze env (first others))) |
1617 | | - eof |
1618 | | - (rest others)) |
1619 | | - asts) |
1620 | | - (recur (conj asts (analyze env r)) |
1621 | | - (read pbr false eof false) |
1622 | | - others))))))))) |
1623 | | - ([f] |
1624 | | - (analyze-file f nil))) |
| 1600 | +(defn analyze-files |
| 1601 | + ([files others] |
| 1602 | + (letfn [(an [form] |
| 1603 | + (analyze {:ns (@namespaces *cljs-ns*) :context :statement :locals {}} |
| 1604 | + form))] |
| 1605 | + (binding [*cljs-ns* 'cljc.user] |
| 1606 | + (loop [asts [] |
| 1607 | + files files |
| 1608 | + others others] |
| 1609 | + (if (seq files) |
| 1610 | + (recur (let [f (first files) |
| 1611 | + res (if (= \/ (first f)) f (io/resource f))] |
| 1612 | + (assert res (str "Can't find " f " in classpath")) |
| 1613 | + (binding [*cljs-file* (.getPath ^java.net.URL res)] |
| 1614 | + (with-open [r (io/reader res)] |
| 1615 | + (let [pbr (clojure.lang.LineNumberingPushbackReader. r) |
| 1616 | + eof (Object.)] |
| 1617 | + (loop [asts asts |
| 1618 | + r (read pbr false eof false)] |
| 1619 | + (if (identical? eof r) |
| 1620 | + asts |
| 1621 | + (recur (conj asts (an r)) |
| 1622 | + (read pbr false eof false)))))))) |
| 1623 | + (rest files) |
| 1624 | + others) |
| 1625 | + (if (seq others) |
| 1626 | + (recur (conj asts (an (first others))) |
| 1627 | + nil |
| 1628 | + (rest others)) |
| 1629 | + asts)))))) |
| 1630 | + ([files] |
| 1631 | + (analyze-files files nil))) |
1625 | 1632 |
|
1626 | 1633 | (defn forms-seq |
1627 | 1634 | "Seq of forms in a Clojure or ClojureScript file." |
|
0 commit comments