Skip to content

Commit

Permalink
Fix #394: add int
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Dec 1, 2023
1 parent 8ae2b8d commit 228fd4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,16 @@ break;}" body)
(defmethod emit-special 'js-in [_ env [_ key obj]]
(bool-expr (emit (list 'js* "~{} in ~{}" key obj) env)))

(defmethod emit-special 'int [_ env [_ obj]]
(-> (format "(%s | 0)" (emit obj (assoc env :context :expr)))
(emit-return env)))

(defmethod emit #?(:clj clojure.lang.MapEntry :cljs MapEntry) [expr env]
;; RegExp case moved here:
;; References to the global RegExp object prevents optimization of regular expressions.
(emit (vec expr) env))

(def special-forms '#{zero? pos? neg? js-delete nil? js-in})
(def special-forms '#{zero? pos? neg? js-delete nil? js-in int})

(derive #?(:clj clojure.lang.Cons :cljs Cons) ::list)
(derive #?(:clj clojure.lang.IPersistentList :cljs IList) ::list)
Expand Down
4 changes: 4 additions & 0 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,5 +1676,9 @@
(deftest js-in-test
(is (true? (jsv! "(js-in :foo {:foo 1})"))))

(deftest int-test
(is (= 3 (jsv! "(int 3.14)"))))


(defn init []
(t/run-tests 'squint.compiler-test 'squint.jsx-test 'squint.string-test))

0 comments on commit 228fd4c

Please sign in to comment.