@elaraai/east 1.0.12 → 1.0.14
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/src/walker.d.ts +36 -0
- package/dist/src/walker.d.ts.map +1 -1
- package/dist/src/walker.js +64 -0
- package/dist/src/walker.js.map +1 -1
- package/package.json +1 -1
package/dist/src/walker.d.ts
CHANGED
|
@@ -39,6 +39,42 @@ import type { IR, ValueIR } from "./ir.js";
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
export declare function literalValueOf(ir: ValueIR): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Reconstruct the JS value from a *constant* IR subtree — the inverse of the
|
|
44
|
+
* lowering `East.value(jsValue, type)` performs.
|
|
45
|
+
*
|
|
46
|
+
* `East.value` recursively lowers a JS literal into constant IR: an array
|
|
47
|
+
* becomes a `NewArray` of element nodes, a variant a `Variant` node, a struct
|
|
48
|
+
* a `Struct` node, a primitive a `Value` node, and so on. This walks that
|
|
49
|
+
* subtree back to the JS value, dispatching on the IR node tag — so
|
|
50
|
+
* static-analysis tooling can read a literal argument back out without
|
|
51
|
+
* hand-destructuring each envelope shape (the partial, brittle alternative).
|
|
52
|
+
*
|
|
53
|
+
* Dispatch is on the node tag, not an expected East type: the tag already
|
|
54
|
+
* records which constructor produced the node (`NewArray` vs `NewSet` vs
|
|
55
|
+
* `Struct`), so the reconstruction is unambiguous and needs no type argument.
|
|
56
|
+
*
|
|
57
|
+
* A node that is not a constant constructor — `Variable`, `Call`, `GetField`,
|
|
58
|
+
* `Platform`, an arithmetic `Builtin`, `IfElse`, … — means the value was
|
|
59
|
+
* computed at runtime rather than a literal, and throws. Use this where a
|
|
60
|
+
* value is required to be statically known (e.g. deriving the manifest of
|
|
61
|
+
* dataset paths a UI binds).
|
|
62
|
+
*
|
|
63
|
+
* Sets and dicts come back as plain `Set` / `Map` in the literal's element
|
|
64
|
+
* order; a `SortedSet` / `SortedMap` would need a comparator from the key
|
|
65
|
+
* type, which a tag-directed reader does not carry. Vectors and matrices are
|
|
66
|
+
* not reconstructed — faithfully rebuilding their typed-array storage needs
|
|
67
|
+
* the element type — and throw.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { East, StringType, ArrayType, constValueOf } from "@elaraai/east";
|
|
72
|
+
*
|
|
73
|
+
* const ir = East.value(["a", "b"], ArrayType(StringType)).toIR().ir;
|
|
74
|
+
* constValueOf(ir); // ["a", "b"]
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function constValueOf(ir: IR): unknown;
|
|
42
78
|
/** Context passed to {@link IRVisitor} on each node. */
|
|
43
79
|
export interface IRWalkContext {
|
|
44
80
|
/** The parent IR node, or `null` at the root. */
|
package/dist/src/walker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walker.d.ts","sourceRoot":"","sources":["../../src/walker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"walker.d.ts","sourceRoot":"","sources":["../../src/walker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAQ3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAEnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CA4B5C;AAED,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC1B,iDAAiD;IACjD,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC;CACrB;AAED,4DAA4D;AAC5D,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAErD"}
|
package/dist/src/walker.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
+
import { variant } from "./containers/variant.js";
|
|
6
|
+
import { ref } from "./containers/ref.js";
|
|
5
7
|
// ============================================================================
|
|
6
8
|
// Convenience helper
|
|
7
9
|
// ============================================================================
|
|
@@ -34,6 +36,68 @@
|
|
|
34
36
|
export function literalValueOf(ir) {
|
|
35
37
|
return ir.value.value.value;
|
|
36
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Reconstruct the JS value from a *constant* IR subtree — the inverse of the
|
|
41
|
+
* lowering `East.value(jsValue, type)` performs.
|
|
42
|
+
*
|
|
43
|
+
* `East.value` recursively lowers a JS literal into constant IR: an array
|
|
44
|
+
* becomes a `NewArray` of element nodes, a variant a `Variant` node, a struct
|
|
45
|
+
* a `Struct` node, a primitive a `Value` node, and so on. This walks that
|
|
46
|
+
* subtree back to the JS value, dispatching on the IR node tag — so
|
|
47
|
+
* static-analysis tooling can read a literal argument back out without
|
|
48
|
+
* hand-destructuring each envelope shape (the partial, brittle alternative).
|
|
49
|
+
*
|
|
50
|
+
* Dispatch is on the node tag, not an expected East type: the tag already
|
|
51
|
+
* records which constructor produced the node (`NewArray` vs `NewSet` vs
|
|
52
|
+
* `Struct`), so the reconstruction is unambiguous and needs no type argument.
|
|
53
|
+
*
|
|
54
|
+
* A node that is not a constant constructor — `Variable`, `Call`, `GetField`,
|
|
55
|
+
* `Platform`, an arithmetic `Builtin`, `IfElse`, … — means the value was
|
|
56
|
+
* computed at runtime rather than a literal, and throws. Use this where a
|
|
57
|
+
* value is required to be statically known (e.g. deriving the manifest of
|
|
58
|
+
* dataset paths a UI binds).
|
|
59
|
+
*
|
|
60
|
+
* Sets and dicts come back as plain `Set` / `Map` in the literal's element
|
|
61
|
+
* order; a `SortedSet` / `SortedMap` would need a comparator from the key
|
|
62
|
+
* type, which a tag-directed reader does not carry. Vectors and matrices are
|
|
63
|
+
* not reconstructed — faithfully rebuilding their typed-array storage needs
|
|
64
|
+
* the element type — and throw.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { East, StringType, ArrayType, constValueOf } from "@elaraai/east";
|
|
69
|
+
*
|
|
70
|
+
* const ir = East.value(["a", "b"], ArrayType(StringType)).toIR().ir;
|
|
71
|
+
* constValueOf(ir); // ["a", "b"]
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function constValueOf(ir) {
|
|
75
|
+
switch (ir.type) {
|
|
76
|
+
case "Value":
|
|
77
|
+
return literalValueOf(ir);
|
|
78
|
+
case "NewArray":
|
|
79
|
+
return ir.value.values.map(v => constValueOf(v));
|
|
80
|
+
case "NewSet":
|
|
81
|
+
return new Set(ir.value.values.map(v => constValueOf(v)));
|
|
82
|
+
case "NewDict":
|
|
83
|
+
return new Map(ir.value.values
|
|
84
|
+
.map(e => [constValueOf(e.key), constValueOf(e.value)]));
|
|
85
|
+
case "Struct":
|
|
86
|
+
return Object.fromEntries(ir.value.fields
|
|
87
|
+
.map(f => [f.name, constValueOf(f.value)]));
|
|
88
|
+
case "Variant":
|
|
89
|
+
return variant(ir.value.case, constValueOf(ir.value.value));
|
|
90
|
+
case "NewRef":
|
|
91
|
+
return ref(constValueOf(ir.value.value));
|
|
92
|
+
case "WrapRecursive":
|
|
93
|
+
return constValueOf(ir.value.value);
|
|
94
|
+
default:
|
|
95
|
+
throw new Error(`constValueOf: cannot read a constant value from a ${ir.type} node. ` +
|
|
96
|
+
`Only literals produced by East.value are supported ` +
|
|
97
|
+
`(Value / NewArray / NewSet / NewDict / Struct / Variant / NewRef); ` +
|
|
98
|
+
`pass a JS value, not a computed expression.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
37
101
|
/**
|
|
38
102
|
* Walk an East IR tree depth-first, invoking `visit` for every node.
|
|
39
103
|
*
|
package/dist/src/walker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walker.js","sourceRoot":"","sources":["../../src/walker.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"walker.js","sourceRoot":"","sources":["../../src/walker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,cAAc,CAAC,EAAW;IACtC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,YAAY,CAAC,EAAM;IAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;QACd,KAAK,OAAO;YACR,OAAO,cAAc,CAAC,EAAa,CAAC,CAAC;QACzC,KAAK,UAAU;YACX,OAAQ,EAAE,CAAC,KAAK,CAAC,MAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,KAAK,QAAQ;YACT,OAAO,IAAI,GAAG,CAAE,EAAE,CAAC,KAAK,CAAC,MAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,C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