Skip to content

Commit ebee071

Browse files
committed
Always check .cljs before .cljc
1 parent 9a1a92a commit ebee071

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

src/clj/cljs/analyzer.clj

+9-9
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
(defmethod error-message :undeclared-ns
111111
[warning-type {:keys [ns-sym] :as info}]
112112
(str "No such namespace: " ns-sym
113-
", could not locate " (util/ns->relpath ns-sym :cljc)
114-
" or " (util/ns->relpath ns-sym :cljs)))
113+
", could not locate " (util/ns->relpath ns-sym :cljs)
114+
" or " (util/ns->relpath ns-sym :cljc)))
115115

116116
(defmethod error-message :dynamic
117117
[warning-type info]
@@ -1212,18 +1212,18 @@
12121212
(declare analyze-file)
12131213

12141214
(defn locate-src
1215-
"Given a namespace return the corresponding ClojureScript (.cljc or .cljs)
1215+
"Given a namespace return the corresponding ClojureScript (.cljs or .cljc)
12161216
resource on the classpath or file from the root of the build."
12171217
[ns]
12181218
(or (util/ns->source ns)
12191219
(let [rootp (when-let [root (:root @env/*compiler*)]
12201220
(.getPath ^File root))
1221-
cljcf (io/file rootp (util/ns->relpath ns :cljc))
1222-
cljsf (io/file rootp (util/ns->relpath ns :cljs))]
1223-
(if (and (.exists cljcf) (.isFile cljcf))
1224-
cljcf
1225-
(if (and (.exists cljsf) (.isFile cljsf))
1226-
cljsf)))))
1221+
cljsf (io/file rootp (util/ns->relpath ns :cljs))
1222+
cljcf (io/file rootp (util/ns->relpath ns :cljc))]
1223+
(if (and (.exists cljsf) (.isFile cljsf))
1224+
cljsf
1225+
(if (and (.exists cljcf) (.isFile cljcf))
1226+
cljcf)))))
12271227

12281228
(defn foreign-dep? [dep]
12291229
{:pre [(symbol? dep)]}

src/clj/cljs/closure.clj

+12-12
Original file line numberDiff line numberDiff line change
@@ -479,30 +479,30 @@
479479
(-compile uri (merge opts {:output-file js-file}))))
480480

481481
(defn cljs-source-for-namespace
482-
"Given a namespace return the corresponding source with either a .cljc or
483-
.cljs extension."
482+
"Given a namespace return the corresponding source with either a .cljs or
483+
.cljc extension."
484484
[ns]
485485
(let [path (-> (munge ns) (string/replace \. \/))
486-
relpath (str path ".cljc")]
486+
relpath (str path ".cljs")]
487487
(if-let [res (io/resource relpath)]
488488
{:relative-path relpath :uri res}
489-
(let [relpath (str path ".cljs")]
489+
(let [relpath (str path ".cljc")]
490490
(if-let [res (io/resource relpath)]
491491
{:relative-path relpath :uri res})))))
492492

493493
(defn source-for-namespace
494494
"Given a namespace and compilation environment return the relative path and
495495
uri of the corresponding source regardless of the source language extension:
496-
.cljc, .cljs, .js"
496+
.cljs, .cljc, .js"
497497
[ns compiler-env]
498498
(let [ns-str (str (comp/munge ns {}))
499499
path (string/replace ns-str \. \/)
500-
relpath (str path ".cljc")]
501-
(if-let [cljc-res (io/resource relpath)]
502-
{:relative-path relpath :uri cljc-res}
503-
(let [relpath (str path ".cljs")]
504-
(if-let [cljs-res (io/resource relpath)]
505-
{:relative-path relpath :uri cljs-res}
500+
relpath (str path ".cljs")]
501+
(if-let [cljs-res (io/resource relpath)]
502+
{:relative-path relpath :uri cljs-res}
503+
(let [relpath (str path ".cljc")]
504+
(if-let [cljc-res (io/resource relpath)]
505+
{:relative-path relpath :uri cljc-res}
506506
(let [relpath (:file (get-in @compiler-env [:js-dependency-index ns-str]))]
507507
(if-let [js-res (and relpath (io/resource relpath))]
508508
{:relative-path relpath :uri js-res}
@@ -1606,7 +1606,7 @@
16061606
([src {:keys [wrap all-provides] :as options}]
16071607
(let [goog-ns
16081608
(case (util/ext src)
1609-
("cljc" "cljs") (comp/munge (:ns (ana/parse-ns src)))
1609+
("cljs" "cljc") (comp/munge (:ns (ana/parse-ns src)))
16101610
"js" (cond-> (:provides (parse-js-ns src))
16111611
(not all-provides) first)
16121612
(throw

src/clj/cljs/compiler.clj

+6-6
Original file line numberDiff line numberDiff line change
@@ -940,12 +940,12 @@
940940
String. Always returns a String."
941941
[^String file-str]
942942
(cond
943-
(.endsWith file-str ".cljc")
944-
(clojure.string/replace file-str #"\.cljc$" ".js")
945-
946943
(.endsWith file-str ".cljs")
947944
(clojure.string/replace file-str #"\.cljs$" ".js")
948945

946+
(.endsWith file-str ".cljc")
947+
(clojure.string/replace file-str #"\.cljc$" ".js")
948+
949949
:else
950950
(throw (IllegalArgumentException.
951951
(str "Invalid source file extension " file-str)))))
@@ -1136,12 +1136,12 @@
11361136
(throw (java.io.FileNotFoundException. (str "The file " src " does not exist."))))))))
11371137

11381138
(defn cljs-files-in
1139-
"Return a sequence of all .cljc and .cljs files in the given directory."
1139+
"Return a sequence of all .cljs and .cljc files in the given directory."
11401140
[dir]
11411141
(filter
11421142
#(let [name (.getName ^File %)]
1143-
(and (or (.endsWith name ".cljc")
1144-
(.endsWith name ".cljs"))
1143+
(and (or (.endsWith name ".cljs")
1144+
(.endsWith name ".cljc"))
11451145
(not= \. (first name))
11461146
(not (contains? cljs-reserved-file-names name))))
11471147
(file-seq dir)))

src/clj/cljs/repl.clj

+7-7
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,17 @@
202202

203203
(defn ^File js-src->cljs-src
204204
"Map a JavaScript output file back to the original ClojureScript source
205-
file (.cljc or .cljs)."
205+
file (.cljs or .cljc)."
206206
[f]
207207
(let [f (io/file f)
208208
dir (.getParentFile f)
209209
base-name (string/replace (.getName f) ".js" "")
210-
cljcf (io/file dir (str base-name ".cljc"))]
211-
(if (.exists cljcf)
212-
cljcf
213-
(let [cljsf (io/file dir (str base-name ".cljs"))]
214-
(if (.exists cljsf)
215-
cljsf)))))
210+
cljsf (io/file dir (str base-name ".cljs"))]
211+
(if (.exists cljsf)
212+
cljsf
213+
(let [cljcf (io/file dir (str base-name ".cljc"))]
214+
(if (.exists cljcf)
215+
cljcf)))))
216216

217217
(defn read-source-map
218218
"Return the source map for the JavaScript source file."

src/clj/cljs/repl/browser.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
".html" "text/html"
9191
".jpg" "image/jpeg"
9292
".js" "text/javascript"
93-
".cljc" "text/x-clojure"
9493
".cljs" "text/x-clojure"
94+
".cljc" "text/x-clojure"
9595
".map" "application/json"
9696
".png" "image/png"
9797
"text/plain"))

src/clj/cljs/util.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
(defn ns->source
5959
"Given a namespace as a symbol return the corresponding resource if it exists."
6060
[ns]
61-
(or (io/resource (ns->relpath ns :cljc))
62-
(io/resource (ns->relpath ns :cljs))))
61+
(or (io/resource (ns->relpath ns :cljs))
62+
(io/resource (ns->relpath ns :cljc))))
6363

6464
(defn path-seq
6565
[file-str]

0 commit comments

Comments
 (0)