Permalink
Browse files

CLJS-684: throw on circular dependency

  • Loading branch information...
1 parent fe9b557 commit 8f0eafadebce199bf92c788e5db1a7924f12606b @swannodette swannodette committed Nov 17, 2013
Showing with 12 additions and 8 deletions.
  1. +12 −8 src/clj/cljs/analyzer.clj
View
@@ -25,6 +25,7 @@
(def ^:dynamic *cljs-static-fns* false)
(def ^:dynamic *cljs-macros-path* "/cljs/core")
(def ^:dynamic *cljs-macros-is-classpath* true)
+(def ^:dynamic *cljs-dep-set* (with-meta #{} {:dep-path []}))
(def -cljs-macros-loaded (atom false))
(def ^:dynamic *cljs-warnings*
@@ -804,13 +805,16 @@
(declare analyze-file)
-(defn analyze-deps [deps]
- (doseq [dep deps]
- (when-not (contains? (::namespaces @env/*compiler*) dep)
- (let [relpath (ns->relpath dep)]
- (when (io/resource relpath)
- (no-warn
- (analyze-file relpath)))))))
+(defn analyze-deps [lib deps]
+ (binding [*cljs-dep-set* (vary-meta (conj *cljs-dep-set* lib) update-in [:dep-path] conj lib)]
+ (assert (every? #(not (contains? *cljs-dep-set* %)) deps)
+ (str "Circular dependency detected " (-> *cljs-dep-set* meta :dep-path)))
+ (doseq [dep deps]
+ (when-not (contains? (::namespaces @env/*compiler*) dep)
+ (let [relpath (ns->relpath dep)]
+ (when (io/resource relpath)
+ (no-warn
+ (analyze-file relpath))))))))
(defn check-uses [uses env]
(doseq [[sym lib] uses]
@@ -917,7 +921,7 @@
(apply merge-with merge m (map (spec-parsers k) libs)))
{} (remove (fn [[r]] (= r :refer-clojure)) args))]
(when (seq @deps)
- (analyze-deps @deps))
+ (analyze-deps name @deps))
(when (seq uses)
(check-uses uses env))
(set! *cljs-ns* name)

0 comments on commit 8f0eafa

Please sign in to comment.