File tree Expand file tree Collapse file tree 2 files changed +16
-14
lines changed Expand file tree Collapse file tree 2 files changed +16
-14
lines changed Original file line number Diff line number Diff line change 962
962
963
963
(core/defmacro exists?
964
964
" 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."
967
966
[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)))
979
979
980
980
(core/defmacro undefined?
981
981
" Return true if argument is identical to the JavaScript undefined value."
Original file line number Diff line number Diff line change 731
731
(testing " Testing CLJS-2764, exists? on multi-segment symbols"
732
732
(is (false ? (exists? this.ns.does.not.exist)))
733
733
(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 {}))))))
735
737
736
738
(deftest test-518
737
739
(is (nil? (:test " test" ))))
You can’t perform that action at this time.
0 commit comments