Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #255: fn literal with rest args #600

Merged
merged 2 commits into from
Dec 29, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

[Squint](https://github.com/squint-cljs/squint): Light-weight ClojureScript dialect

## v0.8.132 (2024-12-29)

- Fix [#255](https://github.com/squint-cljs/squint/issues/255): fn literal with rest args

## v0.8.131 (2024-12-21)

- [#596](https://github.com/squint-cljs/squint/issues/596): fix unary division to produce reciprocal
Expand Down
40 changes: 23 additions & 17 deletions src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -834,23 +834,29 @@ break;}" body)
signature (first expr)
arrow? (or (:arrow env) (:=> (meta signature)))
env (assoc env :arrow arrow?)]
(-> (if name
(let [body (rest expr)]
(str (when *async*
"async ") "function"
;; TODO: why is this duplicated here and in emit-function?
(when (:gen env)
"*")
" "
(munge name) " "
(emit-function env name signature body true)))
(let [body (rest expr)]
(str (emit-function env nil signature body))))
(cond-> (and
(not (:squint.internal.fn/def opts))
(not arrow?)
(= :expr (:context env))) (wrap-parens))
(emit-return env))))
(if (some #(= '& %) signature)
;; this still needs macro-expansion, see issue #599
(let [new-f (with-meta
(cons 'fn expr)
(meta expr))]
(emit new-f env))
(-> (if name
(let [body (rest expr)]
(str (when *async*
"async ") "function"
;; TODO: why is this duplicated here and in emit-function?
(when (:gen env)
"*")
" "
(munge name) " "
(emit-function env name signature body true)))
(let [body (rest expr)]
(str (emit-function env nil signature body))))
(cond-> (and
(not (:squint.internal.fn/def opts))
(not arrow?)
(= :expr (:context env))) (wrap-parens))
(emit-return env)))))

(defmethod emit-special 'fn* [_type env [_fn & sigs :as expr]]
(let [m (meta expr)
Expand Down
3 changes: 3 additions & 0 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2349,5 +2349,8 @@ new Foo();")
(is (= 0.5 (jsv! "(/ 2)")))
(is (= 0.5 (jsv! "(let [f (fn [] (/ 2))] (f))"))))

(deftest issue-599-test
(is (eq [1 2 3] (jsv! "(def f #(apply vector %&)) (f 1 2 3)"))))

(defn init []
(t/run-tests 'squint.compiler-test 'squint.jsx-test 'squint.string-test 'squint.html-test))
Loading