Skip to content

Commit c7e49a9

Browse files
mfikesdnolen
authored andcommitted
CLJS-1449: self-host: Error if :require-macros with :as
The k argument to cljs.js/load-macros should be either a keyword or nil. The current implementation employs an or construct that can set k to be the value false, and when ultimately passed back into load-macros this false value can inadvertently be used as a function. This patch a) revises the or construct to terminate wil a nil, ensuring k will be be set to nil where previously it would have been set to false b) revises a spot where k is used to look up a value in a map, reversing things so that the map is instead used as the (non-nil) fn
1 parent 4470993 commit c7e49a9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/cljs/cljs/js.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@
353353
(defn- load-macros [bound-vars k macros reload reloads opts cb]
354354
(if (seq macros)
355355
(let [nsym (first (vals macros))
356-
k (or (k reload)
356+
k (or (reload k)
357357
(get-in reloads [k nsym])
358-
(and (= nsym name) (:*reload-macros* bound-vars) :reload))]
358+
(and (= nsym name) (:*reload-macros* bound-vars) :reload)
359+
nil)]
359360
(require bound-vars nsym k
360361
(-> opts
361362
(assoc :macros-ns true)

src/test/self/self_host/test.cljs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@
154154
(is (= "1\n2\n" value))
155155
(inc! l))))))
156156

157+
(deftest test-eval-str-with-require-macros
158+
(async done
159+
(let [l (latch 2 done)]
160+
(cljs/eval-str st
161+
"(ns cljs.user (:require-macros [cljs.user.macros]))"
162+
nil
163+
{:eval node-eval
164+
:load (fn [_ cb] (cb {:lang :clj :source "(ns cljs.user.macros)"}))}
165+
(fn [{:keys [value error]}]
166+
(is (nil? error))
167+
(inc! l)))
168+
(cljs/eval-str st
169+
"(ns cljs.user (:require-macros [cljs.user.macros :as cljs-user-macros]))"
170+
nil
171+
{:eval node-eval
172+
:load (fn [_ cb] (cb {:lang :clj :source "(ns cljs.user.macros)"}))}
173+
(fn [{:keys [error value]}]
174+
(is (nil? error))
175+
(inc! l))))))
176+
157177
#_(deftest test-eval-str-with-require
158178
(async done
159179
(let [l (latch 3 done)]

0 commit comments

Comments
 (0)