Skip to content

Commit 2f233d6

Browse files
mfikesswannodette
authored andcommitted
CLJS-2645: cljs.main: failure with :closure-defines and non-Nashorn in :none mode
1 parent 9dd4d41 commit 2f233d6

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/main/clojure/cljs/repl/browser.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
(= path (cond->> "/main.js" output-dir (str "/" output-dir )))
172172
(let [closure-defines (-> `{clojure.browser.repl/HOST ~host
173173
clojure.browser.repl/PORT ~port}
174+
(merge (:closure-defines @browser-state))
174175
cljsc/normalize-closure-defines
175176
json/write-str)]
176177
(server/send-and-close conn 200
@@ -302,7 +303,8 @@
302303
(cljsc/create-client-js-file
303304
{:optimizations :simple
304305
:output-dir working-dir}
305-
(io/file working-dir "brepl_client.js")))))
306+
(io/file working-dir "brepl_client.js"))
307+
:closure-defines (:closure-defines opts))))
306308
;; TODO: this could be cleaner if compiling forms resulted in a
307309
;; :output-to file with the result of compiling those forms - David
308310
(when (and output-dir (not (.exists (io/file output-dir "clojure" "browser" "repl" "preload.js"))))

src/main/clojure/cljs/repl/node.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@
196196
(when (or (not (contains? *loaded-libs* name)) reload)
197197
(set! *loaded-libs* (conj (or *loaded-libs* #{}) name))
198198
(js/CLOSURE_IMPORT_SCRIPT
199-
(unchecked-get (.. js/goog -dependencies_ -nameToPath) name))))))))))
199+
(unchecked-get (.. js/goog -dependencies_ -nameToPath) name)))))))
200+
(node-eval repl-env
201+
(str "goog.global.CLOSURE_UNCOMPILED_DEFINES = "
202+
(json/write-str (:closure-defines opts)) ";")))))
200203

201204
(defrecord NodeEnv [host port path socket proc]
202205
repl/IReplEnvOptions

src/main/clojure/cljs/repl/rhino.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
(:refer-clojure :exclude [load-file])
1111
(:require [clojure.string :as string]
1212
[clojure.java.io :as io]
13+
[clojure.data.json :as json]
1314
[cljs.compiler :as comp]
1415
[cljs.closure :as closure]
1516
[cljs.analyzer :as ana]
@@ -154,7 +155,12 @@
154155
(when (or (not (contains? *loaded-libs* name)) reload)
155156
(set! *loaded-libs* (conj (or *loaded-libs* #{}) name))
156157
(js/CLOSURE_IMPORT_SCRIPT
157-
(goog.object/get (.. js/goog -dependencies_ -nameToPath) name)))))))))
158+
(goog.object/get (.. js/goog -dependencies_ -nameToPath) name)))))))
159+
160+
;; set closure-defines
161+
(rhino-eval repl-env "CLOSURE_UNCOMPILED_DEFINES" 1
162+
(str "goog.global.CLOSURE_UNCOMPILED_DEFINES = "
163+
(json/write-str (:closure-defines opts)) ";"))))
158164

159165
;; Catching errors and rethrowing in Rhino swallows the original trace
160166
;; https://groups.google.com/d/msg/mozilla.dev.tech.js-engine.rhino/inMyVKhPq6M/cY39hX20_z8J

src/test/cljs_cli/cljs_cli/test.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@
6060
(shell/sh "node" (str (io/file dir "out" "main.js"))))))
6161
(-> (cljs-main "-t" "node" "-o" "out/main.js" "-O" "advanced" "-c" "foo.core")
6262
(output-is))))))
63+
64+
(deftest test-cljs-2645
65+
(with-sources {"src/foo/core.cljs"
66+
"(ns foo.core) (goog-define configurable \"default-value\") (defn -main [& args] (println configurable))"}
67+
(-> (cljs-main "-m" "foo.core")
68+
(output-is "default-value"))
69+
(-> (cljs-main "-co" "{:closure-defines {foo.core/configurable \"configured-value\"}}" "-m" "foo.core")
70+
(output-is "configured-value"))))

0 commit comments

Comments
 (0)