Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CLJS-509: spurious protocol warning

change analyze-file to also accept java.io.File. change parse-ns so that
we restore namespaces to it's value prior to analysis. change
compile-file so that we always analyze files even if they don't require
re-compilation. parse the ns form after that to extract out the
necessary information.
  • Loading branch information...
commit 5a038ffc1c0cba0f0d7f16efe23f0e95cb711518 1 parent e40d685
@swannodette swannodette authored
Showing with 34 additions and 24 deletions.
  1. +8 −4 src/clj/cljs/analyzer.clj
  2. +26 −20 src/clj/cljs/compiler.clj
View
12 src/clj/cljs/analyzer.clj
@@ -1020,12 +1020,16 @@
(if-let [form (binding [*ns* (create-ns *cljs-ns*)] (reader/read rdr nil nil))]
(cons form (forms-seq f rdr))))))
-(defn analyze-file
- [^String f]
- (let [res (if (re-find #"^file://" f) (java.net.URL. f) (io/resource f))]
+(defn analyze-file [f]
+ (let [res (cond
+ (instance? java.io.File f) f
+ (re-find #"^file://" f) (java.net.URL. f)
+ :else (io/resource f))]
(assert res (str "Can't find " f " in classpath"))
(binding [*cljs-ns* 'cljs.user
- *cljs-file* (.getPath ^java.net.URL res)]
+ *cljs-file* (if (instance? java.io.File res)
+ (.getPath ^java.io.File res)
+ (.getPath ^java.net.URL res))]
(with-open [r (io/reader res)]
(let [env (empty-env)
pbr (clojure.lang.LineNumberingPushbackReader. r)
View
46 src/clj/cljs/compiler.clj
@@ -784,24 +784,28 @@
(> (.lastModified src) (.lastModified dest))))
(defn parse-ns [src dest opts]
- (with-core-cljs
- (binding [ana/*cljs-ns* 'cljs.user]
- (loop [forms (ana/forms-seq src)]
- (if (seq forms)
- (let [env (ana/empty-env)
- ast (ana/analyze env (first forms))]
- (if (= (:op ast) :ns)
- (let [ns-name (:name ast)
- deps (merge (:uses ast) (:requires ast))]
- {:ns (or ns-name 'cljs.user)
- :provides [ns-name]
- :requires (if (= ns-name 'cljs.core)
- (set (vals deps))
- (conj (set (vals deps)) 'cljs.core))
- :file dest
- :source-file src
- :lines (-> dest io/reader line-seq count)})
- (recur (rest forms)))))))))
+ (let [namespaces' @ana/namespaces
+ ret
+ (with-core-cljs
+ (binding [ana/*cljs-ns* 'cljs.user]
+ (loop [forms (ana/forms-seq src)]
+ (if (seq forms)
+ (let [env (ana/empty-env)
+ ast (ana/analyze env (first forms))]
+ (if (= (:op ast) :ns)
+ (let [ns-name (:name ast)
+ deps (merge (:uses ast) (:requires ast))]
+ {:ns (or ns-name 'cljs.user)
+ :provides [ns-name]
+ :requires (if (= ns-name 'cljs.core)
+ (set (vals deps))
+ (conj (set (vals deps)) 'cljs.core))
+ :file dest
+ :source-file src
+ :lines (-> dest io/reader line-seq count)})
+ (recur (rest forms))))))))]
+ (reset! ana/namespaces namespaces')
+ ret))
(defn compile-file
"Compiles src to a file of the same name, but with a .js extension,
@@ -823,13 +827,15 @@
(compile-file src dest nil))
([src dest opts]
(let [src-file (io/file src)
- dest-file (io/file dest)]
+ dest-file (io/file dest)]
(if (.exists src-file)
(try
(if (or (requires-compilation? src-file dest-file) (:source-map opts))
(do (mkdirs dest-file)
(compile-file* src-file dest-file opts))
- (parse-ns src-file dest-file opts))
+ (do
+ (ana/analyze-file src-file)
+ (parse-ns src-file dest-file opts)))
(catch Exception e
(throw (ex-info (str "failed compiling file:" src) {:file src} e))))
(throw (java.io.FileNotFoundException. (str "The file " src " does not exist.")))))))
Please sign in to comment.
Something went wrong with that request. Please try again.