Skip to content

Commit 22c10ba

Browse files
mfikesdnolen
authored andcommitted
CLJS-1565: Self-host: whitespace optimization is broken
If generating single-file (in particular :whitespace) output for a project that makes use of cljs.js, it is possible for the concatenated file to have cljs.js appear prior to cljs.core$macros, and thus cause a dependency issue when loading the file. This is a consequence of the fact that the cljs.closure.JavaScriptFile compiled output for cljs.js doesn't specify cljs.core$macros macros as a dependency. There are already a few places where the cljs.core$macros dependency is patched in. This revision factors out a bit of that logic and adds it to another needed place.
1 parent cca12a5 commit 22c10ba

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,23 @@
585585
(js-dependencies {:libs ["closure/library/third_party/closure"]} ["goog.dom.query"])
586586
)
587587

588+
(defn- add-core-macros-if-cljs-js
589+
"If a compiled entity is the cljs.js namespace, explicitly
590+
add the cljs.core macros namespace dependency to it."
591+
[compiled]
592+
(cond-> compiled
593+
;; TODO: IJavaScript :provides :requires should really
594+
;; always be Vector<MungedString> - David
595+
(= ["cljs.js"] (into [] (map str) (deps/-provides compiled)))
596+
(update-in [:requires] concat ["cljs.core$macros"])))
597+
588598
(defn get-compiled-cljs
589599
"Return an IJavaScript for this file. Compiled output will be
590600
written to the working directory."
591601
[opts {:keys [relative-path uri]}]
592602
(let [js-file (comp/rename-to-js relative-path)
593603
compiled (-compile uri (merge opts {:output-file js-file}))]
594-
(cond-> compiled
595-
;; TODO: IJavaScript :provides :requires should really
596-
;; always be Vector<MungedString> - David
597-
(= ["cljs.js"] (into [] (map str) (deps/-provides compiled)))
598-
(update-in [:requires] concat ["cljs.core$macros"]))))
604+
(add-core-macros-if-cljs-js compiled)))
599605

600606
(defn cljs-source-for-namespace
601607
"Given a namespace return the corresponding source with either a .cljs or
@@ -1896,6 +1902,7 @@
18961902
(add-dependency-sources compile-opts)
18971903
deps/dependency-order
18981904
(compile-sources compiler-stats compile-opts)
1905+
(#(map add-core-macros-if-cljs-js %))
18991906
(add-js-sources all-opts)
19001907
(cond-> (= :nodejs (:target all-opts)) (concat [(-compile (io/resource "cljs/nodejs.cljs") all-opts)]))
19011908
deps/dependency-order

0 commit comments

Comments
 (0)