Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Fix [#815](https://github.com/squint-cljs/squint/issues/815): `str` wrapping known-numeric infix expressions in `??''`, which esbuild flagged as `suspicious-nullish-coalescing`.
- Fix [#820](https://github.com/squint-cljs/squint/issues/820): `:macros` option silently ignored when passed to `compileString` / `compileStringEx` from JavaScript callers (string keys were keyword-ized by `clj-ize-opts` and no longer matched the symbol-keyed macro lookups in `compile*`).
- [#817](https://github.com/squint-cljs/squint/issues/817): add minimal `reify`

## 0.11.189

Expand Down
1 change: 1 addition & 0 deletions src/squint/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand Down
8 changes: 8 additions & 0 deletions src/squint/internal/protocols.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
37 changes: 33 additions & 4 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
Expand All @@ -576,6 +576,35 @@
(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))))))
(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})))
(is (eq (js/Set. [1 2 3]) (jsv! '(set [1 2 3]))))
Expand Down
Loading