lemmascript 0.2.0 → 0.3.1

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.
@@ -25,7 +25,14 @@ export function parseTsType(tsType) {
25
25
  const t = tsType.trim();
26
26
  // Union: T | undefined → optional<T>
27
27
  if (t.includes(" | ")) {
28
- const arms = t.split(" | ").map(a => a.trim());
28
+ let arms = t.split(" | ").map(a => a.trim());
29
+ // Normalize expanded boolean literals: true | false → boolean
30
+ const boolLits = new Set(["true", "false"]);
31
+ const hasBoth = arms.includes("true") && arms.includes("false");
32
+ if (hasBoth) {
33
+ arms = arms.filter(a => !boolLits.has(a));
34
+ arms.unshift("boolean");
35
+ }
29
36
  const nonUndef = arms.filter(a => a !== "undefined");
30
37
  if (nonUndef.length === 1 && arms.length === 2) {
31
38
  return { kind: "optional", inner: parseTsType(nonUndef[0]) };
@@ -67,5 +74,11 @@ export function parseTsType(tsType) {
67
74
  const setMatch = t.match(/^Set<(.+)>$/);
68
75
  if (setMatch)
69
76
  return { kind: "set", elem: parseTsType(setMatch[1]) };
77
+ // Tuple [T1, T2, ...] → array of the common element type
78
+ const tupleMatch = t.match(/^\[(.+)\]$/);
79
+ if (tupleMatch) {
80
+ const elems = splitTypeArgs(tupleMatch[1]);
81
+ return { kind: "array", elem: parseTsType(elems[0]) };
82
+ }
70
83
  return { kind: "user", name: t };
71
84
  }