@telorun/templating 0.107.0 → 0.108.0
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/builtins.d.ts +2 -2
- package/dist/builtins.d.ts.map +1 -1
- package/dist/cel/analyze.d.ts +6 -6
- package/dist/cel/analyze.d.ts.map +1 -1
- package/dist/cel/analyze.js +138 -183
- package/dist/cel/compile.d.ts +47 -17
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +135 -83
- package/dist/cel/diagnose.d.ts +52 -57
- package/dist/cel/diagnose.d.ts.map +1 -1
- package/dist/cel/diagnose.js +69 -291
- package/dist/cel/environment.d.ts +33 -37
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +54 -86
- package/dist/cel/module-call.d.ts +68 -79
- package/dist/cel/module-call.d.ts.map +1 -1
- package/dist/cel/module-call.js +118 -194
- package/dist/cel/value-brands.d.ts +14 -12
- package/dist/cel/value-brands.d.ts.map +1 -1
- package/dist/cel/value-brands.js +26 -24
- package/dist/cel/verdict-codes.d.ts +13 -2
- package/dist/cel/verdict-codes.d.ts.map +1 -1
- package/dist/cel/verdict-codes.js +20 -1
- package/dist/engine.d.ts +4 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/cel.d.ts +2 -2
- package/dist/engines/cel.d.ts.map +1 -1
- package/dist/engines/cel.js +53 -81
- package/dist/engines/hole-analysis.d.ts +3 -3
- package/dist/engines/hole-analysis.d.ts.map +1 -1
- package/dist/engines/interpolate.js +11 -8
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/package.json +4 -4
- package/src/builtins.ts +2 -2
- package/src/cel/analyze.ts +152 -193
- package/src/cel/compile.ts +160 -77
- package/src/cel/diagnose.ts +115 -370
- package/src/cel/environment.ts +64 -87
- package/src/cel/module-call.ts +129 -292
- package/src/cel/value-brands.ts +26 -25
- package/src/cel/verdict-codes.ts +20 -1
- package/src/engine.ts +4 -4
- package/src/engines/cel.ts +52 -84
- package/src/engines/hole-analysis.ts +3 -3
- package/src/engines/interpolate.ts +16 -13
- package/src/index.ts +8 -11
- package/dist/cel/catalog.d.ts +0 -70
- package/dist/cel/catalog.d.ts.map +0 -1
- package/dist/cel/catalog.js +0 -1320
- package/dist/cel/json-prefix-scan.d.ts +0 -17
- package/dist/cel/json-prefix-scan.d.ts.map +0 -1
- package/dist/cel/json-prefix-scan.js +0 -160
- package/dist/cel/value-identity.d.ts +0 -18
- package/dist/cel/value-identity.d.ts.map +0 -1
- package/dist/cel/value-identity.js +0 -25
- package/src/cel/catalog.ts +0 -1455
- package/src/cel/json-prefix-scan.ts +0 -152
- package/src/cel/value-identity.ts +0 -34
|
@@ -1,108 +1,97 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Module calls: what a resolved one says, where the dispatch table hangs, and the two walks
|
|
3
|
+
* the analyzer asks of an expression's own names.
|
|
3
4
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* **The rewrite is gone.** `Alias.fn(x)` and `obj.method(x)` are the same syntax and only a
|
|
6
|
+
* set of names distinguishes them, so this package used to rewrite the parsed tree itself,
|
|
7
|
+
* through internals the previous engine did not expose: a `setMeta('macro', …)` redirect
|
|
8
|
+
* that made a qualified call check and evaluate as something else, with a comprehension
|
|
9
|
+
* macro's `alternate` winning over `macro` unless cleared, and an rcall's asyncness derived
|
|
10
|
+
* from state the replaced checker filled in. Three facts about a dependency's internals,
|
|
11
|
+
* each pinned by a test, and the reason it was pinned to an exact version.
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* `@telorun/cel` has **`qcall` as a node of its own**, produced by a total tree-to-tree pass
|
|
14
|
+
* over the name set — never by the parser, because the set is the host's — and a
|
|
15
|
+
* `CelExpression` records the set it was resolved under, so an environment refuses a tree
|
|
16
|
+
* resolved for a different site instead of answering a different question about it. So
|
|
17
|
+
* reading a module call is reading a node kind, and there is nothing to rewrite and nothing
|
|
18
|
+
* to pin.
|
|
16
19
|
*
|
|
17
|
-
*
|
|
18
|
-
* the
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* - `ASTNode.setMeta('macro', …)` redirects a node's check and evaluation. A
|
|
22
|
-
* comprehension macro (`map`, `filter`, …) sets `alternate` instead, and
|
|
23
|
-
* `alternate` WINS over `macro`, so a call the parser expanded as a macro
|
|
24
|
-
* needs it cleared or the rewrite is silently ignored. The parser expands
|
|
25
|
-
* those names BEFORE this rewrite and refuses any call whose arguments do not
|
|
26
|
-
* fit the macro, so no function may take a macro's name
|
|
27
|
-
* (`FUNCTION_NAME_RESERVED`); clearing keeps a call that did parse reported
|
|
28
|
-
* as the module call it names.
|
|
29
|
-
* - `async` must be set explicitly: cel-js derives it for an `rcall` from
|
|
30
|
-
* `receiverWithArgs`, which only the rcall's own checker fills in — and ours
|
|
31
|
-
* replaces it.
|
|
32
|
-
*
|
|
33
|
-
* The dispatch table is read from the activation under a key no CEL source can
|
|
34
|
-
* spell, so nothing an author can write reaches the mechanism past the export
|
|
35
|
-
* gate or the dependency edge. Binding the table is the kernel's, per scope;
|
|
36
|
-
* until something binds one, evaluating a module call throws naming the
|
|
37
|
-
* function.
|
|
20
|
+
* What is left here is Telo's half: the activation key the kernel binds a scope's table
|
|
21
|
+
* under, the unbound message, and the two questions the analyzer asks about a module's own
|
|
22
|
+
* names colliding with the expression's.
|
|
38
23
|
*/
|
|
39
|
-
import type
|
|
24
|
+
import { type CelNode } from "@telorun/cel";
|
|
40
25
|
/**
|
|
41
|
-
*
|
|
26
|
+
* Where a scope's dispatch table hangs on the activation.
|
|
42
27
|
*
|
|
43
|
-
* `@` and `:` are outside CEL's identifier grammar and
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* that orders the callee before its caller.
|
|
28
|
+
* `@` and `:` are outside CEL's identifier grammar and the activation is reachable no other
|
|
29
|
+
* way, so no author can call past the export gate or the dependency edge. Binding the table
|
|
30
|
+
* is the kernel's, per owning scope; with none, evaluating a module call is refused.
|
|
47
31
|
*/
|
|
48
32
|
export declare const MODULE_CALL_DISPATCH_KEY = "@telo:module-functions";
|
|
49
|
-
/**
|
|
33
|
+
/** A scope's module functions, keyed by qualified name. */
|
|
50
34
|
export type ModuleCallDispatch = ReadonlyMap<string, (args: readonly unknown[]) => unknown>;
|
|
51
35
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* A hook rather than a table because the answer belongs to the analysis, not to
|
|
56
|
-
* the expression: a signature is declared on a resource in the module the call
|
|
57
|
-
* resolves through. With no resolver — every compile, and every analysis until
|
|
58
|
-
* signatures are typed — a module call is `dyn`, which types its arguments and
|
|
59
|
-
* claims nothing about its result.
|
|
36
|
+
* What the host says a module call's RESULT is, as a CEL type expression. The engine types
|
|
37
|
+
* the call node from it, so an operator over the call checks; absent, the call is `dyn`.
|
|
60
38
|
*/
|
|
61
39
|
export type ModuleCallTypeResolver = (qualified: string) => string | undefined;
|
|
62
|
-
/** What a resolved module call says about itself
|
|
63
|
-
* written, the argument nodes, and — once the tree has been type-checked — the
|
|
64
|
-
* type the checker gave each argument. The single reader — no other surface
|
|
65
|
-
* pattern-matches the macro's shape. */
|
|
40
|
+
/** What a resolved module call says about itself. */
|
|
66
41
|
export interface ModuleCall {
|
|
67
42
|
readonly qualified: string;
|
|
68
|
-
readonly args: readonly
|
|
69
|
-
readonly argumentTypes?: readonly string[];
|
|
43
|
+
readonly args: readonly CelNode[];
|
|
70
44
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*
|
|
45
|
+
/** The module call this node IS, or nothing. One node kind, no pattern-matching. */
|
|
46
|
+
export declare function moduleCallOf(node: CelNode): ModuleCall | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Message for a call nothing has bound. Not a fallback value: a call that cannot reach its
|
|
49
|
+
* function has no result, and inventing one would make a missing export read as a null.
|
|
50
|
+
*/
|
|
75
51
|
export declare function unboundModuleCallMessage(qualified: string): string;
|
|
76
52
|
/**
|
|
77
|
-
*
|
|
53
|
+
* Which of a module's own names CEL can read as a namespace.
|
|
54
|
+
*
|
|
55
|
+
* **A module name and an import alias are YAML scalars nothing lexes where they are
|
|
56
|
+
* written** — `my-module`, `test-run` and `cel` all reach a name set, and the naming
|
|
57
|
+
* diagnostics (`INVALID_NAME`, `INVALID_TYPE_NAME`) are what report them. The engine refuses
|
|
58
|
+
* such a name at registration and refuses the SET WHOLE, so handing one over unfiltered
|
|
59
|
+
* turns a reportable name into a crash that loses every other diagnostic in the file. A name
|
|
60
|
+
* CEL cannot read as a namespace resolves no call, which is exactly what the naming
|
|
61
|
+
* diagnostic says is wrong with it.
|
|
78
62
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* reported again, so two passes over one tree agree about what it calls.
|
|
63
|
+
* It is here rather than in a consumer because the module-name set is this package's concept
|
|
64
|
+
* — `CompileEnv.moduleNames` — and three callers need the same answer: compiling an
|
|
65
|
+
* expression, the analyzer's typed site environments, and the kernel's type-rule conditions.
|
|
83
66
|
*/
|
|
84
|
-
export declare function
|
|
85
|
-
/** Every resolved module call in
|
|
86
|
-
export declare function moduleCallNodes(
|
|
87
|
-
node:
|
|
67
|
+
export declare function celNamespaceNames(moduleNames: Iterable<string>): ReadonlySet<string>;
|
|
68
|
+
/** Every resolved module call in the tree with its node, outermost first. */
|
|
69
|
+
export declare function moduleCallNodes(root: CelNode | undefined): Array<{
|
|
70
|
+
node: CelNode;
|
|
88
71
|
call: ModuleCall;
|
|
89
72
|
}>;
|
|
73
|
+
/** Every qualified call's name, as written. */
|
|
74
|
+
export declare function moduleCallNames(root: CelNode | undefined): readonly string[];
|
|
90
75
|
/**
|
|
91
|
-
* Bare identifiers
|
|
76
|
+
* Bare identifiers that are the RECEIVER of an unresolved call (`dbb.query(1)`), so the
|
|
77
|
+
* caller reporting the root can ask whether such a name could denote a module at all rather
|
|
78
|
+
* than telling an author to add an `imports:` alias for a typo.
|
|
92
79
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* different spelling — so the caller that reports the root says so.
|
|
80
|
+
* A call the name set resolved is a `qcall` and is not here — it names a module, so reading
|
|
81
|
+
* its receiver as a root would invent a dependency the expression never states.
|
|
96
82
|
*/
|
|
97
|
-
export declare function unresolvedCallReceivers(
|
|
83
|
+
export declare function unresolvedCallReceivers(root: CelNode | undefined, moduleNames?: ReadonlySet<string>): Set<string>;
|
|
98
84
|
/**
|
|
99
|
-
* Names bound INSIDE the expression — a comprehension variable, a `cel.bind`
|
|
100
|
-
*
|
|
85
|
+
* Names bound INSIDE the expression — a comprehension variable, a `cel.bind` name — that
|
|
86
|
+
* collide with one of the module's names.
|
|
87
|
+
*
|
|
88
|
+
* Such a binding is unreachable through a call: `Billing.f(x)` inside it resolves to the
|
|
89
|
+
* module, never to the bound value. Reported as a reserved name rather than silently
|
|
90
|
+
* shadowed, which is the rule every other name in CEL scope already follows.
|
|
101
91
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* scope already follows.
|
|
92
|
+
* The binding forms come from the engine's own enumeration (`BINDING_FORMS`) rather than a
|
|
93
|
+
* list kept in step with it here — the previous spelling carried a hand-written set of
|
|
94
|
+
* comprehension method names, mirrored in a second file.
|
|
106
95
|
*/
|
|
107
|
-
export declare function moduleNameBindings(
|
|
96
|
+
export declare function moduleNameBindings(root: CelNode | undefined, moduleNames?: ReadonlySet<string>): string[];
|
|
108
97
|
//# sourceMappingURL=module-call.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-call.d.ts","sourceRoot":"","sources":["../../src/cel/module-call.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"module-call.d.ts","sourceRoot":"","sources":["../../src/cel/module-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAQL,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAEtB;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,2BAA2B,CAAC;AAEjE,2DAA2D;AAC3D,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;AAE5F;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE/E,qDAAqD;AACrD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;CACnC;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAGlE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CASlE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAQpF;AAID,6EAA6E;AAC7E,wBAAgB,eAAe,CAC7B,IAAI,EAAE,OAAO,GAAG,SAAS,GACxB,KAAK,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAU5C;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,MAAM,EAAE,CAE5E;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,WAAW,GAAE,WAAW,CAAC,MAAM,CAAY,GAC1C,GAAG,CAAC,MAAM,CAAC,CAeb;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,WAAW,GAAE,WAAW,CAAC,MAAM,CAAY,GAC1C,MAAM,EAAE,CAUV"}
|
package/dist/cel/module-call.js
CHANGED
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Module calls: what a resolved one says, where the dispatch table hangs, and the two walks
|
|
3
|
+
* the analyzer asks of an expression's own names.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* that
|
|
5
|
+
* **The rewrite is gone.** `Alias.fn(x)` and `obj.method(x)` are the same syntax and only a
|
|
6
|
+
* set of names distinguishes them, so this package used to rewrite the parsed tree itself,
|
|
7
|
+
* through internals the previous engine did not expose: a `setMeta('macro', …)` redirect
|
|
8
|
+
* that made a qualified call check and evaluate as something else, with a comprehension
|
|
9
|
+
* macro's `alternate` winning over `macro` unless cleared, and an rcall's asyncness derived
|
|
10
|
+
* from state the replaced checker filled in. Three facts about a dependency's internals,
|
|
11
|
+
* each pinned by a test, and the reason it was pinned to an exact version.
|
|
12
|
+
*
|
|
13
|
+
* `@telorun/cel` has **`qcall` as a node of its own**, produced by a total tree-to-tree pass
|
|
14
|
+
* over the name set — never by the parser, because the set is the host's — and a
|
|
15
|
+
* `CelExpression` records the set it was resolved under, so an environment refuses a tree
|
|
16
|
+
* resolved for a different site instead of answering a different question about it. So
|
|
17
|
+
* reading a module call is reading a node kind, and there is nothing to rewrite and nothing
|
|
18
|
+
* to pin.
|
|
19
|
+
*
|
|
20
|
+
* What is left here is Telo's half: the activation key the kernel binds a scope's table
|
|
21
|
+
* under, the unbound message, and the two questions the analyzer asks about a module's own
|
|
22
|
+
* names colliding with the expression's.
|
|
23
|
+
*/
|
|
24
|
+
import { childNodes, isIdentifierSpelling, isReservedWord, namespaceMacroBinding, qualifiedCalls, receiverMacroBinding, RESERVED_NAMESPACES, } from "@telorun/cel";
|
|
25
|
+
/**
|
|
26
|
+
* Where a scope's dispatch table hangs on the activation.
|
|
27
|
+
*
|
|
28
|
+
* `@` and `:` are outside CEL's identifier grammar and the activation is reachable no other
|
|
29
|
+
* way, so no author can call past the export gate or the dependency edge. Binding the table
|
|
30
|
+
* is the kernel's, per owning scope; with none, evaluating a module call is refused.
|
|
8
31
|
*/
|
|
9
32
|
export const MODULE_CALL_DISPATCH_KEY = "@telo:module-functions";
|
|
10
|
-
/**
|
|
11
|
-
* known members to extend — the internals are read through this cast, in one
|
|
12
|
-
* place. */
|
|
13
|
-
const metaOf = (node) => node;
|
|
33
|
+
/** The module call this node IS, or nothing. One node kind, no pattern-matching. */
|
|
14
34
|
export function moduleCallOf(node) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
qualified: macro.qualified,
|
|
19
|
-
args: macro.args,
|
|
20
|
-
...(macro.argumentTypes ? { argumentTypes: macro.argumentTypes } : {}),
|
|
21
|
-
}
|
|
22
|
-
: undefined;
|
|
35
|
+
if (node.kind !== "qcall")
|
|
36
|
+
return undefined;
|
|
37
|
+
return { qualified: `${node.namespace}.${node.name}`, args: node.args };
|
|
23
38
|
}
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
39
|
+
/**
|
|
40
|
+
* Message for a call nothing has bound. Not a fallback value: a call that cannot reach its
|
|
41
|
+
* function has no result, and inventing one would make a missing export read as a null.
|
|
42
|
+
*/
|
|
27
43
|
export function unboundModuleCallMessage(qualified) {
|
|
28
44
|
const dot = qualified.indexOf(".");
|
|
29
45
|
const receiver = qualified.slice(0, dot);
|
|
@@ -32,214 +48,122 @@ export function unboundModuleCallMessage(qualified) {
|
|
|
32
48
|
`'${receiver}' must be an imports: alias (or Self, or this module's own name) whose ` +
|
|
33
49
|
`module declares a callable named '${fn}' and exports it.`);
|
|
34
50
|
}
|
|
35
|
-
const NO_NAMES = new Set();
|
|
36
51
|
/**
|
|
37
|
-
*
|
|
52
|
+
* Which of a module's own names CEL can read as a namespace.
|
|
53
|
+
*
|
|
54
|
+
* **A module name and an import alias are YAML scalars nothing lexes where they are
|
|
55
|
+
* written** — `my-module`, `test-run` and `cel` all reach a name set, and the naming
|
|
56
|
+
* diagnostics (`INVALID_NAME`, `INVALID_TYPE_NAME`) are what report them. The engine refuses
|
|
57
|
+
* such a name at registration and refuses the SET WHOLE, so handing one over unfiltered
|
|
58
|
+
* turns a reportable name into a crash that loses every other diagnostic in the file. A name
|
|
59
|
+
* CEL cannot read as a namespace resolves no call, which is exactly what the naming
|
|
60
|
+
* diagnostic says is wrong with it.
|
|
38
61
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* reported again, so two passes over one tree agree about what it calls.
|
|
62
|
+
* It is here rather than in a consumer because the module-name set is this package's concept
|
|
63
|
+
* — `CompileEnv.moduleNames` — and three callers need the same answer: compiling an
|
|
64
|
+
* expression, the analyzer's typed site environments, and the kernel's type-rule conditions.
|
|
43
65
|
*/
|
|
44
|
-
export function
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// is what the TREE calls rather than what this pass happened to change.
|
|
53
|
-
const resolved = moduleCallOf(node);
|
|
54
|
-
if (resolved) {
|
|
55
|
-
calls.push(resolved.qualified);
|
|
56
|
-
for (const arg of resolved.args)
|
|
57
|
-
visit(arg, moduleNames, typeOf, calls);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const receiver = moduleCallReceiver(node, moduleNames);
|
|
61
|
-
if (receiver) {
|
|
62
|
-
const [method, , args] = node.args;
|
|
63
|
-
const qualified = `${receiver}.${method}`;
|
|
64
|
-
calls.push(qualified);
|
|
65
|
-
rewrite(node, qualified, args, typeOf);
|
|
66
|
-
// The receiver names a MODULE, not a value, so it is not descended into:
|
|
67
|
-
// that is what keeps it out of every access chain, out of `refs`, and out
|
|
68
|
-
// of the undeclared-root check.
|
|
69
|
-
for (const arg of args)
|
|
70
|
-
visit(arg, moduleNames, typeOf, calls);
|
|
71
|
-
return;
|
|
66
|
+
export function celNamespaceNames(moduleNames) {
|
|
67
|
+
const usable = new Set();
|
|
68
|
+
for (const name of moduleNames) {
|
|
69
|
+
if (!isIdentifierSpelling(name) || isReservedWord(name))
|
|
70
|
+
continue;
|
|
71
|
+
if (RESERVED_NAMESPACES.includes(name))
|
|
72
|
+
continue;
|
|
73
|
+
usable.add(name);
|
|
72
74
|
}
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
/** The module name a node's receiver is, or undefined when the node is not a
|
|
76
|
-
* module call. `a.b.c(x)` is not one — its receiver is a member access, not a
|
|
77
|
-
* bare identifier. */
|
|
78
|
-
function moduleCallReceiver(node, moduleNames) {
|
|
79
|
-
if (node.op !== "rcall" || !Array.isArray(node.args))
|
|
80
|
-
return undefined;
|
|
81
|
-
const [method, receiver, args] = node.args;
|
|
82
|
-
if (typeof method !== "string" || !Array.isArray(args))
|
|
83
|
-
return undefined;
|
|
84
|
-
if (!isNode(receiver) || receiver.op !== "id")
|
|
85
|
-
return undefined;
|
|
86
|
-
const name = receiver.args;
|
|
87
|
-
return moduleNames.has(name) ? name : undefined;
|
|
75
|
+
return usable;
|
|
88
76
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
qualified,
|
|
93
|
-
args,
|
|
94
|
-
typeCheck(chk, m, ctx) {
|
|
95
|
-
// The arguments are checked in the CURRENT context, so a mistake inside
|
|
96
|
-
// one is reported where it is written — and each argument's type is kept,
|
|
97
|
-
// so whoever knows the callee's signature can compare against it.
|
|
98
|
-
m.argumentTypes = m.args.map((arg) => typeNameOf(chk.check(arg, ctx)));
|
|
99
|
-
// cel-js derives an rcall's asyncness from `receiverWithArgs`, which only
|
|
100
|
-
// the rcall checker this macro replaces fills in — so it is stated: the
|
|
101
|
-
// dispatch is synchronous, so the node is async exactly when one of its
|
|
102
|
-
// arguments is. Asked only now, once each argument is checked: an
|
|
103
|
-
// argument's answer is cached on first reading, and read before its own
|
|
104
|
-
// check it is the conservative `true` for every operator and call.
|
|
105
|
-
metaOf(node).setMeta("async", m.args.some((arg) => arg.maybeAsync === true));
|
|
106
|
-
const declared = typeOf?.(m.qualified);
|
|
107
|
-
return declared === undefined ? chk.dynType : chk.getType(declared);
|
|
108
|
-
},
|
|
109
|
-
evaluate(ev, m, ctx) {
|
|
110
|
-
const table = ctx.getValue(MODULE_CALL_DISPATCH_KEY);
|
|
111
|
-
const fn = table?.get(m.qualified);
|
|
112
|
-
if (!fn)
|
|
113
|
-
throw new Error(unboundModuleCallMessage(m.qualified));
|
|
114
|
-
const values = m.args.map((arg) => ev.eval(arg, ctx));
|
|
115
|
-
// A callable's `call` is synchronous; an ARGUMENT need not be, and every
|
|
116
|
-
// other dispatch in cel-js settles its operands first. Handing a pending
|
|
117
|
-
// Promise to the function instead would pass it a value of the wrong type
|
|
118
|
-
// with nothing reported.
|
|
119
|
-
return values.some((value) => value instanceof Promise)
|
|
120
|
-
? Promise.all(values).then((settled) => fn(settled))
|
|
121
|
-
: fn(values);
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
metaOf(node)
|
|
125
|
-
// A comprehension macro expands into an `alternate`, which cel-js consults
|
|
126
|
-
// BEFORE `macro`. Left in place, `Billing.map(i, i)` would evaluate as a
|
|
127
|
-
// comprehension over an identifier rather than as the module call it names.
|
|
128
|
-
.setMeta("alternate", undefined)
|
|
129
|
-
.setMeta("macro", macro);
|
|
130
|
-
}
|
|
131
|
-
/** Every resolved module call in `ast` with its node, outermost first. */
|
|
132
|
-
export function moduleCallNodes(ast) {
|
|
77
|
+
const NO_NAMES = new Set();
|
|
78
|
+
/** Every resolved module call in the tree with its node, outermost first. */
|
|
79
|
+
export function moduleCallNodes(root) {
|
|
133
80
|
const out = [];
|
|
134
|
-
if (
|
|
135
|
-
walk(
|
|
81
|
+
if (root)
|
|
82
|
+
walk(root);
|
|
136
83
|
return out;
|
|
137
84
|
function walk(node) {
|
|
138
85
|
const call = moduleCallOf(node);
|
|
139
|
-
if (call)
|
|
86
|
+
if (call)
|
|
140
87
|
out.push({ node, call });
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
descend(node, walk);
|
|
88
|
+
for (const child of childNodes(node))
|
|
89
|
+
walk(child);
|
|
146
90
|
}
|
|
147
91
|
}
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const name = type?.name;
|
|
152
|
-
return typeof name === "string" ? name : "dyn";
|
|
92
|
+
/** Every qualified call's name, as written. */
|
|
93
|
+
export function moduleCallNames(root) {
|
|
94
|
+
return root ? qualifiedCalls(root).map((call) => call.qualifiedName) : [];
|
|
153
95
|
}
|
|
154
96
|
/**
|
|
155
|
-
* Bare identifiers
|
|
97
|
+
* Bare identifiers that are the RECEIVER of an unresolved call (`dbb.query(1)`), so the
|
|
98
|
+
* caller reporting the root can ask whether such a name could denote a module at all rather
|
|
99
|
+
* than telling an author to add an `imports:` alias for a typo.
|
|
156
100
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* different spelling — so the caller that reports the root says so.
|
|
101
|
+
* A call the name set resolved is a `qcall` and is not here — it names a module, so reading
|
|
102
|
+
* its receiver as a root would invent a dependency the expression never states.
|
|
160
103
|
*/
|
|
161
|
-
export function unresolvedCallReceivers(
|
|
104
|
+
export function unresolvedCallReceivers(root, moduleNames = NO_NAMES) {
|
|
162
105
|
const out = new Set();
|
|
163
|
-
if (
|
|
164
|
-
walk(
|
|
106
|
+
if (root)
|
|
107
|
+
walk(root);
|
|
165
108
|
return out;
|
|
166
109
|
function walk(node) {
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
if (node.op === "rcall" && Array.isArray(node.args)) {
|
|
173
|
-
const receiver = node.args[1];
|
|
174
|
-
if (isNode(receiver) && receiver.op === "id" && !moduleNames.has(receiver.args)) {
|
|
175
|
-
out.add(receiver.args);
|
|
176
|
-
}
|
|
110
|
+
if (node.kind === "receiverCall" &&
|
|
111
|
+
node.receiver.kind === "ident" &&
|
|
112
|
+
!moduleNames.has(node.receiver.name)) {
|
|
113
|
+
out.add(node.receiver.name);
|
|
177
114
|
}
|
|
178
|
-
|
|
115
|
+
for (const child of childNodes(node))
|
|
116
|
+
walk(child);
|
|
179
117
|
}
|
|
180
118
|
}
|
|
181
119
|
/**
|
|
182
|
-
* Names bound INSIDE the expression — a comprehension variable, a `cel.bind`
|
|
183
|
-
*
|
|
120
|
+
* Names bound INSIDE the expression — a comprehension variable, a `cel.bind` name — that
|
|
121
|
+
* collide with one of the module's names.
|
|
184
122
|
*
|
|
185
|
-
* Such a binding is unreachable through a call: `Billing.f(x)` inside it
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
123
|
+
* Such a binding is unreachable through a call: `Billing.f(x)` inside it resolves to the
|
|
124
|
+
* module, never to the bound value. Reported as a reserved name rather than silently
|
|
125
|
+
* shadowed, which is the rule every other name in CEL scope already follows.
|
|
126
|
+
*
|
|
127
|
+
* The binding forms come from the engine's own enumeration (`BINDING_FORMS`) rather than a
|
|
128
|
+
* list kept in step with it here — the previous spelling carried a hand-written set of
|
|
129
|
+
* comprehension method names, mirrored in a second file.
|
|
189
130
|
*/
|
|
190
|
-
export function moduleNameBindings(
|
|
131
|
+
export function moduleNameBindings(root, moduleNames = NO_NAMES) {
|
|
191
132
|
const out = [];
|
|
192
|
-
if (
|
|
193
|
-
walk(
|
|
133
|
+
if (root && moduleNames.size > 0)
|
|
134
|
+
walk(root);
|
|
194
135
|
return [...new Set(out)];
|
|
195
136
|
function walk(node) {
|
|
196
137
|
const bound = boundNameOf(node);
|
|
197
138
|
if (bound !== undefined && moduleNames.has(bound))
|
|
198
139
|
out.push(bound);
|
|
199
|
-
|
|
140
|
+
for (const child of childNodes(node))
|
|
141
|
+
walk(child);
|
|
200
142
|
}
|
|
201
143
|
}
|
|
202
|
-
/**
|
|
203
|
-
*
|
|
144
|
+
/**
|
|
145
|
+
* The name a binding form introduces: a comprehension macro's iteration variable, or
|
|
146
|
+
* `cel.bind(<name>, …)`'s first argument.
|
|
147
|
+
*
|
|
148
|
+
* **The binding is asked of the engine by NAME AND ARITY.** `BINDING_FORMS` is a list of
|
|
149
|
+
* `"map/2"`, `"map/3"`, `"cel.bind/3"` — a bare `"map"` matches none of them, so a set over
|
|
150
|
+
* the list and a `.has(node.name)` test silently never fires.
|
|
151
|
+
*
|
|
152
|
+
* **And `cel` is a RESERVED namespace** (`cel`, `optional`), which a host can never claim —
|
|
153
|
+
* so `cel.bind(c, …)` is not a qualified call at all: it reads as a receiver call on the
|
|
154
|
+
* ident `cel`, which is in no scope and never will be. Reading it as a `qcall` matches
|
|
155
|
+
* nothing, and the cost is not just a missed binding: the bound name and the bare `cel` then
|
|
156
|
+
* leak out as member-access chains, so a comprehension variable is reported as an undeclared
|
|
157
|
+
* field and `cel` itself as an unknown identifier.
|
|
158
|
+
*/
|
|
204
159
|
function boundNameOf(node) {
|
|
205
|
-
if (node.
|
|
206
|
-
return undefined;
|
|
207
|
-
if (moduleCallOf(node))
|
|
160
|
+
if (node.kind !== "receiverCall")
|
|
208
161
|
return undefined;
|
|
209
|
-
const
|
|
210
|
-
|
|
162
|
+
const binding = node.receiver.kind === "ident" && node.receiver.name === "cel"
|
|
163
|
+
? namespaceMacroBinding("cel", node.name, node.args.length)
|
|
164
|
+
: receiverMacroBinding(node.name, node.args.length);
|
|
165
|
+
if (!binding)
|
|
211
166
|
return undefined;
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
return undefined;
|
|
215
|
-
if (method === "bind") {
|
|
216
|
-
return isNode(receiver) && receiver.op === "id" && receiver.args === "cel"
|
|
217
|
-
? first.args
|
|
218
|
-
: undefined;
|
|
219
|
-
}
|
|
220
|
-
return COMPREHENSION_METHODS.has(method) ? first.args : undefined;
|
|
221
|
-
}
|
|
222
|
-
/** cel-js's comprehension macros, which bind their first argument as the
|
|
223
|
-
* iteration variable. Mirrors the set `analyze.ts` walks with. */
|
|
224
|
-
const COMPREHENSION_METHODS = new Set(["filter", "map", "exists", "all", "exists_one"]);
|
|
225
|
-
/** Generic descent over a node's operands — an array, a single node, or an
|
|
226
|
-
* array of arrays (a map literal's entries). */
|
|
227
|
-
function descend(node, fn) {
|
|
228
|
-
const args = node.args;
|
|
229
|
-
if (Array.isArray(args)) {
|
|
230
|
-
for (const arg of args) {
|
|
231
|
-
if (isNode(arg))
|
|
232
|
-
fn(arg);
|
|
233
|
-
else if (Array.isArray(arg))
|
|
234
|
-
for (const item of arg)
|
|
235
|
-
if (isNode(item))
|
|
236
|
-
fn(item);
|
|
237
|
-
}
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (isNode(args))
|
|
241
|
-
fn(args);
|
|
242
|
-
}
|
|
243
|
-
function isNode(v) {
|
|
244
|
-
return v !== null && typeof v === "object" && "op" in v;
|
|
167
|
+
const held = node.args[binding.variableArgument];
|
|
168
|
+
return held?.kind === "ident" ? held.name : undefined;
|
|
245
169
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CelEnvironment } from "@telorun/cel";
|
|
2
2
|
/**
|
|
3
|
-
* Register every nominal value brand on an analysis environment, with what a
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* extended with `.joinPath(relative)` and stay one.
|
|
3
|
+
* Register every nominal value brand on an analysis environment, with what a brand may do:
|
|
4
|
+
* convert to its base with the base's own conversion (`int(ports.http)`,
|
|
5
|
+
* `string(variables.dataDir)`), render as text (`string(ports.http)`), and — for a host
|
|
6
|
+
* path — be extended with `.joinPath(relative)` and stay one.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
8
|
+
* **Declared, not implemented.** A nominal type is a checking concept: the engine takes the
|
|
9
|
+
* conversions and members as signatures over `Self` and needs no function body for any of
|
|
10
|
+
* them, because at runtime a branded value IS its base (an int, a string) and the standard
|
|
11
|
+
* library's own overloads are what evaluate. The previous engine required an implementation
|
|
12
|
+
* per registration, so this file carried three stubs a brand's values never reached.
|
|
13
|
+
*
|
|
14
|
+
* `buildCelEnvironment` registers none of it: a caller typing a site registers the brands on
|
|
15
|
+
* its own clone.
|
|
14
16
|
*/
|
|
15
|
-
export declare function registerValueBrands(
|
|
17
|
+
export declare function registerValueBrands(environment: CelEnvironment): void;
|
|
16
18
|
//# sourceMappingURL=value-brands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value-brands.d.ts","sourceRoot":"","sources":["../../src/cel/value-brands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"value-brands.d.ts","sourceRoot":"","sources":["../../src/cel/value-brands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,cAAc,GAAG,IAAI,CAerE"}
|