Skip to content

Commit 72e99c5

Browse files
author
dnolen
committed
exists? should continue to support some? style usage
1 parent d5e8da2 commit 72e99c5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/main/clojure/cljs/core.cljc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -962,20 +962,20 @@
962962

963963
(core/defmacro exists?
964964
"Return true if argument exists, analogous to usage of typeof operator
965-
in JavaScript to check for undefined top-level var. x must be a symbol but
966-
need not be top-level."
965+
in JavaScript."
967966
[x]
968-
(core/assert (core/symbol? x))
969-
(let [x (cond-> (:name (cljs.analyzer/resolve-var &env x))
970-
(= "js" (namespace x)) name)
971-
segs (string/split (core/str (string/replace x #"\/" ".")) #"\.")
972-
n (count segs)
973-
syms (map
974-
#(vary-meta (symbol "js" (string/join "." %))
975-
assoc :cljs.analyzer/no-resolve true)
976-
(reverse (take n (iterate butlast segs))))
977-
js (string/join " && " (repeat n "(typeof ~{} !== 'undefined')"))]
978-
(bool-expr (concat (core/list 'js* js) syms))))
967+
(if (core/symbol? x)
968+
(let [x (cond-> (:name (cljs.analyzer/resolve-var &env x))
969+
(= "js" (namespace x)) name)
970+
segs (string/split (core/str (string/replace x #"\/" ".")) #"\.")
971+
n (count segs)
972+
syms (map
973+
#(vary-meta (symbol "js" (string/join "." %))
974+
assoc :cljs.analyzer/no-resolve true)
975+
(reverse (take n (iterate butlast segs))))
976+
js (string/join " && " (repeat n "(typeof ~{} !== 'undefined')"))]
977+
(bool-expr (concat (core/list 'js* js) syms)))
978+
`(some? ~x)))
979979

980980
(core/defmacro undefined?
981981
"Return true if argument is identical to the JavaScript undefined value."

src/test/cljs/cljs/core_test.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,9 @@
731731
(testing "Testing CLJS-2764, exists? on multi-segment symbols"
732732
(is (false? (exists? this.ns.does.not.exist)))
733733
(is (true? (exists? cljs.core.first)))
734-
(is (true? (exists? cljs.core/first)))))
734+
(is (true? (exists? cljs.core/first)))
735+
(is (true? (exists? (:foo {:foo 1}))))
736+
(is (false? (exists? (:foo {}))))))
735737

736738
(deftest test-518
737739
(is (nil? (:test "test"))))

0 commit comments

Comments
 (0)