squint-cljs 0.12.192 → 0.13.194

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ function setHasEquiv(s, v) {
22
22
  }
23
23
 
24
24
  // Map<any, Set<any>> insert with value equality on both keys and
25
- // members so a preference/ancestry relation expressed with freshly
25
+ // members - so a preference/ancestry relation expressed with freshly
26
26
  // allocated vectors like [:km :m] reads back the same as the original.
27
27
  // Without this, everything that keys on dispatch values (prefer tables,
28
28
  // hierarchy maps) silently loses entries for compound keys.
@@ -77,9 +77,9 @@ function _deriveInto(h, tag, parent) {
77
77
  }
78
78
  addRel(h.parents, tag, parent);
79
79
  // Matches Clojure's derive: new ancestor relations flow to
80
- // { tag and everything under tag } × { parent and everything above parent }.
80
+ // { tag and everything under tag } x { parent and everything above parent }.
81
81
  // Crucially, the left side is the DESCENDANTS of tag (plus tag), not
82
- // its ancestors deriving 'tag isa parent' must not make tag's
82
+ // its ancestors - deriving 'tag isa parent' must not make tag's
83
83
  // existing ancestors also isa parent.
84
84
  const withSelf = (m, t) => {
85
85
  const acc = new Set([t]);
@@ -195,7 +195,7 @@ class MultiFn {
195
195
  this.methodCache = new Map();
196
196
  this.cachedHierarchy = this.hierarchy.deref();
197
197
  // defaultDispatchVal is immutable after construction, so the
198
- // resolved default fn only changes when methodTable changes
198
+ // resolved default fn only changes when methodTable changes -
199
199
  // which always routes through resetCache. Memoize here so
200
200
  // getMethod's no-match branch is O(1).
201
201
  const defKey = findKeyByEquiv(this.methodTable, this.defaultDispatchVal);
@@ -238,8 +238,8 @@ class MultiFn {
238
238
  // Two-path cache read: primitives hit Map.get in O(1); non-primitive
239
239
  // dispatch values (typically vectors) scan the cache with _EQ_ so
240
240
  // freshly-allocated structurally-equal vectors hit prior entries.
241
- // Previously non-primitives skipped the cache entirely every
242
- // dispatch redid findBest, which scans methodTable × _isa cost.
241
+ // Previously non-primitives skipped the cache entirely - every
242
+ // dispatch redid findBest, which scans methodTable x _isa cost.
243
243
  if (isPrimitive(val)) {
244
244
  const cached = this.methodCache.get(val);
245
245
  if (cached !== undefined) return cached;
@@ -270,10 +270,10 @@ class MultiFn {
270
270
  export function defmulti(name, dispatchFn, opts) {
271
271
  opts = opts || {};
272
272
  const defaultVal = 'default' in opts ? opts.default : 'default';
273
- // Accept three shapes for :hierarchy
274
- // (a) omitted defer to the global hierarchy
275
- // (b) a deref-able ref (atom/var-like) use as-is
276
- // (c) a plain hierarchy (the result of make-hierarchy) wrap so
273
+ // Accept three shapes for :hierarchy -
274
+ // (a) omitted -> defer to the global hierarchy
275
+ // (b) a deref-able ref (atom/var-like) -> use as-is
276
+ // (c) a plain hierarchy (the result of make-hierarchy) -> wrap so
277
277
  // MultiFn can call .deref() on it uniformly. The wrapped form
278
278
  // is a frozen snapshot of that hierarchy at defmulti time.
279
279
  let hierarchy;
package/src/squint/set.js CHANGED
@@ -24,7 +24,7 @@ export function intersection(...xs) {
24
24
  switch (xs.length) {
25
25
  case 0: return null;
26
26
  case 1: return xs[0];
27
- case 2: return xs[0].length > xs[1].length ?
27
+ case 2: return xs[0].size > xs[1].size ?
28
28
  _intersection2(xs[0], xs[1]) :
29
29
  _intersection2(xs[1], xs[0]);
30
30
  default: return _bubble_max_key((x) => 0 - x.size, xs).reduce(_intersection2);
@@ -62,8 +62,8 @@ export function union(...xs) {
62
62
  switch (xs.length) {
63
63
  case 0: return null;
64
64
  case 1: return xs[0];
65
- case 2: return xs[0].length > xs[1].length ?
66
- _union2(xs[0], xs[1]) :
65
+ case 2: return xs[0].size > xs[1].size ?
66
+ _union2(xs[0], xs[1]) :
67
67
  _union2(xs[1], xs[0]);
68
68
  default: return _bubble_max_key((x) => x.size, xs).reduce(_union2);
69
69
  }
@@ -40,7 +40,7 @@ export function trimr(s) {
40
40
  }
41
41
 
42
42
  function discardTrailingIfNeeded(limit, v) {
43
- if (limit == null && v.length > 1) {
43
+ if ((limit == null || limit === 0) && v.length > 1) {
44
44
  for (;;)
45
45
  if (v[v.length - 1] === "") {
46
46
  v.pop();
@@ -50,8 +50,25 @@ function discardTrailingIfNeeded(limit, v) {
50
50
  }
51
51
 
52
52
  export function split(s, re, limit) {
53
- const split = s.split(re, limit);
54
- return discardTrailingIfNeeded(limit, split);
53
+ // Clojure's limit caps the number of splits and keeps the remainder, unlike
54
+ // JS String.prototype.split which truncates the result. Only a positive
55
+ // limit changes behaviour; <1 (or unset) does a full split, with trailing
56
+ // empties discarded when the limit is 0 / unset.
57
+ if (limit == null || limit < 1) {
58
+ return discardTrailingIfNeeded(limit, s.split(re));
59
+ }
60
+ const parts = [];
61
+ let rem = s;
62
+ while (limit > 1) {
63
+ const m = rem.match(re);
64
+ if (m == null) break;
65
+ const idx = m.index;
66
+ parts.push(rem.substring(0, idx));
67
+ rem = rem.substring(idx + m[0].length);
68
+ limit--;
69
+ }
70
+ parts.push(rem);
71
+ return parts;
55
72
  }
56
73
 
57
74
  export function starts_with_QMARK_(s, substr) {
@@ -4,9 +4,9 @@ import * as clojure_DOT_string from 'squint-cljs/src/squint/string.js';
4
4
  var _STAR_current_env_STAR_ = null;
5
5
  var _STAR_current_reporter_STAR_ = "cljs.test/default";
6
6
  var current_reporter = function () {
7
- const or__23476__auto__1 = _STAR_current_reporter_STAR_;
8
- if (squint_core.truth_(or__23476__auto__1)) {
9
- return or__23476__auto__1} else {
7
+ const or__23719__auto__1 = _STAR_current_reporter_STAR_;
8
+ if (squint_core.truth_(or__23719__auto__1)) {
9
+ return or__23719__auto__1} else {
10
10
  return "cljs.test/default"};
11
11
 
12
12
  };
@@ -15,9 +15,9 @@ return ({"report-counters": ({"test": 0, "pass": 0, "fail": 0, "error": 0}), "te
15
15
 
16
16
  };
17
17
  var get_current_env = function () {
18
- const or__23476__auto__1 = _STAR_current_env_STAR_;
19
- if (squint_core.truth_(or__23476__auto__1)) {
20
- return or__23476__auto__1} else {
18
+ const or__23719__auto__1 = _STAR_current_env_STAR_;
19
+ if (squint_core.truth_(or__23719__auto__1)) {
20
+ return or__23719__auto__1} else {
21
21
  return empty_env()};
22
22
 
23
23
  };
@@ -34,10 +34,10 @@ return null;
34
34
  var update_current_env_BANG_ = (() => {
35
35
  const f1 = (function (var_args) {
36
36
  const args21 = [];
37
- const len__23403__auto__2 = arguments.length;
37
+ const len__23467__auto__2 = arguments.length;
38
38
  let i33 = 0;
39
39
  while(true){
40
- if ((i33 < len__23403__auto__2)) {
40
+ if ((i33 < len__23467__auto__2)) {
41
41
  args21.push((arguments[i33]));
42
42
  let G__4 = (i33 + 1);
43
43
  i33 = G__4;
@@ -45,8 +45,8 @@ continue;
45
45
  };break;
46
46
  }
47
47
  ;
48
- const argseq__23572__auto__5 = (((2 < args21.length)) ? (args21.slice(2)) : (null));
49
- return f1.cljs$core$IFn$_invoke$arity$variadic((arguments[0]), (arguments[1]), argseq__23572__auto__5);
48
+ const argseq__23695__auto__5 = (((2 < args21.length)) ? (args21.slice(2)) : (null));
49
+ return f1.cljs$core$IFn$_invoke$arity$variadic((arguments[0]), (arguments[1]), argseq__23695__auto__5);
50
50
 
51
51
  });
52
52
  f1.cljs$core$IFn$_invoke$arity$variadic = (function (ks, f, args) {
@@ -60,17 +60,17 @@ return f1;
60
60
 
61
61
  })();
62
62
  var testing_contexts_str = function () {
63
- const temp__23113__auto__1 = squint_core.seq(squint_core.get(get_current_env(), "testing-contexts"));
64
- if (squint_core.truth_(temp__23113__auto__1)) {
65
- const contexts2 = temp__23113__auto__1;
63
+ const temp__23371__auto__1 = squint_core.seq(squint_core.get(get_current_env(), "testing-contexts"));
64
+ if (squint_core.truth_(temp__23371__auto__1)) {
65
+ const contexts2 = temp__23371__auto__1;
66
66
  return clojure_DOT_string.join(" ", squint_core.reverse(contexts2));
67
67
  };
68
68
 
69
69
  };
70
70
  var testing_vars_str = function () {
71
- const temp__23113__auto__1 = squint_core.seq(squint_core.get(get_current_env(), "testing-vars"));
72
- if (squint_core.truth_(temp__23113__auto__1)) {
73
- const vars2 = temp__23113__auto__1;
71
+ const temp__23371__auto__1 = squint_core.seq(squint_core.get(get_current_env(), "testing-vars"));
72
+ if (squint_core.truth_(temp__23371__auto__1)) {
73
+ const vars2 = temp__23371__auto__1;
74
74
  return clojure_DOT_string.join(" ", squint_core.map(squint_core.str, vars2));
75
75
  };
76
76
 
@@ -85,10 +85,10 @@ var current_test_str = function () {
85
85
  const vars1 = testing_vars_str();
86
86
  const ctx2 = testing_contexts_str();
87
87
  if (squint_core.truth_((() => {
88
- const and__23514__auto__3 = vars1;
89
- if (squint_core.truth_(and__23514__auto__3)) {
88
+ const and__23759__auto__3 = vars1;
89
+ if (squint_core.truth_(and__23759__auto__3)) {
90
90
  return ctx2} else {
91
- return and__23514__auto__3};
91
+ return and__23759__auto__3};
92
92
 
93
93
  })())) {
94
94
  return `${vars1??''}${" "}${ctx2??''}`} else {
@@ -107,12 +107,12 @@ const line3 = squint_core.get(map__12, "line");
107
107
  const column4 = squint_core.get(map__12, "column");
108
108
  const file5 = squint_core.get(map__12, "file");
109
109
  if (squint_core.truth_((() => {
110
- const or__23476__auto__6 = line3;
111
- if (squint_core.truth_(or__23476__auto__6)) {
112
- return or__23476__auto__6} else {
113
- const or__23476__auto__7 = column4;
114
- if (squint_core.truth_(or__23476__auto__7)) {
115
- return or__23476__auto__7} else {
110
+ const or__23719__auto__6 = line3;
111
+ if (squint_core.truth_(or__23719__auto__6)) {
112
+ return or__23719__auto__6} else {
113
+ const or__23719__auto__7 = column4;
114
+ if (squint_core.truth_(or__23719__auto__7)) {
115
+ return or__23719__auto__7} else {
116
116
  return file5};
117
117
  };
118
118
 
@@ -136,9 +136,9 @@ return inc_report_counter_BANG_("pass");
136
136
  squint_multi.defmethod(report, ["cljs.test/default", "fail"], (function (m) {
137
137
  inc_report_counter_BANG_("fail");
138
138
  console.error(`${"FAIL in "}${current_test_str()??''}${(() => {
139
- const temp__23113__auto__1 = report_loc(m);
140
- if (squint_core.truth_(temp__23113__auto__1)) {
141
- const l2 = temp__23113__auto__1;
139
+ const temp__23371__auto__1 = report_loc(m);
140
+ if (squint_core.truth_(temp__23371__auto__1)) {
141
+ const l2 = temp__23371__auto__1;
142
142
  return `${" ("}${l2??''}${")"}`;
143
143
  };
144
144
 
@@ -152,9 +152,9 @@ return console.error(" actual:", squint_core.pr_str(squint_core.get(m, "actua
152
152
  squint_multi.defmethod(report, ["cljs.test/default", "error"], (function (m) {
153
153
  inc_report_counter_BANG_("error");
154
154
  console.error(`${"ERROR in "}${current_test_str()??''}${(() => {
155
- const temp__23113__auto__1 = report_loc(m);
156
- if (squint_core.truth_(temp__23113__auto__1)) {
157
- const l2 = temp__23113__auto__1;
155
+ const temp__23371__auto__1 = report_loc(m);
156
+ if (squint_core.truth_(temp__23371__auto__1)) {
157
+ const l2 = temp__23371__auto__1;
158
158
  return `${" ("}${l2??''}${")"}`;
159
159
  };
160
160
 
@@ -197,10 +197,10 @@ return ((squint_core.get(results, "fail", 0) === 0) && (squint_core.get(results,
197
197
 
198
198
  };
199
199
  var async_QMARK_ = function (x) {
200
- const c__23442__auto__1 = Promise;
201
- const x__23443__auto__2 = x;
202
- const ret__23444__auto__3 = (x__23443__auto__2 instanceof c__23442__auto__1);
203
- return ret__23444__auto__3;
200
+ const c__23690__auto__1 = Promise;
201
+ const x__23691__auto__2 = x;
202
+ const ret__23692__auto__3 = (x__23691__auto__2 instanceof c__23690__auto__1);
203
+ return ret__23692__auto__3;
204
204
 
205
205
  };
206
206
  var wrap_async = function (setup, teardown) {
@@ -344,9 +344,9 @@ return f20;
344
344
  var test_var = function (v) {
345
345
  if (squint_core.truth_(squint_core.fn_QMARK_(v))) {
346
346
  const test_name1 = (() => {
347
- const or__23476__auto__2 = squint_core.get(squint_core.meta(v), "name");
348
- if (squint_core.truth_(or__23476__auto__2)) {
349
- return or__23476__auto__2} else {
347
+ const or__23719__auto__2 = squint_core.get(squint_core.meta(v), "name");
348
+ if (squint_core.truth_(or__23719__auto__2)) {
349
+ return or__23719__auto__2} else {
350
350
  return "anonymous"};
351
351
 
352
352
  })();
@@ -469,10 +469,10 @@ var fresh_counters = ({"test": 0, "pass": 0, "fail": 0, "error": 0});
469
469
  var run_tests = (() => {
470
470
  const f26 = (function (var_args) {
471
471
  const args271 = [];
472
- const len__23403__auto__2 = arguments.length;
472
+ const len__23467__auto__2 = arguments.length;
473
473
  let i283 = 0;
474
474
  while(true){
475
- if ((i283 < len__23403__auto__2)) {
475
+ if ((i283 < len__23467__auto__2)) {
476
476
  args271.push((arguments[i283]));
477
477
  let G__4 = (i283 + 1);
478
478
  i283 = G__4;
@@ -480,8 +480,8 @@ continue;
480
480
  };break;
481
481
  }
482
482
  ;
483
- const argseq__23572__auto__5 = (((0 < args271.length)) ? (args271.slice(0)) : (null));
484
- return f26.cljs$core$IFn$_invoke$arity$variadic(argseq__23572__auto__5);
483
+ const argseq__23695__auto__5 = (((0 < args271.length)) ? (args271.slice(0)) : (null));
484
+ return f26.cljs$core$IFn$_invoke$arity$variadic(argseq__23695__auto__5);
485
485
 
486
486
  });
487
487
  f26.cljs$core$IFn$_invoke$arity$variadic = (function (args) {
@@ -0,0 +1,103 @@
1
+ import * as squint_core from 'squint-cljs/core.js';
2
+ var walk = function (inner, outer, form) {
3
+ if (squint_core.truth_(squint_core.list_QMARK_(form))) {
4
+ return outer(squint_core.with_meta(squint_core.apply(squint_core.list, squint_core.map(inner, form)), squint_core.meta(form)))} else {
5
+ if (squint_core.truth_(squint_core.map_QMARK_(form))) {
6
+ return outer(squint_core.into(squint_core.empty(form), squint_core.map(inner, form)))} else {
7
+ if (squint_core.truth_(squint_core.vector_QMARK_(form))) {
8
+ return outer(squint_core.into(squint_core.empty(form), squint_core.map(inner, form)))} else {
9
+ if (squint_core.truth_(squint_core.set_QMARK_(form))) {
10
+ return outer(squint_core.into(squint_core.empty(form), squint_core.map(inner, form)))} else {
11
+ if (squint_core.truth_((() => {
12
+ const and__28252__auto__1 = squint_core.seq_QMARK_(form);
13
+ if (squint_core.truth_(and__28252__auto__1)) {
14
+ return squint_core.not(squint_core.string_QMARK_(form))} else {
15
+ return and__28252__auto__1};
16
+
17
+ })())) {
18
+ return outer(squint_core.with_meta(squint_core.vec(squint_core.map(inner, form)), squint_core.meta(form)))} else {
19
+ if ("else") {
20
+ return outer(form)} else {
21
+ return null}}}}}};
22
+
23
+ };
24
+ var postwalk = function (f, form) {
25
+ return walk((function (x) {
26
+ return postwalk(f, x);
27
+
28
+ }), f, form);
29
+
30
+ };
31
+ var prewalk = function (f, form) {
32
+ return walk((function (x) {
33
+ return prewalk(f, x);
34
+
35
+ }), squint_core.identity, f(form));
36
+
37
+ };
38
+ var postwalk_replace = function (smap, form) {
39
+ return postwalk((function (x) {
40
+ if (squint_core.truth_(squint_core.contains_QMARK_(smap, x))) {
41
+ return squint_core.get(smap, x)} else {
42
+ return x};
43
+
44
+ }), form);
45
+
46
+ };
47
+ var prewalk_replace = function (smap, form) {
48
+ return prewalk((function (x) {
49
+ if (squint_core.truth_(squint_core.contains_QMARK_(smap, x))) {
50
+ return squint_core.get(smap, x)} else {
51
+ return x};
52
+
53
+ }), form);
54
+
55
+ };
56
+ var postwalk_demo = function (form) {
57
+ return postwalk((function (x) {
58
+ squint_core.println("Walked:", squint_core.pr_str(x));
59
+ return x;
60
+
61
+ }), form);
62
+
63
+ };
64
+ var prewalk_demo = function (form) {
65
+ return prewalk((function (x) {
66
+ squint_core.println("Walked:", squint_core.pr_str(x));
67
+ return x;
68
+
69
+ }), form);
70
+
71
+ };
72
+ var keywordize_keys = function (m) {
73
+ return postwalk((function (x) {
74
+ if (squint_core.truth_(squint_core.map_QMARK_(x))) {
75
+ return squint_core.into(squint_core.empty(x), squint_core.map((function (p__1) {
76
+ const vec__14 = p__1;
77
+ const k5 = squint_core.nth(vec__14, 0, null);
78
+ const v6 = squint_core.nth(vec__14, 1, null);
79
+ return [squint_core.name(k5), v6];
80
+
81
+ }), x))} else {
82
+ return x};
83
+
84
+ }), m);
85
+
86
+ };
87
+ var stringify_keys = function (m) {
88
+ return postwalk((function (x) {
89
+ if (squint_core.truth_(squint_core.map_QMARK_(x))) {
90
+ return squint_core.into(squint_core.empty(x), squint_core.map((function (p__2) {
91
+ const vec__14 = p__2;
92
+ const k5 = squint_core.nth(vec__14, 0, null);
93
+ const v6 = squint_core.nth(vec__14, 1, null);
94
+ return [squint_core.name(k5), v6];
95
+
96
+ }), x))} else {
97
+ return x};
98
+
99
+ }), m);
100
+
101
+ };
102
+
103
+ export { stringify_keys, postwalk_demo, postwalk, walk, postwalk_replace, prewalk, keywordize_keys, prewalk_demo, prewalk_replace }
package/vite.js CHANGED
@@ -18,7 +18,7 @@
18
18
  // An optional dev-only HTTP endpoint (POST /__repl_eval, off by default, see
19
19
  // ENABLE_HTTP_EVAL) drives the same eval path with curl, handy without an editor.
20
20
 
21
- import { compileFile, readConfig } from './node-api.js';
21
+ import { compileFile, readConfig, depsPaths } from './node-api.js';
22
22
  import {
23
23
  startServer,
24
24
  handleBrowserMessage,
@@ -77,8 +77,32 @@ async function __squintImport(spec) {
77
77
  const url = await res.text();
78
78
  return __rawImport(url);
79
79
  }
80
+ // JS-interop completion against the page's globalThis. Mirrors js-completions
81
+ // in squint.repl.nrepl-server (node side) so browser and node behave the same.
82
+ function __jsCompletions(prefix) {
83
+ if (!prefix || !prefix.startsWith('js/')) return [];
84
+ const s = prefix.slice(3);
85
+ const parts = s.split('.');
86
+ const partial = parts[parts.length - 1];
87
+ const path = parts.slice(0, -1);
88
+ let obj = globalThis;
89
+ for (const seg of path) { obj = obj == null ? obj : obj[seg]; }
90
+ if (obj == null) return [];
91
+ const acc = new Set();
92
+ for (let o = obj; o != null; o = Object.getPrototypeOf(o)) {
93
+ for (const n of Object.getOwnPropertyNames(o)) acc.add(n);
94
+ }
95
+ const pre = 'js/' + (path.length ? path.join('.') + '.' : '');
96
+ return Array.from(acc).filter((n) => n.startsWith(partial)).sort().slice(0, 100).map((n) => pre + n);
97
+ }
80
98
  if (import.meta.hot) {
81
- import.meta.hot.on('squint:nrepl', async ({ op, code, id, session }) => {
99
+ import.meta.hot.on('squint:nrepl', async ({ op, code, id, session, prefix }) => {
100
+ if (op === 'complete-js') {
101
+ import.meta.hot.send('squint:nrepl-reply', {
102
+ op: 'complete-js', id, session, completions: __jsCompletions(prefix),
103
+ });
104
+ return;
105
+ }
82
106
  if (op !== 'eval') return;
83
107
  // bare dynamic imports in eval'd code resolve through __squintImport
84
108
  // (\\s* tolerates squint emitting e.g. \`import ('preact')\` for :refer)
@@ -176,7 +200,14 @@ export default function squint(options = {}) {
176
200
  logger = config.logger ?? console;
177
201
  // squint.edn is the source of truth; plugin options override it.
178
202
  const cfg = readConfig(root) || {};
179
- paths = (options.paths ?? cfg.paths ?? ['src']).map((p) => resolve(root, p));
203
+ // :deps in squint.edn resolve (via `clojure -Spath`) to absolute source
204
+ // dirs; add them to paths so the dep namespaces are compiled and their
205
+ // requires resolve. depsPaths reads squint.edn itself: the deps map has
206
+ // symbol keys that would not survive readConfig's clj<->js round-trip.
207
+ const depDirs = options.paths ? [] : depsPaths(root);
208
+ paths = [...(options.paths ?? cfg.paths ?? ['src']), ...depDirs].map((p) =>
209
+ resolve(root, p),
210
+ );
180
211
  outDir = options.outDir ?? cfg['output-dir'] ?? 'js';
181
212
  extension = options.extension ?? cfg.extension ?? 'js';
182
213
  main = options.main ?? cfg.main;