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,17 +1,8 @@
1
1
  // Native string helpers used by clojure.string.
2
2
  // All public API lives in src/clojure/string.clj; these are private helpers.
3
- import { isAFunction } from '../assertions'
3
+ import { is } from '../assertions'
4
4
  import { EvaluationError } from '../errors'
5
- import {
6
- cljBoolean,
7
- cljNativeFunction,
8
- cljNativeFunctionWithContext,
9
- cljNil,
10
- cljNumber,
11
- cljString,
12
- cljVector,
13
- withDoc,
14
- } from '../factories'
5
+ import { v } from '../factories'
15
6
  import { printString } from '../printer'
16
7
  import { valueToString } from '../transformations'
17
8
  import type {
@@ -37,7 +28,11 @@ function assertStr(val: CljValue | undefined, fnName: string): string {
37
28
  return val.value
38
29
  }
39
30
 
40
- function assertStrArg(val: CljValue | undefined, pos: string, fnName: string): string {
31
+ function assertStrArg(
32
+ val: CljValue | undefined,
33
+ pos: string,
34
+ fnName: string
35
+ ): string {
41
36
  if (val === undefined || val.kind !== 'string') {
42
37
  throw new EvaluationError(
43
38
  `${fnName} expects a string as ${pos} argument${val !== undefined ? `, got ${printString(val)}` : ''}`,
@@ -70,10 +65,12 @@ function buildMatchValue(whole: string, args: unknown[]): CljValue {
70
65
  }
71
66
  }
72
67
  const groups = offsetIdx > 0 ? args.slice(0, offsetIdx) : []
73
- if (groups.length === 0) return cljString(whole)
74
- return cljVector([
75
- cljString(whole),
76
- ...groups.map((g) => (g == null ? cljNil() : cljString(String(g)))),
68
+ if (groups.length === 0) return v.string(whole)
69
+ return v.vector([
70
+ v.string(whole),
71
+ ...groups.map(function mapGroupToClj(g) {
72
+ return g == null ? v.nil() : v.string(String(g))
73
+ }),
77
74
  ])
78
75
  }
79
76
 
@@ -103,7 +100,7 @@ function doReplace(
103
100
  )
104
101
  }
105
102
  const re = new RegExp(escapeRegex(matchVal.value), global ? 'g' : '')
106
- return cljString(s.replace(re, escapeDollarInReplacement(replVal.value)))
103
+ return v.string(s.replace(re, escapeDollarInReplacement(replVal.value)))
107
104
  }
108
105
 
109
106
  // --- regex / * ---
@@ -114,18 +111,21 @@ function doReplace(
114
111
 
115
112
  // regex / string
116
113
  if (replVal.kind === 'string') {
117
- return cljString(s.replace(jsRe, replVal.value))
114
+ return v.string(s.replace(jsRe, replVal.value))
118
115
  }
119
116
 
120
117
  // regex / function
121
- if (isAFunction(replVal)) {
118
+ if (is.aFunction(replVal)) {
122
119
  const fn = replVal as CljFunction | CljNativeFunction
123
- const result = s.replace(jsRe, (whole: string, ...args: unknown[]) => {
124
- const matchClj = buildMatchValue(whole, args)
125
- const replResult = ctx.applyFunction(fn, [matchClj], callEnv)
126
- return valueToString(replResult)
127
- })
128
- return cljString(result)
120
+ const result = s.replace(
121
+ jsRe,
122
+ function replaceCallback(whole: string, ...args: unknown[]) {
123
+ const matchClj = buildMatchValue(whole, args)
124
+ const replResult = ctx.applyFunction(fn, [matchClj], callEnv)
125
+ return valueToString(replResult)
126
+ }
127
+ )
128
+ return v.string(result)
129
129
  }
130
130
 
131
131
  throw new EvaluationError(
@@ -145,110 +145,122 @@ function doReplace(
145
145
  // ---------------------------------------------------------------------------
146
146
 
147
147
  export const stringFunctions: Record<string, CljValue> = {
148
- 'str-upper-case*': withDoc(
149
- cljNativeFunction('str-upper-case*', (sVal: CljValue) => {
150
- return cljString(assertStr(sVal, 'str-upper-case*').toUpperCase())
151
- }),
152
- 'Internal helper. Converts s to upper-case.',
153
- [['s']]
154
- ),
148
+ 'str-upper-case*': v
149
+ .nativeFn('str-upper-case*', function strUpperCaseImpl(sVal: CljValue) {
150
+ return v.string(assertStr(sVal, 'str-upper-case*').toUpperCase())
151
+ })
152
+ .doc('Internal helper. Converts s to upper-case.', [['s']]),
155
153
 
156
- 'str-lower-case*': withDoc(
157
- cljNativeFunction('str-lower-case*', (sVal: CljValue) => {
158
- return cljString(assertStr(sVal, 'str-lower-case*').toLowerCase())
159
- }),
160
- 'Internal helper. Converts s to lower-case.',
161
- [['s']]
162
- ),
154
+ 'str-lower-case*': v
155
+ .nativeFn('str-lower-case*', function strLowerCaseImpl(sVal: CljValue) {
156
+ return v.string(assertStr(sVal, 'str-lower-case*').toLowerCase())
157
+ })
158
+ .doc('Internal helper. Converts s to lower-case.', [['s']]),
163
159
 
164
- 'str-trim*': withDoc(
165
- cljNativeFunction('str-trim*', (sVal: CljValue) => {
166
- return cljString(assertStr(sVal, 'str-trim*').trim())
167
- }),
168
- 'Internal helper. Removes whitespace from both ends of s.',
169
- [['s']]
170
- ),
160
+ 'str-trim*': v
161
+ .nativeFn('str-trim*', function strTrimImpl(sVal: CljValue) {
162
+ return v.string(assertStr(sVal, 'str-trim*').trim())
163
+ })
164
+ .doc('Internal helper. Removes whitespace from both ends of s.', [['s']]),
171
165
 
172
- 'str-triml*': withDoc(
173
- cljNativeFunction('str-triml*', (sVal: CljValue) => {
174
- return cljString(assertStr(sVal, 'str-triml*').trimStart())
175
- }),
176
- 'Internal helper. Removes whitespace from the left of s.',
177
- [['s']]
178
- ),
166
+ 'str-triml*': v
167
+ .nativeFn('str-triml*', function strTrimlImpl(sVal: CljValue) {
168
+ return v.string(assertStr(sVal, 'str-triml*').trimStart())
169
+ })
170
+ .doc('Internal helper. Removes whitespace from the left of s.', [['s']]),
179
171
 
180
- 'str-trimr*': withDoc(
181
- cljNativeFunction('str-trimr*', (sVal: CljValue) => {
182
- return cljString(assertStr(sVal, 'str-trimr*').trimEnd())
183
- }),
184
- 'Internal helper. Removes whitespace from the right of s.',
185
- [['s']]
186
- ),
172
+ 'str-trimr*': v
173
+ .nativeFn('str-trimr*', function strTrimrImpl(sVal: CljValue) {
174
+ return v.string(assertStr(sVal, 'str-trimr*').trimEnd())
175
+ })
176
+ .doc('Internal helper. Removes whitespace from the right of s.', [['s']]),
187
177
 
188
- 'str-reverse*': withDoc(
189
- cljNativeFunction('str-reverse*', (sVal: CljValue) => {
190
- return cljString([...assertStr(sVal, 'str-reverse*')].reverse().join(''))
191
- }),
192
- 'Internal helper. Returns s with its characters reversed (Unicode-safe).',
193
- [['s']]
194
- ),
178
+ 'str-reverse*': v
179
+ .nativeFn('str-reverse*', function strReverseImpl(sVal: CljValue) {
180
+ return v.string([...assertStr(sVal, 'str-reverse*')].reverse().join(''))
181
+ })
182
+ .doc(
183
+ 'Internal helper. Returns s with its characters reversed (Unicode-safe).',
184
+ [['s']]
185
+ ),
195
186
 
196
- 'str-starts-with*': withDoc(
197
- cljNativeFunction('str-starts-with*', (sVal: CljValue, substrVal: CljValue) => {
198
- const s = assertStr(sVal, 'str-starts-with*')
199
- const substr = assertStrArg(substrVal, 'second', 'str-starts-with*')
200
- return cljBoolean(s.startsWith(substr))
201
- }),
202
- 'Internal helper. Returns true if s starts with substr.',
203
- [['s', 'substr']]
204
- ),
187
+ 'str-starts-with*': v
188
+ .nativeFn(
189
+ 'str-starts-with*',
190
+ function strStartsWithImpl(sVal: CljValue, substrVal: CljValue) {
191
+ const s = assertStr(sVal, 'str-starts-with*')
192
+ const substr = assertStrArg(substrVal, 'second', 'str-starts-with*')
193
+ return v.boolean(s.startsWith(substr))
194
+ }
195
+ )
196
+ .doc('Internal helper. Returns true if s starts with substr.', [
197
+ ['s', 'substr'],
198
+ ]),
205
199
 
206
- 'str-ends-with*': withDoc(
207
- cljNativeFunction('str-ends-with*', (sVal: CljValue, substrVal: CljValue) => {
208
- const s = assertStr(sVal, 'str-ends-with*')
209
- const substr = assertStrArg(substrVal, 'second', 'str-ends-with*')
210
- return cljBoolean(s.endsWith(substr))
211
- }),
212
- 'Internal helper. Returns true if s ends with substr.',
213
- [['s', 'substr']]
214
- ),
200
+ 'str-ends-with*': v
201
+ .nativeFn(
202
+ 'str-ends-with*',
203
+ function strEndsWithImpl(sVal: CljValue, substrVal: CljValue) {
204
+ const s = assertStr(sVal, 'str-ends-with*')
205
+ const substr = assertStrArg(substrVal, 'second', 'str-ends-with*')
206
+ return v.boolean(s.endsWith(substr))
207
+ }
208
+ )
209
+ .doc('Internal helper. Returns true if s ends with substr.', [
210
+ ['s', 'substr'],
211
+ ]),
215
212
 
216
- 'str-includes*': withDoc(
217
- cljNativeFunction('str-includes*', (sVal: CljValue, substrVal: CljValue) => {
218
- const s = assertStr(sVal, 'str-includes*')
219
- const substr = assertStrArg(substrVal, 'second', 'str-includes*')
220
- return cljBoolean(s.includes(substr))
221
- }),
222
- 'Internal helper. Returns true if s contains substr.',
223
- [['s', 'substr']]
224
- ),
213
+ 'str-includes*': v
214
+ .nativeFn(
215
+ 'str-includes*',
216
+ function strIncludesImpl(sVal: CljValue, substrVal: CljValue) {
217
+ const s = assertStr(sVal, 'str-includes*')
218
+ const substr = assertStrArg(substrVal, 'second', 'str-includes*')
219
+ return v.boolean(s.includes(substr))
220
+ }
221
+ )
222
+ .doc('Internal helper. Returns true if s contains substr.', [
223
+ ['s', 'substr'],
224
+ ]),
225
225
 
226
- 'str-index-of*': withDoc(
227
- cljNativeFunction('str-index-of*', (sVal: CljValue, valVal: CljValue, fromVal?: CljValue) => {
228
- const s = assertStr(sVal, 'str-index-of*')
229
- const needle = assertStrArg(valVal, 'second', 'str-index-of*')
230
- let idx: number
231
- if (fromVal !== undefined && fromVal.kind !== 'nil') {
232
- if (fromVal.kind !== 'number') {
233
- throw new EvaluationError(
234
- `str-index-of* expects a number as third argument, got ${printString(fromVal)}`,
235
- { fromVal }
236
- )
226
+ 'str-index-of*': v
227
+ .nativeFn(
228
+ 'str-index-of*',
229
+ function strIndexOfImpl(
230
+ sVal: CljValue,
231
+ valVal: CljValue,
232
+ fromVal?: CljValue
233
+ ) {
234
+ const s = assertStr(sVal, 'str-index-of*')
235
+ const needle = assertStrArg(valVal, 'second', 'str-index-of*')
236
+ let idx: number
237
+ if (fromVal !== undefined && fromVal.kind !== 'nil') {
238
+ if (fromVal.kind !== 'number') {
239
+ throw new EvaluationError(
240
+ `str-index-of* expects a number as third argument, got ${printString(fromVal)}`,
241
+ { fromVal }
242
+ )
243
+ }
244
+ idx = s.indexOf(needle, fromVal.value)
245
+ } else {
246
+ idx = s.indexOf(needle)
237
247
  }
238
- idx = s.indexOf(needle, fromVal.value)
239
- } else {
240
- idx = s.indexOf(needle)
248
+ return idx === -1 ? v.nil() : v.number(idx)
241
249
  }
242
- return idx === -1 ? cljNil() : cljNumber(idx)
243
- }),
244
- 'Internal helper. Returns index of value in s, or nil if not found.',
245
- [['s', 'value'], ['s', 'value', 'from-index']]
246
- ),
250
+ )
251
+ .doc('Internal helper. Returns index of value in s, or nil if not found.', [
252
+ ['s', 'value'],
253
+ ['s', 'value', 'from-index'],
254
+ ]),
247
255
 
248
- 'str-last-index-of*': withDoc(
249
- cljNativeFunction(
256
+ 'str-last-index-of*': v
257
+ .nativeFn(
250
258
  'str-last-index-of*',
251
- (sVal: CljValue, valVal: CljValue, fromVal?: CljValue) => {
259
+ function strLastIndexOfImpl(
260
+ sVal: CljValue,
261
+ valVal: CljValue,
262
+ fromVal?: CljValue
263
+ ) {
252
264
  const s = assertStr(sVal, 'str-last-index-of*')
253
265
  const needle = assertStrArg(valVal, 'second', 'str-last-index-of*')
254
266
  let idx: number
@@ -263,39 +275,54 @@ export const stringFunctions: Record<string, CljValue> = {
263
275
  } else {
264
276
  idx = s.lastIndexOf(needle)
265
277
  }
266
- return idx === -1 ? cljNil() : cljNumber(idx)
278
+ return idx === -1 ? v.nil() : v.number(idx)
267
279
  }
280
+ )
281
+ .doc(
282
+ 'Internal helper. Returns last index of value in s, or nil if not found.',
283
+ [
284
+ ['s', 'value'],
285
+ ['s', 'value', 'from-index'],
286
+ ]
268
287
  ),
269
- 'Internal helper. Returns last index of value in s, or nil if not found.',
270
- [['s', 'value'], ['s', 'value', 'from-index']]
271
- ),
272
288
 
273
- 'str-replace*': withDoc(
274
- cljNativeFunctionWithContext(
289
+ 'str-replace*': v
290
+ .nativeFnCtx(
275
291
  'str-replace*',
276
- (
292
+ function strReplaceImpl(
277
293
  ctx: EvaluationContext,
278
294
  callEnv: Env,
279
295
  sVal: CljValue,
280
296
  matchVal: CljValue,
281
297
  replVal: CljValue
282
- ) => doReplace(ctx, callEnv, 'str-replace*', sVal, matchVal, replVal, true)
298
+ ) {
299
+ return doReplace(
300
+ ctx,
301
+ callEnv,
302
+ 'str-replace*',
303
+ sVal,
304
+ matchVal,
305
+ replVal,
306
+ true
307
+ )
308
+ }
309
+ )
310
+ .doc(
311
+ 'Internal helper. Replaces all occurrences of match with replacement in s.',
312
+ [['s', 'match', 'replacement']]
283
313
  ),
284
- 'Internal helper. Replaces all occurrences of match with replacement in s.',
285
- [['s', 'match', 'replacement']]
286
- ),
287
314
 
288
- 'str-replace-first*': withDoc(
289
- cljNativeFunctionWithContext(
315
+ 'str-replace-first*': v
316
+ .nativeFnCtx(
290
317
  'str-replace-first*',
291
- (
318
+ function strReplaceFirstImpl(
292
319
  ctx: EvaluationContext,
293
320
  callEnv: Env,
294
321
  sVal: CljValue,
295
322
  matchVal: CljValue,
296
323
  replVal: CljValue
297
- ) =>
298
- doReplace(
324
+ ) {
325
+ return doReplace(
299
326
  ctx,
300
327
  callEnv,
301
328
  'str-replace-first*',
@@ -304,8 +331,10 @@ export const stringFunctions: Record<string, CljValue> = {
304
331
  replVal,
305
332
  false
306
333
  )
334
+ }
335
+ )
336
+ .doc(
337
+ 'Internal helper. Replaces the first occurrence of match with replacement in s.',
338
+ [['s', 'match', 'replacement']]
307
339
  ),
308
- 'Internal helper. Replaces the first occurrence of match with replacement in s.',
309
- [['s', 'match', 'replacement']]
310
- ),
311
340
  }