@mark1russell7/vex-compiler 0.17.0 → 0.17.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/vex-compiler",
4
- "version": "0.17.0",
4
+ "version": "0.17.2",
5
5
  "description": "The Vex compiler: generated JavaScript for Vex programs, at run time and at build time, with the results of the interpreter.",
6
6
  "keywords": [
7
7
  "vex",
@@ -43,15 +43,15 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@mark1russell7/cue": "github:mark1russell7/cue",
46
- "@mark1russell7/vex-domains": "0.17.0",
47
- "@mark1russell7/vex-testkit": "0.17.0",
46
+ "@mark1russell7/vex-domains": "0.17.2",
47
+ "@mark1russell7/vex-testkit": "0.17.2",
48
48
  "@types/node": "^26.6.4",
49
49
  "fast-check": "^4.10.2",
50
50
  "typescript": "^7.0.2",
51
51
  "vitest": "^5.0.3"
52
52
  },
53
53
  "dependencies": {
54
- "@mark1russell7/vex": "0.17.0"
54
+ "@mark1russell7/vex": "0.17.2"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsdown",
package/src/module.ts CHANGED
@@ -299,13 +299,15 @@ const HELPERS: Readonly<Record<Exclude<Helper, "S">, string>> = {
299
299
  K: 'function K(k, n) { return typeof k === "string" && /^(0|[1-9]\\d*)$/.test(k) && +k < n ? +k : F(); }',
300
300
  // The ops on the order of a list (LIST.SORT, LIST.TAKE, LIST.NTH) work on the items with values. With strict, an
301
301
  // error item is the error of the op. A sort is stable, and the values are numbers without NaN or texts of one kind.
302
- V: "function V(l, s) { if (s && l.some((x) => x[1] === E)) F(); return l.filter((x) => x[1] !== E); }",
302
+ // V gives a list without error items itself, so it is not copied (COMPILE.MODULE.LIST.SHARE). No op changes it. V does
303
+ // not keep the cache of VW: a property on each new list made the list ops slower (ireko, vex-compiler 0.17.1).
304
+ V: "function V(l, s) { if (!l.some((x) => x[1] === E)) return l; if (s) F(); return l.filter((x) => x[1] !== E); }",
303
305
  SB: [
304
306
  "function SB(l, s) {",
305
307
  " const o = V(l, s);",
306
308
  " const t = o.length > 0 ? typeof o[0][1] : \"number\";",
307
309
  " for (const [, v] of o) if (typeof v !== t || (t !== \"number\" && t !== \"string\") || v !== v) F();",
308
- " return o.sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));",
310
+ " return o.slice().sort((a, b) => (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));",
309
311
  "}",
310
312
  ].join("\n"),
311
313
  // The option by of sortBy (LIST.SORT.BY): the function f gives the sort value of each item with a value, in order.
@@ -320,11 +322,12 @@ const HELPERS: Readonly<Record<Exclude<Helper, "S">, string>> = {
320
322
  TK: "function TK(l, n, s) { const o = V(l, s); return Number.isSafeInteger(n) && n >= 0 ? o.slice(0, n) : F(); }",
321
323
  // The items with values of a list stay on its array, as GT keeps its index. Thus a loop that reads each item of a list
322
324
  // of n items with nth costs O(n), not O(n squared). count and first read them too (COMPILE.MODULE.NTH.INDEX).
325
+ // A list without error items is its own array of items with values.
323
326
  VW: [
324
327
  "function VW(l) {",
325
328
  " let o = l.vw;",
326
329
  " if (o === undefined) {",
327
- " o = l.filter((x) => x[1] !== E);",
330
+ " o = l.some((x) => x[1] === E) ? l.filter((x) => x[1] !== E) : l;",
328
331
  " l.vw = o;",
329
332
  " }",
330
333
  " return o;",
@@ -380,9 +383,10 @@ const HELPERS: Readonly<Record<Exclude<Helper, "S">, string>> = {
380
383
  DR: "function DR(l, n, s) { const o = V(l, s); return Number.isSafeInteger(n) && n >= 0 ? o.slice(n) : F(); }",
381
384
  AP: "function AP(l, o, s) { return V(l, s).concat(V(o, s)); }",
382
385
  // append into the list of a name of a loop (COMPILE.MODULE.APPEND.OWN). w is the array of the last append of the name
383
- // in this run of the loop, and no other part reads it. Such an array has no error items, so V(l, s) is a copy of l.
384
- // Each other list gets the copy of AP. V(o, s) throws before the first push, so an error does not change l.
385
- AO: "function AO(l, o, s, w) { if (l !== w) return AP(l, o, s); for (const x of V(o, s)) l.push(x); return l; }",
386
+ // in this run of the loop, and no other part reads it. Such an array has no error items, so VW of it is the array.
387
+ // Each other list gets the copy of AP. V(o, s) throws before the first push, so an error does not change l. The loop
388
+ // reads n items, so it ends also if a is l.
389
+ AO: "function AO(l, o, s, w) { if (l !== w) return AP(l, o, s); const a = V(o, s), n = a.length; for (let i = 0; i < n; i++) l.push(a[i]); return l; }",
386
390
  WO: [
387
391
  "function WO(l, o, s) {",
388
392
  " const a = V(l, s), g = new Map();",