Skip to content

Commit

Permalink
Fix #45: native js array
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Aug 7, 2022
1 parent ceec244 commit b229c24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "module",
"name": "cherry-cljs",
"sideEffects": false,
"version": "0.0.0-alpha.43",
"version": "0.0.0-alpha.44",
"files": [
"cljs.core.js",
"lib",
Expand Down
9 changes: 6 additions & 3 deletions src/cherry/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,12 @@ break;}" body)

(defmethod emit #?(:clj clojure.lang.IPersistentVector
:cljs ::vector) [expr env]
(swap! *imported-core-vars* conj 'vector)
(emit-wrap env (format "vector(%s)"
(str/join ", " (emit-args env expr)))))
(if (::js (meta expr))
(emit-wrap env (format "[%s]"
(str/join ", " (emit-args env expr))))
(do (swap! *imported-core-vars* conj 'vector)
(emit-wrap env (format "vector(%s)"
(str/join ", " (emit-args env expr)))))))

#?(:cljs (derive PersistentArrayMap ::map))
#?(:cljs (derive PersistentHashMap ::map))
Expand Down
9 changes: 9 additions & 0 deletions test/cherry/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,14 @@
(is (= :hello v))
(done)))))

(deftest native-js-array-test
(let [s (jss! "(let [x 2
x #js [1 2 x]]
x)")
x (js/eval s)]
(is (array? x))
(is (= [1 2 2] (js->clj x))))
(is (= 1 (jsv! "(aget #js [1 2 3] 0)"))))

(defn init []
(cljs.test/run-tests 'cherry.compiler-test))

0 comments on commit b229c24

Please sign in to comment.