From 995b6be09425c57e90082c2118df5a2e04167354 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 11 Jun 2024 15:34:45 +0200 Subject: [PATCH] Fix #537: not should wrap entire expression (#538) --- CHANGELOG.md | 3 ++- src/squint/compiler.cljc | 2 +- test/squint/compiler_test.cljs | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87d714ee..edb8666a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ [Squint](https://github.com/squint-cljs/squint): Light-weight ClojureScript dialect -## Unreleased +## v0.7.111 +- [#537](https://github.com/squint-cljs/squint/issues/537): Fix `not`: wrap argument in parens - Return interop expression in function body ## v0.7.110 diff --git a/src/squint/compiler.cljc b/src/squint/compiler.cljc index d12fa88e..83ffa7b9 100644 --- a/src/squint/compiler.cljc +++ b/src/squint/compiler.cljc @@ -117,7 +117,7 @@ (defmethod emit-special 'not [_ env [_ form]] (let [js (emit form (expr-env env))] (if (:bool js) - (emit-return (cc/bool-expr (str "!" js)) env) + (emit-return (cc/bool-expr (format "!(%s)" js)) env) (cc/bool-expr (emit (list 'js* (format "~{}(%s)" js) 'clojure.core/not) env))))) diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index 07e31c7e..37b9b221 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -2275,6 +2275,8 @@ new Foo();") (deftest interop-test (is (= 1 (jsv! "(defn foo [x] x.a) (foo {:a 1})")))) +(deftest issue-537-test + (is (true? (jsv! "(not (= 1 2))")))) (defn init [] (t/run-tests 'squint.compiler-test 'squint.jsx-test 'squint.string-test 'squint.html-test))