conjure-js 0.0.12 → 0.0.13

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.
Files changed (77) hide show
  1. package/dist-cli/conjure-js.mjs +9360 -5298
  2. package/dist-vite-plugin/index.mjs +9463 -5185
  3. package/package.json +3 -1
  4. package/src/bin/cli.ts +2 -2
  5. package/src/bin/nrepl-symbol.ts +150 -0
  6. package/src/bin/nrepl.ts +289 -167
  7. package/src/bin/version.ts +1 -1
  8. package/src/clojure/core.clj +757 -29
  9. package/src/clojure/core.clj.d.ts +75 -131
  10. package/src/clojure/generated/builtin-namespace-registry.ts +4 -0
  11. package/src/clojure/generated/clojure-core-source.ts +758 -29
  12. package/src/clojure/generated/clojure-set-source.ts +136 -0
  13. package/src/clojure/generated/clojure-walk-source.ts +72 -0
  14. package/src/clojure/set.clj +132 -0
  15. package/src/clojure/set.clj.d.ts +20 -0
  16. package/src/clojure/string.clj.d.ts +14 -0
  17. package/src/clojure/walk.clj +68 -0
  18. package/src/clojure/walk.clj.d.ts +7 -0
  19. package/src/core/assertions.ts +114 -6
  20. package/src/core/bootstrap.ts +337 -0
  21. package/src/core/conversions.ts +48 -31
  22. package/src/core/core-module.ts +303 -0
  23. package/src/core/env.ts +20 -6
  24. package/src/core/evaluator/apply.ts +40 -25
  25. package/src/core/evaluator/arity.ts +8 -8
  26. package/src/core/evaluator/async-evaluator.ts +565 -0
  27. package/src/core/evaluator/collections.ts +28 -5
  28. package/src/core/evaluator/destructure.ts +180 -69
  29. package/src/core/evaluator/dispatch.ts +12 -14
  30. package/src/core/evaluator/evaluate.ts +22 -20
  31. package/src/core/evaluator/expand.ts +45 -15
  32. package/src/core/evaluator/form-parsers.ts +178 -0
  33. package/src/core/evaluator/index.ts +7 -9
  34. package/src/core/evaluator/js-interop.ts +189 -0
  35. package/src/core/evaluator/quasiquote.ts +14 -8
  36. package/src/core/evaluator/recur-check.ts +6 -6
  37. package/src/core/evaluator/special-forms.ts +234 -191
  38. package/src/core/factories.ts +182 -3
  39. package/src/core/index.ts +54 -4
  40. package/src/core/module.ts +136 -0
  41. package/src/core/ns-forms.ts +107 -0
  42. package/src/core/printer.ts +371 -11
  43. package/src/core/reader.ts +84 -33
  44. package/src/core/registry.ts +209 -0
  45. package/src/core/runtime.ts +376 -0
  46. package/src/core/session.ts +253 -487
  47. package/src/core/stdlib/arithmetic.ts +528 -194
  48. package/src/core/stdlib/async-fns.ts +132 -0
  49. package/src/core/stdlib/atoms.ts +291 -56
  50. package/src/core/stdlib/errors.ts +54 -50
  51. package/src/core/stdlib/hof.ts +82 -166
  52. package/src/core/stdlib/js-namespace.ts +344 -0
  53. package/src/core/stdlib/lazy.ts +34 -0
  54. package/src/core/stdlib/maps-sets.ts +322 -0
  55. package/src/core/stdlib/meta.ts +61 -30
  56. package/src/core/stdlib/predicates.ts +325 -187
  57. package/src/core/stdlib/regex.ts +126 -98
  58. package/src/core/stdlib/seq.ts +564 -0
  59. package/src/core/stdlib/strings.ts +164 -135
  60. package/src/core/stdlib/transducers.ts +95 -100
  61. package/src/core/stdlib/utils.ts +292 -130
  62. package/src/core/stdlib/vars.ts +27 -27
  63. package/src/core/stdlib/vectors.ts +122 -0
  64. package/src/core/tokenizer.ts +2 -2
  65. package/src/core/transformations.ts +117 -9
  66. package/src/core/types.ts +98 -2
  67. package/src/host/node-host-module.ts +74 -0
  68. package/src/{vite-plugin-clj/nrepl-relay.ts → nrepl/relay.ts} +72 -11
  69. package/src/vite-plugin-clj/codegen.ts +87 -95
  70. package/src/vite-plugin-clj/index.ts +178 -23
  71. package/src/vite-plugin-clj/namespace-utils.ts +39 -0
  72. package/src/vite-plugin-clj/static-analysis.ts +211 -0
  73. package/src/clojure/demo.clj +0 -72
  74. package/src/clojure/demo.clj.d.ts +0 -0
  75. package/src/core/core-env.ts +0 -61
  76. package/src/core/stdlib/collections.ts +0 -739
  77. package/src/host/node.ts +0 -55
@@ -1,21 +1,8 @@
1
1
  // Transducer protocol primitives: reduced, volatile!, transduce
2
2
 
3
- import {
4
- isAFunction,
5
- isNil,
6
- isReduced,
7
- isSeqable,
8
- isVolatile,
9
- } from '../assertions'
3
+ import { is } from '../assertions'
10
4
  import { EvaluationError } from '../errors'
11
- import {
12
- cljBoolean,
13
- cljNativeFunction,
14
- cljNativeFunctionWithContext,
15
- cljReduced,
16
- cljVolatile,
17
- withDoc,
18
- } from '../factories'
5
+ import { v } from '../factories'
19
6
  import { joinLines, printString } from '../printer'
20
7
  import { toSeq } from '../transformations'
21
8
  import type {
@@ -28,71 +15,76 @@ import type {
28
15
 
29
16
  export const transducerFunctions: Record<string, CljValue> = {
30
17
  // ── Reduced sentinel ────────────────────────────────────────────────────
31
- reduced: withDoc(
32
- cljNativeFunction('reduced', (value: CljValue) => {
18
+ reduced: v
19
+ .nativeFn('reduced', function reducedImpl(value: CljValue) {
33
20
  if (value === undefined) {
34
21
  throw new EvaluationError('reduced expects one argument', {})
35
22
  }
36
- return cljReduced(value)
37
- }),
38
- 'Returns a reduced value, indicating termination of the reduction process.',
39
- [['value']]
40
- ),
41
- 'reduced?': withDoc(
42
- cljNativeFunction('reduced?', (value: CljValue) => {
23
+ return v.reduced(value)
24
+ })
25
+ .doc(
26
+ 'Returns a reduced value, indicating termination of the reduction process.',
27
+ [['value']]
28
+ ),
29
+ 'reduced?': v
30
+ .nativeFn('reduced?', function isReducedImpl(value: CljValue) {
43
31
  if (value === undefined) {
44
32
  throw new EvaluationError('reduced? expects one argument', {})
45
33
  }
46
- return cljBoolean(isReduced(value))
47
- }),
48
- 'Returns true if the given value is a reduced value, false otherwise.',
49
- [['value']]
50
- ),
51
- unreduced: withDoc(
52
- cljNativeFunction('unreduced', (value: CljValue) => {
34
+ return v.boolean(is.reduced(value))
35
+ })
36
+ .doc(
37
+ 'Returns true if the given value is a reduced value, false otherwise.',
38
+ [['value']]
39
+ ),
40
+ unreduced: v
41
+ .nativeFn('unreduced', function unreducedImpl(value: CljValue) {
53
42
  if (value === undefined) {
54
43
  throw new EvaluationError('unreduced expects one argument', {})
55
44
  }
56
- return isReduced(value) ? value.value : value
57
- }),
58
- 'Returns the unreduced value of the given value. If the value is not a reduced value, it is returned unchanged.',
59
- [['value']]
60
- ),
61
- 'ensure-reduced': withDoc(
62
- cljNativeFunction('ensure-reduced', (value: CljValue) => {
45
+ return is.reduced(value) ? value.value : value
46
+ })
47
+ .doc(
48
+ 'Returns the unreduced value of the given value. If the value is not a reduced value, it is returned unchanged.',
49
+ [['value']]
50
+ ),
51
+ 'ensure-reduced': v
52
+ .nativeFn('ensure-reduced', function ensureReducedImpl(value: CljValue) {
63
53
  if (value === undefined) {
64
54
  throw new EvaluationError('ensure-reduced expects one argument', {})
65
55
  }
66
- return isReduced(value) ? value : cljReduced(value)
67
- }),
68
- 'Returns the given value if it is a reduced value, otherwise returns a reduced value with the given value as its value.',
69
- [['value']]
70
- ),
56
+ return is.reduced(value) ? value : v.reduced(value)
57
+ })
58
+ .doc(
59
+ 'Returns the given value if it is a reduced value, otherwise returns a reduced value with the given value as its value.',
60
+ [['value']]
61
+ ),
71
62
 
72
63
  // ── Volatile ─────────────────────────────────────────────────────────────
73
- 'volatile!': withDoc(
74
- cljNativeFunction('volatile!', (value: CljValue) => {
64
+ 'volatile!': v
65
+ .nativeFn('volatile!', function volatileImpl(value: CljValue) {
75
66
  if (value === undefined) {
76
67
  throw new EvaluationError('volatile! expects one argument', {})
77
68
  }
78
- return cljVolatile(value)
79
- }),
80
- 'Returns a volatile value with the given value as its value.',
81
- [['value']]
82
- ),
83
- 'volatile?': withDoc(
84
- cljNativeFunction('volatile?', (value: CljValue) => {
69
+ return v.volatile(value)
70
+ })
71
+ .doc('Returns a volatile value with the given value as its value.', [
72
+ ['value'],
73
+ ]),
74
+ 'volatile?': v
75
+ .nativeFn('volatile?', function isVolatileImpl(value: CljValue) {
85
76
  if (value === undefined) {
86
77
  throw new EvaluationError('volatile? expects one argument', {})
87
78
  }
88
- return cljBoolean(isVolatile(value))
89
- }),
90
- 'Returns true if the given value is a volatile value, false otherwise.',
91
- [['value']]
92
- ),
93
- 'vreset!': withDoc(
94
- cljNativeFunction('vreset!', (vol: CljValue, newVal: CljValue) => {
95
- if (!isVolatile(vol)) {
79
+ return v.boolean(is.volatile(value))
80
+ })
81
+ .doc(
82
+ 'Returns true if the given value is a volatile value, false otherwise.',
83
+ [['value']]
84
+ ),
85
+ 'vreset!': v
86
+ .nativeFn('vreset!', function vresetImpl(vol: CljValue, newVal: CljValue) {
87
+ if (!is.volatile(vol)) {
96
88
  throw new EvaluationError(
97
89
  `vreset! expects a volatile as its first argument, got ${printString(vol)}`,
98
90
  { vol }
@@ -103,27 +95,28 @@ export const transducerFunctions: Record<string, CljValue> = {
103
95
  }
104
96
  vol.value = newVal
105
97
  return newVal
106
- }),
107
- 'Resets the value of the given volatile to the given new value and returns the new value.',
108
- [['vol', 'newVal']]
109
- ),
110
- 'vswap!': withDoc(
111
- cljNativeFunctionWithContext(
98
+ })
99
+ .doc(
100
+ 'Resets the value of the given volatile to the given new value and returns the new value.',
101
+ [['vol', 'newVal']]
102
+ ),
103
+ 'vswap!': v
104
+ .nativeFnCtx(
112
105
  'vswap!',
113
- (
106
+ function vswapImpl(
114
107
  ctx: EvaluationContext,
115
108
  callEnv: Env,
116
109
  vol: CljValue,
117
110
  fn: CljValue,
118
111
  ...extraArgs: CljValue[]
119
- ) => {
120
- if (!isVolatile(vol)) {
112
+ ) {
113
+ if (!is.volatile(vol)) {
121
114
  throw new EvaluationError(
122
115
  `vswap! expects a volatile as its first argument, got ${printString(vol)}`,
123
116
  { vol }
124
117
  )
125
118
  }
126
- if (!isAFunction(fn)) {
119
+ if (!is.aFunction(fn)) {
127
120
  throw new EvaluationError(
128
121
  `vswap! expects a function as its second argument, got ${printString(fn)}`,
129
122
  { fn }
@@ -137,13 +130,14 @@ export const transducerFunctions: Record<string, CljValue> = {
137
130
  vol.value = newVal
138
131
  return newVal
139
132
  }
133
+ )
134
+ .doc(
135
+ 'Applies fn to the current value of the volatile, replacing the current value with the result. Returns the new value.',
136
+ [
137
+ ['vol', 'fn'],
138
+ ['vol', 'fn', '&', 'extraArgs'],
139
+ ]
140
140
  ),
141
- 'Applies fn to the current value of the volatile, replacing the current value with the result. Returns the new value.',
142
- [
143
- ['vol', 'fn'],
144
- ['vol', 'fn', '&', 'extraArgs'],
145
- ]
146
- ),
147
141
 
148
142
  // ── transduce ─────────────────────────────────────────────────────────────
149
143
 
@@ -153,24 +147,24 @@ export const transducerFunctions: Record<string, CljValue> = {
153
147
  // f — bottom reducing function (must support 0-arity when used as 3-arity)
154
148
  // init — initial accumulator value
155
149
  // coll — source collection (nil is treated as empty)
156
- transduce: withDoc(
157
- cljNativeFunctionWithContext(
150
+ transduce: v
151
+ .nativeFnCtx(
158
152
  'transduce',
159
- (
153
+ function transduceImpl(
160
154
  ctx: EvaluationContext,
161
155
  callEnv: Env,
162
156
  xform: CljValue,
163
157
  f: CljValue,
164
158
  init: CljValue,
165
159
  coll: CljValue
166
- ) => {
167
- if (!isAFunction(xform)) {
160
+ ) {
161
+ if (!is.aFunction(xform)) {
168
162
  throw new EvaluationError(
169
163
  `transduce expects a transducer (function) as first argument, got ${printString(xform)}`,
170
164
  { xf: xform }
171
165
  )
172
166
  }
173
- if (!isAFunction(f)) {
167
+ if (!is.aFunction(f)) {
174
168
  throw new EvaluationError(
175
169
  `transduce expects a reducing function as second argument, got ${printString(f)}`,
176
170
  { f }
@@ -206,7 +200,7 @@ export const transducerFunctions: Record<string, CljValue> = {
206
200
  ) as CljFunction | CljNativeFunction
207
201
 
208
202
  // nil collection is treated as empty — skip loop, run completion only
209
- if (isNil(actualColl)) {
203
+ if (is.nil(actualColl)) {
210
204
  return ctx.applyFunction(
211
205
  rf as CljFunction | CljNativeFunction,
212
206
  [actualInit],
@@ -214,7 +208,7 @@ export const transducerFunctions: Record<string, CljValue> = {
214
208
  )
215
209
  }
216
210
 
217
- if (!isSeqable(actualColl)) {
211
+ if (!is.seqable(actualColl)) {
218
212
  throw new EvaluationError(
219
213
  `transduce expects a collection or string as ${coll === undefined ? 'third' : 'fourth'} argument, got ${printString(actualColl)}`,
220
214
  { coll: actualColl }
@@ -227,7 +221,7 @@ export const transducerFunctions: Record<string, CljValue> = {
227
221
  for (const item of items) {
228
222
  // 2-arity call on the composed rf
229
223
  const result = ctx.applyFunction(rf, [acc, item], callEnv)
230
- if (isReduced(result)) {
224
+ if (is.reduced(result)) {
231
225
  acc = result.value
232
226
  break
233
227
  }
@@ -237,20 +231,21 @@ export const transducerFunctions: Record<string, CljValue> = {
237
231
  // Completion (1-arity call on the composed rf)
238
232
  return ctx.applyFunction(rf, [acc], callEnv)
239
233
  }
234
+ )
235
+ .doc(
236
+ joinLines([
237
+ 'reduce with a transformation of f (xf). If init is not',
238
+ 'supplied, (f) will be called to produce it. f should be a reducing',
239
+ 'step function that accepts both 1 and 2 arguments, if it accepts',
240
+ "only 2 you can add the arity-1 with 'completing'. Returns the result",
241
+ 'of applying (the transformed) xf to init and the first item in coll,',
242
+ 'then applying xf to that result and the 2nd item, etc. If coll',
243
+ 'contains no items, returns init and f is not called. Note that',
244
+ 'certain transforms may inject or skip items.',
245
+ ]),
246
+ [
247
+ ['xform', 'f', 'coll'],
248
+ ['xform', 'f', 'init', 'coll'],
249
+ ]
240
250
  ),
241
- joinLines([
242
- 'reduce with a transformation of f (xf). If init is not',
243
- 'supplied, (f) will be called to produce it. f should be a reducing',
244
- 'step function that accepts both 1 and 2 arguments, if it accepts',
245
- "only 2 you can add the arity-1 with 'completing'. Returns the result",
246
- 'of applying (the transformed) xf to init and the first item in coll,',
247
- 'then applying xf to that result and the 2nd item, etc. If coll',
248
- 'contains no items, returns init and f is not called. Note that',
249
- 'certain transforms may inject or skip items.',
250
- ]),
251
- [
252
- ['xform', 'f', 'coll'],
253
- ['xform', 'f', 'init', 'coll'],
254
- ]
255
- ),
256
251
  }