From cf57299d274f9b6b895e1b7874fc14817987c4e9 Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Sun, 10 May 2026 10:52:28 -0400 Subject: [PATCH 1/2] Add minimal reify --- CHANGELOG.md | 1 + src/squint/compiler.cljc | 1 + src/squint/internal/protocols.cljc | 8 ++++++++ test/squint/compiler_test.cljs | 24 ++++++++++++++++++++---- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a717f7..22d00a9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## Unreleased - Fix [#815](https://github.com/squint-cljs/squint/issues/815): `str` wrapping known-numeric infix expressions in `??''`, which esbuild flagged as `suspicious-nullish-coalescing`. +- [#817](https://github.com/squint-cljs/squint/issues/817): add minimal `reify` ## 0.11.189 diff --git a/src/squint/compiler.cljc b/src/squint/compiler.cljc index a4bdb66d..2bf10d24 100644 --- a/src/squint/compiler.cljc +++ b/src/squint/compiler.cljc @@ -87,6 +87,7 @@ 'defprotocol protocols/core-defprotocol 'extend-type protocols/core-extend-type 'extend-protocol protocols/core-extend-protocol + 'reify protocols/core-reify 'deftype deftype/core-deftype 'defn core-defn 'defn- core-defn- diff --git a/src/squint/internal/protocols.cljc b/src/squint/internal/protocols.cljc index 7b77e623..9d84bcb4 100644 --- a/src/squint/internal/protocols.cljc +++ b/src/squint/internal/protocols.cljc @@ -156,3 +156,11 @@ (bar [x y] ...)))" [_ _ p & specs] (emit-extend-protocol p specs)) + +(core/defn core-reify + [_ _ & impls] + (core/let [t (gensym "t_reify_")] + `(do + (deftype ~t [] + ~@impls) + (new ~t)))) diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index 64fd01dd..1deb91af 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -558,11 +558,11 @@ (bar (->Foo) 1 2)))))) (deftest satisfies?-test - #_#_(is (jsv! '(do (defprotocol IFoo) - (satisfies? (reify IFoo))))) + (is (jsv! '(do (defprotocol IFoo) + (satisfies? IFoo (reify IFoo))))) (is (jsv! '(do (defprotocol IFoo (-foo [_])) - (satisfies? (reify IFoo - (-foo [_] "bar")))))) + (satisfies? IFoo (reify IFoo + (-foo [_] "bar")))))) (is (jsv! '(do (defprotocol IFoo) (deftype Foo [] IFoo) (satisfies? IFoo (->Foo))))) @@ -576,6 +576,22 @@ (extend-type string IFoo) (satisfies? IFoo "bar"))))) +(deftest reify-test + (is (jsv! '(do (defprotocol IFoo (-foo [_])) + (defprotocol IBar (-bar [_])) + (let [r (reify IFoo (-foo [_] :foo) + IBar (-bar [_] :bar))] + (and (satisfies? IFoo r) (satisfies? IBar r)))))) + (is (= "b" (jsv! '(do (defprotocol IFoo (-foo [_]) (-bar [_])) + (-foo (reify IFoo + (-foo [this] (-bar this)) + (-bar [_] "b"))))))) + (is (eq #js [10 20 30] + (jsv! '(do (defprotocol IFoo (-foo [_])) + (let [xs [10 20 30]] + (mapv (fn [x] (-foo (reify IFoo (-foo [_] x)))) + xs))))))) + (deftest set-test (is (eq (js/Set. #js [1 2 3]) (jsv! #{1 2 3}))) (is (eq (js/Set. [1 2 3]) (jsv! '(set [1 2 3])))) From f6a91832f5d7bf2040f59aef2e21dfbc8a1f4def Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Wed, 13 May 2026 12:54:11 -0400 Subject: [PATCH 2/2] Add reify test --- test/squint/compiler_test.cljs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index 1deb91af..1e22250c 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -590,7 +590,20 @@ (jsv! '(do (defprotocol IFoo (-foo [_])) (let [xs [10 20 30]] (mapv (fn [x] (-foo (reify IFoo (-foo [_] x)))) - xs))))))) + xs)))))) + (is (true? (jsv! '(do (defprotocol P + (a? [h]) + (b? [h]) + (c [h])) + (defn mk-p [v] + (reify P + (a? [_] true) + (b? [_] false) + (c [_] v))) + (let [h (mk-p :foo)] + (and (a? h) + (not (b? h)) + (= :foo (c h))))))))) (deftest set-test (is (eq (js/Set. #js [1 2 3]) (jsv! #{1 2 3})))