Browse files

CLJS-631: Use ana/namespaces for shadowing vars

The compiler used to be keeping track of namespaces it
had emitted and using that atom to determine whether a
variable shadowed a declared namespace. If dependent
namespaces were emitted before their dependencies, this
could result in the dependent file shadowing the names
of the not-yet-compiled dependency. This happened both
during out-of-order clean compilation and certain
instances of incremental compilation.

This patch utilizes the analyzer's existing namespaces atom
to track loaded namespaces rather than maintaining a separate
atom in the compiler.

Files are guaranteed to be analyzed in dependency order, so
this ensures that all files with valid ns forms will know of
the namespaces they need to avoid shadowing and behave
  • Loading branch information...
thieman authored and swannodette committed Oct 30, 2013
1 parent 8460555 commit c135f06992823ceec85f38877776a7c8bc238b74
Showing with 4 additions and 3 deletions.
  1. +4 −3 src/clj/cljs/compiler.clj
@@ -50,15 +50,17 @@
[& args]
`(.println System/err (str ~@args)))
(defonce ns-first-segments (atom '#{"cljs" "clojure"}))
(defn ns-first-segments []
(letfn [(get-first-ns-segment [ns] (first (string/split (str ns) #"\.")))]
(map get-first-ns-segment (keys @ana/namespaces))))
; Helper fn
(defn shadow-depth [s]
(let [{:keys [name info]} s]
(loop [d 0, {:keys [shadow]} info]
shadow (recur (inc d) shadow)
(@ns-first-segments (str name)) (inc d)
(some #{(str name)} (ns-first-segments)) (inc d)
:else d))))
(defn munge
@@ -744,7 +746,6 @@
(defmethod emit :ns
[{:keys [name requires uses requires-macros env]}]
(swap! ns-first-segments conj (first (string/split (str name) #"\.")))
(emitln "goog.provide('" (munge name) "');")
(when-not (= name 'cljs.core)
(emitln "goog.require('cljs.core');"))

0 comments on commit c135f06

Please sign in to comment.