@calcit/procs 0.5.32 → 0.5.35

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.
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.5.32";
3
+ export const calcit_version = "0.5.35";
4
4
  import "@calcit/ternary-tree";
5
5
  import { parse } from "@cirru/parser.ts";
6
6
  import { writeCirruCode } from "@cirru/writer.ts";
package/lib/js-cirru.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "@calcit/ternary-tree";
2
2
  import { writeCirruCode } from "@cirru/writer.ts";
3
- import { _$n_compare } from "./js-primes.mjs";
3
+ import { is_literal, _$n_compare } from "./js-primes.mjs";
4
4
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
5
5
  import { CalcitRecord } from "./js-record.mjs";
6
6
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
@@ -50,7 +50,30 @@ export let to_cirru_edn = (x) => {
50
50
  pairs.push(pair);
51
51
  }
52
52
  pairs.sort((a, b) => {
53
- return _$n_compare(a[0], b[0]);
53
+ let a0_literal = is_literal(a[0]);
54
+ let a1_literal = is_literal(a[1]);
55
+ let b0_literal = is_literal(b[0]);
56
+ let b1_literal = is_literal(b[1]);
57
+ if (a0_literal && b0_literal) {
58
+ if (a1_literal && !b1_literal) {
59
+ return -1;
60
+ }
61
+ else if (!a1_literal && b1_literal) {
62
+ return 1;
63
+ }
64
+ else {
65
+ return _$n_compare(a[0], b[0]);
66
+ }
67
+ }
68
+ else if (a0_literal && !b0_literal) {
69
+ return -1;
70
+ }
71
+ else if (!a0_literal && b0_literal) {
72
+ return 1;
73
+ }
74
+ else {
75
+ return _$n_compare(a[0], b[0]);
76
+ }
54
77
  });
55
78
  for (let [k, v] of pairs) {
56
79
  buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
package/lib/js-primes.mjs CHANGED
@@ -4,6 +4,21 @@ import { CalcitRecord } from "./js-record.mjs";
4
4
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
5
5
  import { CalcitSet as CalcitSet } from "./js-set.mjs";
6
6
  import { CalcitTuple } from "./js-tuple.mjs";
7
+ export let is_literal = (x) => {
8
+ if (x == null)
9
+ return true;
10
+ if (typeof x == "string")
11
+ return true;
12
+ if (typeof x == "boolean")
13
+ return true;
14
+ if (typeof x == "number")
15
+ return true;
16
+ if (x instanceof CalcitKeyword)
17
+ return true;
18
+ if (x instanceof CalcitSymbol)
19
+ return true;
20
+ return false;
21
+ };
7
22
  var PseudoTypeIndex;
8
23
  (function (PseudoTypeIndex) {
9
24
  PseudoTypeIndex[PseudoTypeIndex["nil"] = 0] = "nil";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.5.32",
3
+ "version": "0.5.35",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^17.0.23",
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.5.32";
2
+ export const calcit_version = "0.5.35";
3
3
 
4
4
  import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
5
5
  import { parse, ICirruNode } from "@cirru/parser.ts";
@@ -1,7 +1,7 @@
1
1
  import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
2
2
  import { CirruWriterNode, writeCirruCode } from "@cirru/writer.ts";
3
3
 
4
- import { CalcitValue, _$n_compare } from "./js-primes.mjs";
4
+ import { CalcitValue, is_literal, _$n_compare } from "./js-primes.mjs";
5
5
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
6
6
  import { CalcitRecord } from "./js-record.mjs";
7
7
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
@@ -55,7 +55,25 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
55
55
  pairs.push(pair);
56
56
  }
57
57
  pairs.sort((a, b) => {
58
- return _$n_compare(a[0], b[0]);
58
+ let a0_literal = is_literal(a[0]);
59
+ let a1_literal = is_literal(a[1]);
60
+ let b0_literal = is_literal(b[0]);
61
+ let b1_literal = is_literal(b[1]);
62
+ if (a0_literal && b0_literal) {
63
+ if (a1_literal && !b1_literal) {
64
+ return -1;
65
+ } else if (!a1_literal && b1_literal) {
66
+ return 1;
67
+ } else {
68
+ return _$n_compare(a[0], b[0]);
69
+ }
70
+ } else if (a0_literal && !b0_literal) {
71
+ return -1;
72
+ } else if (!a0_literal && b0_literal) {
73
+ return 1;
74
+ } else {
75
+ return _$n_compare(a[0], b[0]);
76
+ }
59
77
  });
60
78
  for (let [k, v] of pairs) {
61
79
  buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
@@ -23,6 +23,16 @@ export type CalcitValue =
23
23
  | CalcitRecord
24
24
  | null;
25
25
 
26
+ export let is_literal = (x: CalcitValue): boolean => {
27
+ if (x == null) return true;
28
+ if (typeof x == "string") return true;
29
+ if (typeof x == "boolean") return true;
30
+ if (typeof x == "number") return true;
31
+ if (x instanceof CalcitKeyword) return true;
32
+ if (x instanceof CalcitSymbol) return true;
33
+ return false;
34
+ };
35
+
26
36
  enum PseudoTypeIndex {
27
37
  nil,
28
38
  bool,