diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d29191..7ba84e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ [Squint](https://github.com/squint-cljs/squint): ClojureScript syntax to JavaScript compiler +## 0.2.31 (2023-10-09) + +- Add `bit-and` and `bit-or` + ## 0.2.30 (2023-10-04) - Include `lib/squint.core.umd.js` which defines a global `squint.core` object (easy to use in browsers) diff --git a/package.json b/package.json index 2041f2db..226f4640 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "squint-cljs", "type": "module", "sideEffects": false, - "version": "0.2.30", + "version": "0.2.31", "files": [ "core.js", "src/squint/core.js", diff --git a/src/squint/compiler_common.cljc b/src/squint/compiler_common.cljc index d9f43313..d4405159 100644 --- a/src/squint/compiler_common.cljc +++ b/src/squint/compiler_common.cljc @@ -131,9 +131,10 @@ (def suffix-unary-operators '#{++ --}) (def infix-operators #{"+" "+=" "-" "-=" "/" "*" "%" "=" "==" "===" "<" ">" "<=" ">=" "!=" - "<<" ">>" "<<<" ">>>" "!==" "&" "|" "&&" "||" "not=" "instanceof"}) + "<<" ">>" "<<<" ">>>" "!==" "&" "|" "&&" "||" "not=" "instanceof" + "bit-or" "bit-and"}) -(def chainable-infix-operators #{"+" "-" "*" "/" "&" "|" "&&" "||"}) +(def chainable-infix-operators #{"+" "-" "*" "/" "&" "|" "&&" "||" "bit-or" "bit-and"}) (defn infix-operator? [env expr] (contains? (or (:infix-operators env) @@ -163,7 +164,9 @@ (str "-" (emit (first args) env)) (-> (let [substitutions {'= "===" == "===" '!= "!==" 'not= "!==" - '+ "+"}] + '+ "+" + 'bit-or "|" + 'bit-and "&"}] (str "(" (str/join (str " " (or (substitutions operator) operator) " ") (emit-args env args)) ")")) diff --git a/src/squint/repl/node.cljs b/src/squint/repl/node.cljs index bf26904e..57874340 100644 --- a/src/squint/repl/node.cljs +++ b/src/squint/repl/node.cljs @@ -1,16 +1,11 @@ (ns squint.repl.node (:require - ["fs" :as fs] ["net" :as net] - ["path" :as path] - ["process" :as process] ["readline" :as readline] ["squint-cljs/core.js" :as squint] - ["url" :as url] ["vm" :as vm] [clojure.string :as str] [edamame.core :as e] - [shadow.esm :as esm] [squint.compiler :as compiler] [squint.compiler-common :refer [*async* *cljs-ns* *repl*]])) @@ -72,14 +67,14 @@ (def last-ns (atom *cljs-ns*)) #_(defn eval-js [js-str] - (let [filename (str ".repl/" (gensym) ".mjs")] - (when-not (fs/existsSync ".repl") - (fs/mkdirSync ".repl")) - (fs/writeFileSync filename js-str) - (-> (esm/dynamic-import (-> (path/resolve (process/cwd) filename) - url/pathToFileURL - str)) - (.finally (fn [] #_(prn filename) (fs/unlinkSync filename)))))) + (let [filename (str ".repl/" (gensym) ".mjs")] + (when-not (fs/existsSync ".repl") + (fs/mkdirSync ".repl")) + (fs/writeFileSync filename js-str) + (-> (esm/dynamic-import (-> (path/resolve (process/cwd) filename) + url/pathToFileURL + str)) + (.finally (fn [] #_(prn filename) (fs/unlinkSync filename)))))) (defn compile [the-val rl socket] (let [{js-str :javascript diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index c714089a..f488c579 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -1457,5 +1457,8 @@ (deftest re-seq-test (is (eq #js ["foo" "foo" "foo"] (jsv! "(vec (re-seq #\"foo\" \"foobfoobfoo\"))")))) +(deftest bit-and-or + (is (= 3 (jsv! "(+ (bit-and 1 2 3) (bit-or 1 2 3))")))) + (defn init [] (t/run-tests 'squint.compiler-test 'squint.jsx-test 'squint.string-test))