From 6b19f942802f3b35059bb4acfa4791ef1717b8a9 Mon Sep 17 00:00:00 2001 From: Stuart Sierra Date: Fri, 6 Nov 2015 17:34:14 -0500 Subject: [PATCH] TNS-38: ignore dependency on self, for CLJS In Clojure (.clj) code, a namespace depending on itself makes no sense. But it is perfectly reasonable for a ClojureScript (.cljs) file to depend on a Clojure (.clj) file for macro definitions in the same namespace, via :require-macros. More generally, this means that a "namespace" is logically defined in multiple files, which tools.namespace does not yet handle. This causes spurious circular-dependency error in tools. See, for example, https://github.com/clojure-emacs/refactor-nrepl/issues/127 It is easy to work around the specific case of self-dependency via :require-macros, which has no meaning anywhere else. As a consequence, tools.namespace will no longer throw an exception if an ordinary Clojure namespace tries to :require itself. --- src/main/clojure/clojure/tools/namespace/parse.cljc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/clojure/clojure/tools/namespace/parse.cljc b/src/main/clojure/clojure/tools/namespace/parse.cljc index d4adacd..b503519 100644 --- a/src/main/clojure/clojure/tools/namespace/parse.cljc +++ b/src/main/clojure/clojure/tools/namespace/parse.cljc @@ -123,6 +123,9 @@ (defn deps-from-ns-decl "Given an (ns...) declaration form (unevaluated), returns a set of symbols naming the dependencies of that namespace. Handles :use and - :require clauses but not :load." + :require clauses but not :load. Ignores a namespace depending on + itself, for example a .cljs file with :require-macros on the .clj + file of the same namespace." [decl] - (set (mapcat deps-from-ns-form decl))) + (disj (set (mapcat deps-from-ns-form decl)) + (name-from-ns-decl decl)))