|
839 | 839 | (emit-wrap env (emits target " = " val))) |
840 | 840 |
|
841 | 841 | (defn load-libs |
842 | | - ([libs] (load-libs libs nil)) |
843 | | - ([libs seen] |
844 | | - (let [loaded-libs (munge 'cljs.core.*loaded-libs*) |
845 | | - loaded-libs-temp (munge (gensym 'cljs.core.*loaded-libs*))] |
846 | | - (when (-> libs meta :reload-all) |
847 | | - (emitln "if(!COMPILED) " loaded-libs-temp " = " loaded-libs " || cljs.core.set();") |
848 | | - (emitln "if(!COMPILED) " loaded-libs " = cljs.core.set();")) |
849 | | - (doseq [lib (remove (set (vals seen)) (distinct (vals libs)))] |
850 | | - (cond |
851 | | - (ana/foreign-dep? lib) |
852 | | - (let [{:keys [target optimizations]} (get @env/*compiler* :options)] |
853 | | - ;; we only load foreign libraries under optimizations :none |
854 | | - (when (= :none optimizations) |
855 | | - (if (= :nodejs target) |
856 | | - ;; under node.js we load foreign libs globally |
857 | | - (let [{:keys [js-dependency-index options]} @env/*compiler* |
858 | | - ijs-url (get-in js-dependency-index [(name lib) :url])] |
859 | | - (emitln "cljs.core.load_file(\"" |
860 | | - (str (io/file (util/output-directory options) (util/get-name ijs-url))) |
861 | | - "\");")) |
862 | | - (emitln "goog.require('" (munge lib) "');")))) |
863 | | - |
864 | | - (-> libs meta :reload) |
865 | | - (emitln "goog.require('" (munge lib) "', 'reload');") |
866 | | - |
867 | | - (-> libs meta :reload-all) |
868 | | - (emitln "goog.require('" (munge lib) "', 'reload-all');") |
869 | | - |
870 | | - :else |
871 | | - (emitln "goog.require('" (munge lib) "');"))) |
872 | | - (when (-> libs meta :reload-all) |
873 | | - (emitln "if(!COMPILED) " loaded-libs " = cljs.core.into(" loaded-libs-temp ", " loaded-libs ");"))))) |
| 842 | + [libs seen reloads] |
| 843 | + (let [loaded-libs (munge 'cljs.core.*loaded-libs*) |
| 844 | + loaded-libs-temp (munge (gensym 'cljs.core.*loaded-libs*))] |
| 845 | + (when (-> libs meta :reload-all) |
| 846 | + (emitln "if(!COMPILED) " loaded-libs-temp " = " loaded-libs " || cljs.core.set();") |
| 847 | + (emitln "if(!COMPILED) " loaded-libs " = cljs.core.set();")) |
| 848 | + (doseq [lib (remove (set (vals seen)) (distinct (vals libs)))] |
| 849 | + (cond |
| 850 | + (ana/foreign-dep? lib) |
| 851 | + (let [{:keys [target optimizations]} (get @env/*compiler* :options)] |
| 852 | + ;; we only load foreign libraries under optimizations :none |
| 853 | + (when (= :none optimizations) |
| 854 | + (if (= :nodejs target) |
| 855 | + ;; under node.js we load foreign libs globally |
| 856 | + (let [{:keys [js-dependency-index options]} @env/*compiler* |
| 857 | + ijs-url (get-in js-dependency-index [(name lib) :url])] |
| 858 | + (emitln "cljs.core.load_file(\"" |
| 859 | + (str (io/file (util/output-directory options) (util/get-name ijs-url))) |
| 860 | + "\");")) |
| 861 | + (emitln "goog.require('" (munge lib) "');")))) |
| 862 | + |
| 863 | + (or (-> libs meta :reload) |
| 864 | + (= (get reloads lib) :reload)) |
| 865 | + (emitln "goog.require('" (munge lib) "', 'reload');") |
| 866 | + |
| 867 | + (or (-> libs meta :reload-all) |
| 868 | + (= (get reloads lib) :reload-all)) |
| 869 | + (emitln "goog.require('" (munge lib) "', 'reload-all');") |
| 870 | + |
| 871 | + :else |
| 872 | + (emitln "goog.require('" (munge lib) "');"))) |
| 873 | + (when (-> libs meta :reload-all) |
| 874 | + (emitln "if(!COMPILED) " loaded-libs " = cljs.core.into(" loaded-libs-temp ", " loaded-libs ");")))) |
874 | 875 |
|
875 | 876 | (defmethod emit* :ns |
876 | | - [{:keys [name requires uses require-macros env]}] |
| 877 | + [{:keys [name requires uses require-macros reloads env]}] |
877 | 878 | (emitln "goog.provide('" (munge name) "');") |
878 | 879 | (when-not (= name 'cljs.core) |
879 | 880 | (emitln "goog.require('cljs.core');")) |
880 | | - (load-libs requires) |
881 | | - (load-libs uses requires)) |
| 881 | + (load-libs requires nil (:require reloads)) |
| 882 | + (load-libs uses requires (:use reloads))) |
882 | 883 |
|
883 | 884 | (defmethod emit* :deftype* |
884 | 885 | [{:keys [t fields pmasks body]}] |
|
0 commit comments