Skip to content

Commit

Permalink
CLJS-409: Extract emit-provide function
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonbloom authored and David Nolen committed Oct 27, 2012
1 parent a615f5e commit d8f490e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/clj/cljs/compiler.clj
Expand Up @@ -130,6 +130,11 @@
(defn ^String emit-str [expr] (defn ^String emit-str [expr]
(with-out-str (emit-top-level expr))) (with-out-str (emit-top-level expr)))


(defn emit-provide [sym]
(when-not (or (nil? *emitted-provides*) (contains? @*emitted-provides* sym))
(swap! *emitted-provides* conj sym)
(emitln "goog.provide('" (munge sym) "');")))

(defmulti emit-constant class) (defmulti emit-constant class)
(defmethod emit-constant nil [x] (emits "null")) (defmethod emit-constant nil [x] (emits "null"))
(defmethod emit-constant Long [x] (emits x)) (defmethod emit-constant Long [x] (emits x))
Expand Down Expand Up @@ -682,10 +687,7 @@
(defmethod emit :deftype* (defmethod emit :deftype*
[{:keys [t fields pmasks]}] [{:keys [t fields pmasks]}]
(let [fields (map munge fields)] (let [fields (map munge fields)]
(when-not (or (nil? *emitted-provides*) (contains? @*emitted-provides* t)) (emit-provide t)
(swap! *emitted-provides* conj t)
(emitln "")
(emitln "goog.provide('" (munge t) "');"))
(emitln "") (emitln "")
(emitln "/**") (emitln "/**")
(emitln "* @constructor") (emitln "* @constructor")
Expand All @@ -700,10 +702,7 @@
(defmethod emit :defrecord* (defmethod emit :defrecord*
[{:keys [t fields pmasks]}] [{:keys [t fields pmasks]}]
(let [fields (concat (map munge fields) '[__meta __extmap])] (let [fields (concat (map munge fields) '[__meta __extmap])]
(when-not (or (nil? *emitted-provides*) (contains? @*emitted-provides* t)) (emit-provide t)
(swap! *emitted-provides* conj t)
(emitln "")
(emitln "goog.provide('" (munge t) "');"))
(emitln "") (emitln "")
(emitln "/**") (emitln "/**")
(emitln "* @constructor") (emitln "* @constructor")
Expand Down

0 comments on commit d8f490e

Please sign in to comment.