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.
- package/dist-cli/conjure-js.mjs +9360 -5298
- package/dist-vite-plugin/index.mjs +9463 -5185
- package/package.json +3 -1
- package/src/bin/cli.ts +2 -2
- package/src/bin/nrepl-symbol.ts +150 -0
- package/src/bin/nrepl.ts +289 -167
- package/src/bin/version.ts +1 -1
- package/src/clojure/core.clj +757 -29
- package/src/clojure/core.clj.d.ts +75 -131
- package/src/clojure/generated/builtin-namespace-registry.ts +4 -0
- package/src/clojure/generated/clojure-core-source.ts +758 -29
- package/src/clojure/generated/clojure-set-source.ts +136 -0
- package/src/clojure/generated/clojure-walk-source.ts +72 -0
- package/src/clojure/set.clj +132 -0
- package/src/clojure/set.clj.d.ts +20 -0
- package/src/clojure/string.clj.d.ts +14 -0
- package/src/clojure/walk.clj +68 -0
- package/src/clojure/walk.clj.d.ts +7 -0
- package/src/core/assertions.ts +114 -6
- package/src/core/bootstrap.ts +337 -0
- package/src/core/conversions.ts +48 -31
- package/src/core/core-module.ts +303 -0
- package/src/core/env.ts +20 -6
- package/src/core/evaluator/apply.ts +40 -25
- package/src/core/evaluator/arity.ts +8 -8
- package/src/core/evaluator/async-evaluator.ts +565 -0
- package/src/core/evaluator/collections.ts +28 -5
- package/src/core/evaluator/destructure.ts +180 -69
- package/src/core/evaluator/dispatch.ts +12 -14
- package/src/core/evaluator/evaluate.ts +22 -20
- package/src/core/evaluator/expand.ts +45 -15
- package/src/core/evaluator/form-parsers.ts +178 -0
- package/src/core/evaluator/index.ts +7 -9
- package/src/core/evaluator/js-interop.ts +189 -0
- package/src/core/evaluator/quasiquote.ts +14 -8
- package/src/core/evaluator/recur-check.ts +6 -6
- package/src/core/evaluator/special-forms.ts +234 -191
- package/src/core/factories.ts +182 -3
- package/src/core/index.ts +54 -4
- package/src/core/module.ts +136 -0
- package/src/core/ns-forms.ts +107 -0
- package/src/core/printer.ts +371 -11
- package/src/core/reader.ts +84 -33
- package/src/core/registry.ts +209 -0
- package/src/core/runtime.ts +376 -0
- package/src/core/session.ts +253 -487
- package/src/core/stdlib/arithmetic.ts +528 -194
- package/src/core/stdlib/async-fns.ts +132 -0
- package/src/core/stdlib/atoms.ts +291 -56
- package/src/core/stdlib/errors.ts +54 -50
- package/src/core/stdlib/hof.ts +82 -166
- package/src/core/stdlib/js-namespace.ts +344 -0
- package/src/core/stdlib/lazy.ts +34 -0
- package/src/core/stdlib/maps-sets.ts +322 -0
- package/src/core/stdlib/meta.ts +61 -30
- package/src/core/stdlib/predicates.ts +325 -187
- package/src/core/stdlib/regex.ts +126 -98
- package/src/core/stdlib/seq.ts +564 -0
- package/src/core/stdlib/strings.ts +164 -135
- package/src/core/stdlib/transducers.ts +95 -100
- package/src/core/stdlib/utils.ts +292 -130
- package/src/core/stdlib/vars.ts +27 -27
- package/src/core/stdlib/vectors.ts +122 -0
- package/src/core/tokenizer.ts +2 -2
- package/src/core/transformations.ts +117 -9
- package/src/core/types.ts +98 -2
- package/src/host/node-host-module.ts +74 -0
- package/src/{vite-plugin-clj/nrepl-relay.ts → nrepl/relay.ts} +72 -11
- package/src/vite-plugin-clj/codegen.ts +87 -95
- package/src/vite-plugin-clj/index.ts +178 -23
- package/src/vite-plugin-clj/namespace-utils.ts +39 -0
- package/src/vite-plugin-clj/static-analysis.ts +211 -0
- package/src/clojure/demo.clj +0 -72
- package/src/clojure/demo.clj.d.ts +0 -0
- package/src/core/core-env.ts +0 -61
- package/src/core/stdlib/collections.ts +0 -739
- 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 {
|
|
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(
|
|
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
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
...groups.map(
|
|
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
|
|
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
|
|
114
|
+
return v.string(s.replace(jsRe, replVal.value))
|
|
118
115
|
}
|
|
119
116
|
|
|
120
117
|
// regex / function
|
|
121
|
-
if (
|
|
118
|
+
if (is.aFunction(replVal)) {
|
|
122
119
|
const fn = replVal as CljFunction | CljNativeFunction
|
|
123
|
-
const result = s.replace(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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*':
|
|
149
|
-
|
|
150
|
-
return
|
|
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*':
|
|
157
|
-
|
|
158
|
-
return
|
|
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*':
|
|
165
|
-
|
|
166
|
-
return
|
|
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*':
|
|
173
|
-
|
|
174
|
-
return
|
|
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*':
|
|
181
|
-
|
|
182
|
-
return
|
|
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*':
|
|
189
|
-
|
|
190
|
-
return
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
|
|
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*':
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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*':
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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*':
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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*':
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
|
239
|
-
} else {
|
|
240
|
-
idx = s.indexOf(needle)
|
|
248
|
+
return idx === -1 ? v.nil() : v.number(idx)
|
|
241
249
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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*':
|
|
249
|
-
|
|
256
|
+
'str-last-index-of*': v
|
|
257
|
+
.nativeFn(
|
|
250
258
|
'str-last-index-of*',
|
|
251
|
-
(
|
|
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 ?
|
|
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*':
|
|
274
|
-
|
|
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
|
-
)
|
|
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*':
|
|
289
|
-
|
|
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
|
}
|