Skip to content

Commit

Permalink
v0.4.46
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 16, 2023
1 parent d6e5bde commit 3d30212
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

[Squint](https://github.com/squint-cljs/squint): ClojureScript syntax to JavaScript compiler

## 0.4.46 (2023-11-16)

- Add `min-key` and `max-key`
- Fix `defonce` in REPL-mode

## 0.4.45 (2023-11-16)

- Fix `doseq` and `for` when binding name clashes with core var
Expand Down
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<body>
<div style="float: right;">
<a href="https://gitHub.com/squint-cljs/squint"><img src="https://img.shields.io/github/stars/squint-cljs/squint.svg?style=social&label=Star"></a></div>
<div id="editor" style="border: 1px solid grey; border-radius: 10px; margin-bottom: 10px;"">
<div id="editor" style="border: 1px solid grey; border-radius: 10px; margin-bottom: 10px;">
</div>
<div>
<button onClick="compile()">
Expand All @@ -140,7 +140,8 @@
</button>
</div>
<div>
<pre><code id="compiledCode"></code></pre>
<pre>
<code style="display: inline-block;white-space: normal;max-width:80%; word-break:break-all; word-wrap:break-word" id="compiledCode"></code></pre>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "squint-cljs",
"type": "module",
"sideEffects": false,
"version": "0.4.45",
"version": "0.4.46",
"files": [
"core.js",
"src/squint/core.js",
Expand Down
2 changes: 2 additions & 0 deletions resources/squint/core.edn
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@
mapcat
mapv
max
max_key
merge
merge_with
meta
min
min_key
mod
neg_QMARK_
next
Expand Down
2 changes: 1 addition & 1 deletion src/squint/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
(emit-return nil enc-env))))

(defmethod emit-special 'squint.impl/defonce [_type env [_defonce name init]]
(emit (list 'do (list 'js* (str "var " name ";\n"))
(emit (list 'do (list 'js* (str "var " (munge name) ";\n"))
(if (:repl env)
`(when-not (exists? ~(symbol *cljs-ns* name))
~(vary-meta `(def ~name ~init)
Expand Down
38 changes: 38 additions & 0 deletions src/squint/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1637,3 +1637,41 @@ export function find(m, k) {
export function mod(x, y) {
return (x % y + y) % y;
}

export function min_key(k, x, y, ...more) {
if (y === undefined) {
return x;
}
if (more.length == 0) {
return (k(x) < k(y)) ? x : y;
}
var kx = k(x);
var min = x;
more.forEach((y) => {
var ky = k(y);
if (ky <= kx) {
kx = ky;
min = y;
}
});
return min;
}

export function max_key(k, x, y, ...more) {
if (y === undefined) {
return x;
}
if (more.length == 0) {
return (k(x) > k(y)) ? x : y;
}
var kx = k(x);
var max = x;
more.forEach((y) => {
var ky = k(y);
if (ky >= kx) {
kx = ky;
max = y;
}
});
return max;
}
10 changes: 10 additions & 0 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,5 +1547,15 @@
(deftest set!-test
(is (eq 1 (jsv! "(def x {}) (set! x -foo 1) (.-foo x)"))))

(deftest min-max-key-test
(jsv! (eq 1 "(min-key #(:foo %) {:foo 1})"))
(jsv! (eq 1 "(min-key #(:foo %) {:foo 1} {:foo 2})"))
(jsv! (eq 1 "(min-key #(:foo %) {:foo 2} {:foo 1})"))
(jsv! (eq 1 "(min-key #(:foo %) {:foo 10} {:foo 2} {:foo 1})"))
(jsv! (eq 1 "(max-key #(:foo %) {:foo 1})"))
(jsv! (eq 2 "(max-key #(:foo %) {:foo 1} {:foo 2})"))
(jsv! (eq 2 "(max-key #(:foo %) {:foo 2} {:foo 1} )"))
(jsv! (eq 10 "(max-key #(:foo %) {:foo 2} {:foo 10} {:foo 1})")))

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

0 comments on commit 3d30212

Please sign in to comment.