From 4769c5e05233d9841aedf882bd99812d0f842abb Mon Sep 17 00:00:00 2001 From: David Nolen Date: Sat, 5 Oct 2013 14:10:54 -0400 Subject: [PATCH] CLJS-574: No warnings when calling functions from unrequired namespaces Change resolve-ns-alias to special case cljs.core, goog, and Math namespaces. Special case convention around cljs.core data structures, but don't support elsewhere. Emit a "no such namespace" warning if we don't find ns in (-> env :ns :requires). --- src/clj/cljs/analyzer.clj | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/clj/cljs/analyzer.clj b/src/clj/cljs/analyzer.clj index 3e2bc7466e..bd4f857b3f 100644 --- a/src/clj/cljs/analyzer.clj +++ b/src/clj/cljs/analyzer.clj @@ -168,6 +168,19 @@ (let [sym (symbol name)] (get (:requires (:ns env)) sym sym))) +(defn confirm-ns [env ns-sym] + (condp get ns-sym + '#{cljs.core goog Math} :>> identity + (-> env :ns :requires) :>> identity + ;; our internal conventions around data structures + ;; should not be allowed elsewhere + (if-not (== (.indexOf (str ns-sym) "cljs.core") -1) + ns-sym + (do (when (:undeclared *cljs-warnings*) + (warning env + (str "WARNING: No such namespace: " ns-sym))) + ns-sym)))) + (defn core-name? "Is sym visible from core in the current compilation namespace?" [env sym] @@ -191,6 +204,7 @@ ns (if (= "clojure.core" ns) "cljs.core" ns) full-ns (resolve-ns-alias env ns)] (when confirm + (confirm-ns env full-ns) (confirm env full-ns (symbol (name sym)))) (merge (get-in @namespaces [full-ns :defs (symbol (name sym))]) {:name (symbol (str full-ns) (str (name sym))) @@ -730,8 +744,10 @@ (error-msg spec ":refer must be followed by a sequence of symbols in :require / :require-macros")) (when-not macros? (swap! deps conj lib)) - (merge (when alias {rk {alias lib}}) - (when referred {uk (apply hash-map (interleave referred (repeat lib)))}))))) + (merge + (when alias + {rk (merge {alias lib} {lib lib})}) + (when referred {uk (apply hash-map (interleave referred (repeat lib)))}))))) use->require (fn use->require [[lib kw referred :as spec]] (assert (and (symbol? lib) (= :only kw) (sequential? referred) (every? symbol? referred)) (error-msg spec "Only [lib.ns :only (names)] specs supported in :use / :use-macros"))