diff --git a/CHANGELOG.md b/CHANGELOG.md index db8e43fa..21851f6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ [Squint](https://github.com/squint-cljs/squint): ClojureScript syntax to JavaScript compiler +## 0.0.7 + +[#274](https://github.com/squint-cljs/squint/issues/274): fix logic precedence by wrapping in parens + ## 0.0.6 Add preliminary Node.js API in `node.js` diff --git a/deps.edn b/deps.edn index ba546a90..b16402f7 100644 --- a/deps.edn +++ b/deps.edn @@ -3,7 +3,7 @@ babashka/process {:mvn/version "0.1.7"} org.babashka/cli {:mvn/version "0.4.37"} org.babashka/sci {:mvn/version "0.6.37"} - io.github.squint-cljs/compiler-common {:git/sha "01fd1c8be7d5677dbf2502e159131b83d88d8e47" + io.github.squint-cljs/compiler-common {:git/sha "11c39efc278e83fe556c36941d9bfd27d8d5a187" :deps/root "compiler-common"}} :aliases {:dev {} diff --git a/src/squint/compiler.cljc b/src/squint/compiler.cljc index adcdc2f7..01b3c043 100644 --- a/src/squint/compiler.cljc +++ b/src/squint/compiler.cljc @@ -16,7 +16,7 @@ [squint.compiler-common :as cc :refer [#?(:cljs Exception) #?(:cljs format) *aliases* *cljs-ns* *excluded-core-vars* *imported-vars* *public-vars* *repl* - comma-list emit emit-args emit-infix emit-repl emit-special emit-wrap escape-jsx + comma-list emit emit-args emit-infix emit-repl emit-special emit-return escape-jsx expr-env infix-operator? prefix-unary? statement suffix-unary?]] [squint.internal.deftype :as deftype] [squint.internal.destructure :refer [core-let]] @@ -28,7 +28,7 @@ (defmethod emit #?(:clj clojure.lang.Keyword :cljs Keyword) [expr env] - (-> (emit-wrap (str (pr-str (subs (str expr) 1))) env) + (-> (emit-return (str (pr-str (subs (str expr) 1))) env) (emit-repl env))) (def special-forms (set ['var '. 'if 'funcall 'fn 'fn* 'quote 'set! @@ -100,13 +100,13 @@ (str (emit arg) operator)) (defmethod emit-special 'quote [_ env [_ form]] - (emit-wrap (emit form (expr-env (assoc env :quote true))) env)) + (emit-return (emit form (expr-env (assoc env :quote true))) env)) (defmethod emit-special 'not [_ env [_ form]] - (emit-wrap (str "!" (emit form (expr-env env))) env)) + (emit-return (str "!" (emit form (expr-env env))) env)) (defmethod emit-special 'js/typeof [_ env [_ form]] - (emit-wrap (str "typeof " (emit form (expr-env env))) env)) + (emit-return (str "typeof " (emit form (expr-env env))) env)) (defmethod emit-special 'letfn* [_ env [_ form & body]] (let [bindings (take-nth 2 form) @@ -118,7 +118,7 @@ (emit let env))) (defmethod emit-special 'quote [_ env [_ form]] - (emit-wrap (emit form (expr-env (assoc env :quote true))) env)) + (emit-return (emit form (expr-env (assoc env :quote true))) env)) #_(defmethod emit-special 'let* [_type enc-env [_let bindings & body]] (emit-let enc-env bindings body false)) @@ -167,7 +167,7 @@ (emit test env) (emit then env) (emit else env))) - (emit-wrap env)) + (emit-return env)) (str (format "if (%s) {\n" (emit test (assoc env :context :expr))) (emit then env) @@ -288,14 +288,14 @@ (symbol "") tag-name) tag-name (emit tag-name (expr-env (dissoc env :jsx)))] - (emit-wrap (format "<%s%s>%s" + (emit-return (format "<%s%s>%s" tag-name (jsx-attrs attrs env) (let [env (expr-env env)] (str/join " " (map #(emit % env) elts))) tag-name) env)) - (-> (emit-wrap (format "[%s]" + (-> (emit-return (format "[%s]" (str/join ", " (emit-args env expr))) env) (emit-repl env)))) @@ -314,13 +314,13 @@ (emit (val pair) expr-env))) keys (str/join ", " (map mk-pair (seq expr)))] (escape-jsx (-> (format "({ %s })" keys) - (emit-wrap env)) + (emit-return env)) env*))) (defmethod emit #?(:clj clojure.lang.PersistentHashSet :cljs PersistentHashSet) [expr env] - (emit-wrap + (emit-return (format "new Set([%s])" (str/join ", " (emit-args (expr-env env) expr))) env)) diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index c0b58cb1..a9daca45 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -1214,6 +1214,9 @@ (is (= 2 (jsv! '(do (defn foo [a b] (and a b)) (foo 1 2))))) (is (= 1 (jsv! '(do (defn foo [a b] (or a b)) (foo 1 2)))))) +(deftest logic-precedence + (is (false? (jsv! '(and (or true false) false))))) + (deftest multiple-arity-infix (is (true? (jsv! '(> 5 4 3 2 1)))) (is (true? (jsv! '(> 5 4 3))))