Skip to content

Commit 9a1a92a

Browse files
committed
permit conditional reading only in cljc files
1 parent d17f911 commit 9a1a92a

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/clj/cljs/analyzer.clj

+5-3
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,9 @@
19641964
([^Reader rdr] (forms-seq* rdr nil))
19651965
([^Reader rdr filename]
19661966
{:pre [(instance? Reader rdr)]}
1967-
(let [pbr (readers/indexing-push-back-reader
1967+
(let [opts (when (and filename (= (util/ext filename) "cljc"))
1968+
{:read-cond :allow :features #{:cljs}})
1969+
pbr (readers/indexing-push-back-reader
19681970
(PushbackReader. rdr) 1 filename)
19691971
data-readers tags/*cljs-data-readers*
19701972
forms-seq_
@@ -1977,7 +1979,7 @@
19771979
(apply merge
19781980
((juxt :requires :require-macros)
19791981
(get-namespace *cljs-ns*)))]
1980-
(reader/read pbr nil eof-sentinel))]
1982+
(reader/read pbr nil eof-sentinel opts nil))]
19811983
(if (identical? form eof-sentinel)
19821984
(.close rdr)
19831985
(cons form (forms-seq_))))))]
@@ -2161,7 +2163,7 @@
21612163
(util/debug-prn "Analyzing" (str res)))
21622164
(let [env (assoc (empty-env) :build-options opts)
21632165
ns (with-open [rdr (io/reader res)]
2164-
(loop [ns nil forms (seq (forms-seq* rdr))]
2166+
(loop [ns nil forms (seq (forms-seq* rdr (util/path res)))]
21652167
(if forms
21662168
(let [form (first forms)
21672169
env (assoc env :ns (get-namespace *cljs-ns*))

src/clj/cljs/compiler.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@
10131013
:gen-line 0}))]
10141014
(emitln (compiled-by-string opts))
10151015
(with-open [rdr (io/reader src)]
1016-
(loop [forms (ana/forms-seq* rdr)
1016+
(loop [forms (ana/forms-seq* rdr (util/path src))
10171017
ns-name nil
10181018
deps nil]
10191019
(if (seq forms)

src/clj/cljs/util.clj

+11-6
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,20 @@
105105
(defn ^String filename [^File f]
106106
(.getName f))
107107

108-
(defn ^String path [^URL url]
109-
(.getPath url))
108+
(defn ^String path [x]
109+
{:pre [(or (file? x) (url? x))]}
110+
(cond
111+
(file? x) (.getAbsolutePath ^File x)
112+
(url? x) (.getPath ^URL x)))
110113

111114
(defn ^String ext
112-
"Given a file or url return the file extension."
113-
[f]
115+
"Given a file, url or string return the file extension."
116+
[x]
117+
{:pre [(or (file? x) (url? x) (string? x))]}
114118
(let [s (cond
115-
(file? f) (filename f)
116-
(url? f) (path f))]
119+
(file? x) (filename x)
120+
(url? x) (path x)
121+
(string? x) x)]
117122
(last (string/split s #"\."))))
118123

119124
(defn ^String get-name

0 commit comments

Comments
 (0)