Permalink
Browse files

CLJS-2958 - make symbol work on keywords and vars

  • Loading branch information...
souenzzo authored and mfikes committed Nov 5, 2018
1 parent e523cfa commit b38ad7e6a5edcb901db96d44ef2b44357253bf31
Showing with 21 additions and 13 deletions.
  1. +16 −13 src/main/cljs/cljs/core.cljs
  2. +5 −0 src/test/cljs/cljs/core_test.cljs
@@ -1098,16 +1098,24 @@ defaults to returning v."))
IPrintWithWriter
(-pr-writer [o writer _] (-write writer str)))
(defn var?
"Returns true if v is of type cljs.core.Var"
[v]
(instance? cljs.core.Var v))
(defn symbol
"Returns a Symbol with the given namespace and name."
"Returns a Symbol with the given namespace and name. Arity-1 works
on strings, keywords, and vars."
([name]
(if (symbol? name)
name
(let [idx (.indexOf name "/")]
(if (< idx 1)
(symbol nil name)
(symbol (.substring name 0 idx)
(.substring name (inc idx) (. name -length)))))))
(cond (symbol? name) name
(string? name) (let [idx (.indexOf name "/")]
(if (< idx 1)
(symbol nil name)
(symbol (.substring name 0 idx)
(.substring name (inc idx) (. name -length)))))
(var? name) (.-sym name)
(keyword? name) (recur (.-fqn name))
:else (throw (new js/Error "no conversion to symbol"))))
([ns name]
(let [sym-str (if-not (nil? ns)
(str ns "/" name)
@@ -1182,11 +1190,6 @@ defaults to returning v."))
(-invoke [_ a b c d e f g h i j k l m n o p q r s t rest]
(apply (val) a b c d e f g h i j k l m n o p q r s t rest)))
(defn var?
"Returns true if v is of type cljs.core.Var"
[v]
(instance? cljs.core.Var v))
;;;;;;;;;;;;;;;;;;; fundamentals ;;;;;;;;;;;;;;;
(declare array-seq prim-seq IndexedSeq)
@@ -1725,6 +1725,11 @@
(is (= "#object[cljs.core.Atom {:val 1}]" (pr-str (atom 1))))
(is (= "#object[cljs.core.Volatile {:val 2}]" (pr-str (volatile! 2)))))
(deftest test-cljs-2944
(is (= (symbol :foo/bar) 'foo/bar))
(is (= (symbol (->Var nil 'bar/foo nil)) 'bar/foo))
(is (thrown? js/Error (symbol 1))))
(deftest test-cljs-2991
(let [o (js-obj)]
(is (object? o))

0 comments on commit b38ad7e

Please sign in to comment.