Skip to content

Commit afde265

Browse files
committed
deprecate cljs.analyzer/forms-seq instead of removing to not break
existing usage. add cljs.analyzer/forms-seq* which does the right thing and accepts a _reader_. Prep work for CLJS-841 - now forms-seq* using code can close the reader itself under error conditions.
1 parent 7224cd7 commit afde265

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,10 +1947,34 @@
19471947
(instance? File x) (.getAbsolutePath ^File x)
19481948
:default (str x)))
19491949

1950+
(defn forms-seq*
1951+
"Seq of Clojure/ClojureScript forms from rdr, a java.io.Reader. Optionally
1952+
accepts a filename argument which will be used in any emitted errors."
1953+
([^Reader rdr] (forms-seq* rdr nil))
1954+
([^Reader rdr filename]
1955+
(let [pbr (readers/indexing-push-back-reader
1956+
(PushbackReader. rdr) 1 filename)
1957+
data-readers tags/*cljs-data-readers*
1958+
forms-seq_
1959+
(fn forms-seq_ []
1960+
(lazy-seq
1961+
(let [eof-sentinel (Object.)
1962+
form (binding [*ns* (create-ns *cljs-ns*)
1963+
reader/*data-readers* data-readers
1964+
reader/*alias-map*
1965+
(apply merge
1966+
((juxt :requires :require-macros)
1967+
(get-namespace *cljs-ns*)))]
1968+
(reader/read pbr nil eof-sentinel))]
1969+
(if (identical? form eof-sentinel)
1970+
(.close rdr)
1971+
(cons form (forms-seq_))))))]
1972+
(forms-seq_))))
1973+
19501974
(defn forms-seq
1951-
"Seq of Clojure/ClojureScript forms from [f], which can be anything for which
1952-
`clojure.java.io/reader` can produce a `java.io.Reader`. Optionally accepts a [filename]
1953-
argument, which the reader will use in any emitted errors."
1975+
"DEPRECATED: Seq of Clojure/ClojureScript forms from [f], which can be anything
1976+
for which `clojure.java.io/reader` can produce a `java.io.Reader`. Optionally
1977+
accepts a [filename] argument, which the reader will use in any emitted errors."
19541978
([f] (forms-seq f (source-path f)))
19551979
([f filename] (forms-seq f filename false))
19561980
([f filename return-reader?]

0 commit comments

Comments
 (0)