Skip to content

Commit 3cfc0b4

Browse files
committed
CLJS-3333: defonce expansion non-hygienic with respect to core names
1 parent 70a5cdf commit 3cfc0b4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/clojure/cljs/core.cljc

+5-2
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,11 @@
618618
"defs name to have the root value of init iff the named var has no root value,
619619
else init is unevaluated"
620620
[x init]
621-
`(when-not (exists? ~x)
622-
(def ~x ~init)))
621+
(core/let [qualified (if (namespace x)
622+
x
623+
(symbol (core/str (core/-> &env :ns :name)) (name x)))]
624+
`(when-not (exists? ~qualified)
625+
(def ~x ~init))))
623626

624627
(core/defn destructure [bindings]
625628
(core/let [bents (partition 2 bindings)

src/test/cljs/cljs/core_test.cljs

+4
Original file line numberDiff line numberDiff line change
@@ -1874,3 +1874,7 @@
18741874
(for [e s :when (and (sequential? e) (every? (fn [x] x) e))]
18751875
e))
18761876
[[]]))))
1877+
1878+
(deftest test-cljs-3333
1879+
(defonce not-native 17) ;; Intentionally matching a core name
1880+
(is (== 17 not-native)))

0 commit comments

Comments
 (0)