From 228fd4c4fba0444350f5c2e5b3b9b087a1c09ea0 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 1 Dec 2023 15:43:01 +0100 Subject: [PATCH] Fix #394: add int --- src/squint/compiler_common.cljc | 6 +++++- test/squint/compiler_test.cljs | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/squint/compiler_common.cljc b/src/squint/compiler_common.cljc index cca5c2f6..9c8412a8 100644 --- a/src/squint/compiler_common.cljc +++ b/src/squint/compiler_common.cljc @@ -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) diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index 5be0356a..f98ef747 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -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))