Skip to content

Commit 4769c5e

Browse files
committed
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).
1 parent 10c445c commit 4769c5e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@
168168
(let [sym (symbol name)]
169169
(get (:requires (:ns env)) sym sym)))
170170

171+
(defn confirm-ns [env ns-sym]
172+
(condp get ns-sym
173+
'#{cljs.core goog Math} :>> identity
174+
(-> env :ns :requires) :>> identity
175+
;; our internal conventions around data structures
176+
;; should not be allowed elsewhere
177+
(if-not (== (.indexOf (str ns-sym) "cljs.core") -1)
178+
ns-sym
179+
(do (when (:undeclared *cljs-warnings*)
180+
(warning env
181+
(str "WARNING: No such namespace: " ns-sym)))
182+
ns-sym))))
183+
171184
(defn core-name?
172185
"Is sym visible from core in the current compilation namespace?"
173186
[env sym]
@@ -191,6 +204,7 @@
191204
ns (if (= "clojure.core" ns) "cljs.core" ns)
192205
full-ns (resolve-ns-alias env ns)]
193206
(when confirm
207+
(confirm-ns env full-ns)
194208
(confirm env full-ns (symbol (name sym))))
195209
(merge (get-in @namespaces [full-ns :defs (symbol (name sym))])
196210
{:name (symbol (str full-ns) (str (name sym)))
@@ -730,8 +744,10 @@
730744
(error-msg spec ":refer must be followed by a sequence of symbols in :require / :require-macros"))
731745
(when-not macros?
732746
(swap! deps conj lib))
733-
(merge (when alias {rk {alias lib}})
734-
(when referred {uk (apply hash-map (interleave referred (repeat lib)))})))))
747+
(merge
748+
(when alias
749+
{rk (merge {alias lib} {lib lib})})
750+
(when referred {uk (apply hash-map (interleave referred (repeat lib)))})))))
735751
use->require (fn use->require [[lib kw referred :as spec]]
736752
(assert (and (symbol? lib) (= :only kw) (sequential? referred) (every? symbol? referred))
737753
(error-msg spec "Only [lib.ns :only (names)] specs supported in :use / :use-macros"))

0 commit comments

Comments
 (0)