@manifesto-ai/compiler 1.6.1 → 1.6.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/dist/api/compile-mel-patch-collector.d.ts +32 -0
- package/dist/api/compile-mel-patch-collector.d.ts.map +1 -0
- package/dist/api/compile-mel-patch-collector.js +425 -0
- package/dist/api/compile-mel-patch-collector.js.map +1 -0
- package/dist/api/compile-mel-patch-expr.d.ts +9 -0
- package/dist/api/compile-mel-patch-expr.d.ts.map +1 -0
- package/dist/api/compile-mel-patch-expr.js +179 -0
- package/dist/api/compile-mel-patch-expr.js.map +1 -0
- package/dist/api/compile-mel-patch-location.d.ts +10 -0
- package/dist/api/compile-mel-patch-location.d.ts.map +1 -0
- package/dist/api/compile-mel-patch-location.js +48 -0
- package/dist/api/compile-mel-patch-location.js.map +1 -0
- package/dist/api/compile-mel-patch.d.ts +6 -0
- package/dist/api/compile-mel-patch.d.ts.map +1 -0
- package/dist/api/compile-mel-patch.js +244 -0
- package/dist/api/compile-mel-patch.js.map +1 -0
- package/dist/api/compile-mel.d.ts.map +1 -1
- package/dist/api/compile-mel.js +2 -17
- package/dist/api/compile-mel.js.map +1 -1
- package/dist/evaluation/context.d.ts.map +1 -1
- package/dist/evaluation/context.js +2 -8
- package/dist/evaluation/context.js.map +1 -1
- package/dist/evaluation/evaluate-expr.d.ts.map +1 -1
- package/dist/evaluation/evaluate-expr.js +2 -1
- package/dist/evaluation/evaluate-expr.js.map +1 -1
- package/dist/evaluation/evaluate-runtime-patch.d.ts.map +1 -1
- package/dist/evaluation/evaluate-runtime-patch.js +35 -3
- package/dist/evaluation/evaluate-runtime-patch.js.map +1 -1
- package/dist/generator/ir.js +10 -4
- package/dist/generator/ir.js.map +1 -1
- package/dist/generator/lowering.d.ts.map +1 -1
- package/dist/generator/lowering.js +3 -2
- package/dist/generator/lowering.js.map +1 -1
- package/dist/lowering/lower-expr.js +15 -0
- package/dist/lowering/lower-expr.js.map +1 -1
- package/dist/renderer/patch-op.d.ts.map +1 -1
- package/dist/renderer/patch-op.js +4 -3
- package/dist/renderer/patch-op.js.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Diagnostic } from "../diagnostics/types.js";
|
|
2
|
+
import type { MelExprNode } from "../lowering/lower-expr.js";
|
|
3
|
+
import type { GuardedStmtNode, InnerStmtNode, PatchStmtNode } from "../parser/ast.js";
|
|
4
|
+
import { toMelExpr } from "./compile-mel-patch-expr.js";
|
|
5
|
+
export interface PatchCollectContext {
|
|
6
|
+
actionName: string;
|
|
7
|
+
onceCounter: number;
|
|
8
|
+
onceIntentCounter: number;
|
|
9
|
+
whenCounter: number;
|
|
10
|
+
}
|
|
11
|
+
export type ConditionedPatchStatement = {
|
|
12
|
+
patch: PatchStmtNode;
|
|
13
|
+
condition?: MelExprNode;
|
|
14
|
+
};
|
|
15
|
+
export interface PatchCollectorDeps {
|
|
16
|
+
toMelExpr: (expr: Parameters<typeof toMelExpr>[0]) => MelExprNode;
|
|
17
|
+
mapLocation: (location: Diagnostic["location"]) => Diagnostic["location"];
|
|
18
|
+
}
|
|
19
|
+
export declare class PatchStatementCollector {
|
|
20
|
+
private readonly deps;
|
|
21
|
+
private readonly conditionComposer;
|
|
22
|
+
constructor(deps: PatchCollectorDeps);
|
|
23
|
+
collect(stmts: GuardedStmtNode[] | InnerStmtNode[], errors: Diagnostic[], context: PatchCollectContext, parentCondition: MelExprNode | undefined): ConditionedPatchStatement[];
|
|
24
|
+
private collectPatchStatements;
|
|
25
|
+
}
|
|
26
|
+
export declare function compilePatchStmtToMelRuntime(patchStatement: ConditionedPatchStatement): {
|
|
27
|
+
op: "set" | "unset" | "merge";
|
|
28
|
+
path: string;
|
|
29
|
+
value?: MelExprNode;
|
|
30
|
+
condition?: MelExprNode;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=compile-mel-patch-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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xC;IAAE,EAAE,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,WAAW,CAAA;CAAE,CAS/F"}
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { sha256Sync } from "@manifesto-ai/core";
|
|
2
|
+
import { toMelExpr } from "./compile-mel-patch-expr.js";
|
|
3
|
+
export class PatchStatementCollector {
|
|
4
|
+
deps;
|
|
5
|
+
conditionComposer = new ConditionComposer();
|
|
6
|
+
constructor(deps) {
|
|
7
|
+
this.deps = deps;
|
|
8
|
+
}
|
|
9
|
+
collect(stmts, errors, context, parentCondition) {
|
|
10
|
+
return this.collectPatchStatements(stmts, errors, context, parentCondition);
|
|
11
|
+
}
|
|
12
|
+
collectPatchStatements(stmts, errors, context, parentCondition) {
|
|
13
|
+
const patchStatements = [];
|
|
14
|
+
for (const stmt of stmts) {
|
|
15
|
+
if (stmt.kind === "patch") {
|
|
16
|
+
const dynamicIndexSegment = stmt.path.segments.find((segment) => segment.kind === "indexSegment" && segment.index.kind !== "literal");
|
|
17
|
+
if (dynamicIndexSegment) {
|
|
18
|
+
errors.push({
|
|
19
|
+
severity: "error",
|
|
20
|
+
code: "E_DYNAMIC_PATCH_PATH",
|
|
21
|
+
message: "Dynamic patch path indexes are not supported. Use a literal index.",
|
|
22
|
+
location: this.deps.mapLocation(dynamicIndexSegment.location),
|
|
23
|
+
});
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
patchStatements.push({
|
|
27
|
+
patch: stmt,
|
|
28
|
+
condition: parentCondition,
|
|
29
|
+
});
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (stmt.kind === "when") {
|
|
33
|
+
let condition = parentCondition;
|
|
34
|
+
try {
|
|
35
|
+
condition = this.conditionComposer.and(parentCondition, this.deps.toMelExpr(stmt.condition));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
errors.push({
|
|
39
|
+
severity: "error",
|
|
40
|
+
code: "E_LOWER",
|
|
41
|
+
message: error.message,
|
|
42
|
+
location: this.deps.mapLocation(stmt.condition.location),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const whenMarkerId = sha256Sync(`${context.actionName}:${context.whenCounter}:when`);
|
|
46
|
+
context.whenCounter += 1;
|
|
47
|
+
const whenMarkerPath = {
|
|
48
|
+
kind: "path",
|
|
49
|
+
segments: [
|
|
50
|
+
{
|
|
51
|
+
kind: "propertySegment",
|
|
52
|
+
name: "$mel",
|
|
53
|
+
location: stmt.location,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
kind: "propertySegment",
|
|
57
|
+
name: "__whenGuards",
|
|
58
|
+
location: stmt.location,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
kind: "propertySegment",
|
|
62
|
+
name: whenMarkerId,
|
|
63
|
+
location: stmt.location,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
location: stmt.location,
|
|
67
|
+
};
|
|
68
|
+
const whenMarkerExpr = pathToMelExpr(whenMarkerPath);
|
|
69
|
+
const guardedBody = this.collectPatchStatements(stmt.body, errors, context, undefined).map((statement) => ({
|
|
70
|
+
patch: statement.patch,
|
|
71
|
+
condition: this.conditionComposer.and(whenMarkerExpr, statement.condition),
|
|
72
|
+
}));
|
|
73
|
+
patchStatements.push({
|
|
74
|
+
patch: {
|
|
75
|
+
kind: "patch",
|
|
76
|
+
op: "set",
|
|
77
|
+
path: whenMarkerPath,
|
|
78
|
+
value: {
|
|
79
|
+
kind: "literal",
|
|
80
|
+
literalType: "boolean",
|
|
81
|
+
value: true,
|
|
82
|
+
location: stmt.location,
|
|
83
|
+
},
|
|
84
|
+
location: stmt.location,
|
|
85
|
+
},
|
|
86
|
+
condition,
|
|
87
|
+
}, ...guardedBody, {
|
|
88
|
+
patch: {
|
|
89
|
+
kind: "patch",
|
|
90
|
+
op: "unset",
|
|
91
|
+
path: whenMarkerPath,
|
|
92
|
+
location: stmt.location,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (stmt.kind === "once") {
|
|
98
|
+
let condition = parentCondition;
|
|
99
|
+
const markerExpr = pathToMelExpr(stmt.marker);
|
|
100
|
+
const markerPath = stmt.marker;
|
|
101
|
+
const markerLocation = stmt.location;
|
|
102
|
+
let onceCondition = {
|
|
103
|
+
kind: "call",
|
|
104
|
+
fn: "neq",
|
|
105
|
+
args: [markerExpr, { kind: "sys", path: ["meta", "intentId"] }],
|
|
106
|
+
};
|
|
107
|
+
if (stmt.condition) {
|
|
108
|
+
try {
|
|
109
|
+
onceCondition = this.conditionComposer.and(onceCondition, this.deps.toMelExpr(stmt.condition)) ?? onceCondition;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
errors.push({
|
|
113
|
+
severity: "error",
|
|
114
|
+
code: "E_LOWER",
|
|
115
|
+
message: error.message,
|
|
116
|
+
location: this.deps.mapLocation(stmt.condition.location),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
condition = this.conditionComposer.and(parentCondition, onceCondition);
|
|
121
|
+
const onceScopeMarkerId = sha256Sync(`${context.actionName}:${context.onceCounter}:once`);
|
|
122
|
+
context.onceCounter += 1;
|
|
123
|
+
const onceScopeMarkerPath = {
|
|
124
|
+
kind: "path",
|
|
125
|
+
segments: [
|
|
126
|
+
{
|
|
127
|
+
kind: "propertySegment",
|
|
128
|
+
name: "$mel",
|
|
129
|
+
location: markerLocation,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
kind: "propertySegment",
|
|
133
|
+
name: "__onceScopeGuards",
|
|
134
|
+
location: markerLocation,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
kind: "propertySegment",
|
|
138
|
+
name: onceScopeMarkerId,
|
|
139
|
+
location: markerLocation,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
location: markerLocation,
|
|
143
|
+
};
|
|
144
|
+
const onceScopeMarkerExpr = pathToMelExpr(onceScopeMarkerPath);
|
|
145
|
+
const scopedBodyPatchStatements = this.collectPatchStatements(stmt.body, errors, context, onceScopeMarkerExpr);
|
|
146
|
+
patchStatements.push({
|
|
147
|
+
patch: {
|
|
148
|
+
kind: "patch",
|
|
149
|
+
op: "set",
|
|
150
|
+
path: onceScopeMarkerPath,
|
|
151
|
+
value: {
|
|
152
|
+
kind: "literal",
|
|
153
|
+
literalType: "boolean",
|
|
154
|
+
value: true,
|
|
155
|
+
location: markerLocation,
|
|
156
|
+
},
|
|
157
|
+
location: markerLocation,
|
|
158
|
+
},
|
|
159
|
+
condition,
|
|
160
|
+
}, {
|
|
161
|
+
patch: {
|
|
162
|
+
kind: "patch",
|
|
163
|
+
op: "set",
|
|
164
|
+
path: markerPath,
|
|
165
|
+
value: {
|
|
166
|
+
kind: "systemIdent",
|
|
167
|
+
path: ["meta", "intentId"],
|
|
168
|
+
location: markerLocation,
|
|
169
|
+
},
|
|
170
|
+
location: markerLocation,
|
|
171
|
+
},
|
|
172
|
+
condition: onceScopeMarkerExpr,
|
|
173
|
+
}, ...scopedBodyPatchStatements, {
|
|
174
|
+
patch: {
|
|
175
|
+
kind: "patch",
|
|
176
|
+
op: "unset",
|
|
177
|
+
path: onceScopeMarkerPath,
|
|
178
|
+
location: markerLocation,
|
|
179
|
+
},
|
|
180
|
+
condition,
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (stmt.kind === "onceIntent") {
|
|
185
|
+
const markerScopeId = sha256Sync(`${context.actionName}:${context.onceCounter}:onceIntent`);
|
|
186
|
+
context.onceCounter += 1;
|
|
187
|
+
const markerScopePath = {
|
|
188
|
+
kind: "path",
|
|
189
|
+
segments: [
|
|
190
|
+
{
|
|
191
|
+
kind: "propertySegment",
|
|
192
|
+
name: "$mel",
|
|
193
|
+
location: stmt.location,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
kind: "propertySegment",
|
|
197
|
+
name: "__onceScopeGuards",
|
|
198
|
+
location: stmt.location,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
kind: "propertySegment",
|
|
202
|
+
name: markerScopeId,
|
|
203
|
+
location: stmt.location,
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
location: stmt.location,
|
|
207
|
+
};
|
|
208
|
+
const markerScopeExpr = pathToMelExpr(markerScopePath);
|
|
209
|
+
const onceIntentGuardId = sha256Sync(`${context.actionName}:${context.onceIntentCounter}:intent`);
|
|
210
|
+
context.onceIntentCounter += 1;
|
|
211
|
+
const markerLocation = stmt.location;
|
|
212
|
+
const onceIntentGuardPath = {
|
|
213
|
+
kind: "path",
|
|
214
|
+
segments: [
|
|
215
|
+
{
|
|
216
|
+
kind: "propertySegment",
|
|
217
|
+
name: "$mel",
|
|
218
|
+
location: markerLocation,
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
kind: "propertySegment",
|
|
222
|
+
name: "guards",
|
|
223
|
+
location: markerLocation,
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
kind: "propertySegment",
|
|
227
|
+
name: "intent",
|
|
228
|
+
location: markerLocation,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
kind: "propertySegment",
|
|
232
|
+
name: onceIntentGuardId,
|
|
233
|
+
location: markerLocation,
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
location: markerLocation,
|
|
237
|
+
};
|
|
238
|
+
let onceIntentCondition = {
|
|
239
|
+
kind: "call",
|
|
240
|
+
fn: "neq",
|
|
241
|
+
args: [
|
|
242
|
+
pathToMelExpr(onceIntentGuardPath),
|
|
243
|
+
{ kind: "sys", path: ["meta", "intentId"] },
|
|
244
|
+
],
|
|
245
|
+
};
|
|
246
|
+
if (stmt.condition) {
|
|
247
|
+
try {
|
|
248
|
+
onceIntentCondition = this.conditionComposer.and(onceIntentCondition, this.deps.toMelExpr(stmt.condition)) ?? onceIntentCondition;
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
errors.push({
|
|
252
|
+
severity: "error",
|
|
253
|
+
code: "E_LOWER",
|
|
254
|
+
message: error.message,
|
|
255
|
+
location: this.deps.mapLocation(stmt.condition.location),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const condition = this.conditionComposer.and(parentCondition, onceIntentCondition);
|
|
260
|
+
const onceIntentGuardMapPath = {
|
|
261
|
+
kind: "path",
|
|
262
|
+
segments: [
|
|
263
|
+
{
|
|
264
|
+
kind: "propertySegment",
|
|
265
|
+
name: "$mel",
|
|
266
|
+
location: markerLocation,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
kind: "propertySegment",
|
|
270
|
+
name: "guards",
|
|
271
|
+
location: markerLocation,
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
kind: "propertySegment",
|
|
275
|
+
name: "intent",
|
|
276
|
+
location: markerLocation,
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
location: markerLocation,
|
|
280
|
+
};
|
|
281
|
+
const scopedBodyPatchStatements = this.collectPatchStatements(stmt.body, errors, context, markerScopeExpr);
|
|
282
|
+
patchStatements.push({
|
|
283
|
+
patch: {
|
|
284
|
+
kind: "patch",
|
|
285
|
+
op: "set",
|
|
286
|
+
path: markerScopePath,
|
|
287
|
+
value: {
|
|
288
|
+
kind: "literal",
|
|
289
|
+
literalType: "boolean",
|
|
290
|
+
value: true,
|
|
291
|
+
location: markerLocation,
|
|
292
|
+
},
|
|
293
|
+
location: markerLocation,
|
|
294
|
+
},
|
|
295
|
+
condition,
|
|
296
|
+
}, {
|
|
297
|
+
patch: {
|
|
298
|
+
kind: "patch",
|
|
299
|
+
op: "merge",
|
|
300
|
+
path: onceIntentGuardMapPath,
|
|
301
|
+
value: {
|
|
302
|
+
kind: "objectLiteral",
|
|
303
|
+
properties: [
|
|
304
|
+
{
|
|
305
|
+
kind: "objectProperty",
|
|
306
|
+
key: onceIntentGuardId,
|
|
307
|
+
value: {
|
|
308
|
+
kind: "systemIdent",
|
|
309
|
+
path: ["meta", "intentId"],
|
|
310
|
+
location: markerLocation,
|
|
311
|
+
},
|
|
312
|
+
location: markerLocation,
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
location: markerLocation,
|
|
316
|
+
},
|
|
317
|
+
location: markerLocation,
|
|
318
|
+
},
|
|
319
|
+
condition: markerScopeExpr,
|
|
320
|
+
}, ...scopedBodyPatchStatements, {
|
|
321
|
+
patch: {
|
|
322
|
+
kind: "patch",
|
|
323
|
+
op: "unset",
|
|
324
|
+
path: markerScopePath,
|
|
325
|
+
location: markerLocation,
|
|
326
|
+
},
|
|
327
|
+
condition,
|
|
328
|
+
});
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
errors.push({
|
|
332
|
+
severity: "error",
|
|
333
|
+
code: "E_UNSUPPORTED_STMT",
|
|
334
|
+
message: `Unsupported statement '${stmt.kind}' in patch text. Only patch statements are allowed.`,
|
|
335
|
+
location: this.deps.mapLocation(stmt.location),
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return patchStatements;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
export function compilePatchStmtToMelRuntime(patchStatement) {
|
|
342
|
+
return {
|
|
343
|
+
op: patchStatement.patch.op,
|
|
344
|
+
path: toRuntimePatchPath(patchStatement.patch.path),
|
|
345
|
+
...(patchStatement.condition ? { condition: patchStatement.condition } : undefined),
|
|
346
|
+
...(patchStatement.patch.value
|
|
347
|
+
? { value: toMelExpr(patchStatement.patch.value) }
|
|
348
|
+
: undefined),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function pathToMelExpr(path) {
|
|
352
|
+
const segments = path.segments;
|
|
353
|
+
let result;
|
|
354
|
+
for (const segment of segments) {
|
|
355
|
+
if (segment.kind === "propertySegment") {
|
|
356
|
+
const prop = { kind: "prop", name: segment.name };
|
|
357
|
+
if (!result) {
|
|
358
|
+
result = { kind: "get", path: [prop] };
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
result = {
|
|
362
|
+
kind: "call",
|
|
363
|
+
fn: "field",
|
|
364
|
+
args: [result, { kind: "lit", value: segment.name }],
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (!result) {
|
|
370
|
+
throw new Error("Path cannot start with index access in compileMelPatch guard.");
|
|
371
|
+
}
|
|
372
|
+
result = {
|
|
373
|
+
kind: "call",
|
|
374
|
+
fn: "at",
|
|
375
|
+
args: [result, toMelExpr(segment.index)],
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
if (!result) {
|
|
379
|
+
throw new Error("Empty patch guard path.");
|
|
380
|
+
}
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
function toRuntimePatchPath(path) {
|
|
384
|
+
const parts = [];
|
|
385
|
+
for (const segment of path.segments) {
|
|
386
|
+
if (segment.kind === "propertySegment") {
|
|
387
|
+
parts.push(segment.name);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const literalValue = toPathSegmentLiteral(segment);
|
|
391
|
+
if (literalValue === null) {
|
|
392
|
+
throw new Error("Dynamic patch path indexes are not supported.");
|
|
393
|
+
}
|
|
394
|
+
parts.push(literalValue);
|
|
395
|
+
}
|
|
396
|
+
return joinPathPreserveEmptySegments(...parts);
|
|
397
|
+
}
|
|
398
|
+
function toPathSegmentLiteral(segment) {
|
|
399
|
+
if (segment.kind === "indexSegment" && segment.index.kind === "literal") {
|
|
400
|
+
return String(segment.index.value);
|
|
401
|
+
}
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
function joinPathPreserveEmptySegments(...segments) {
|
|
405
|
+
return segments.map((segment) => escapePathSegment(segment)).join(".");
|
|
406
|
+
}
|
|
407
|
+
function escapePathSegment(segment) {
|
|
408
|
+
return segment.replaceAll("\\", "\\\\").replaceAll(".", "\\.");
|
|
409
|
+
}
|
|
410
|
+
class ConditionComposer {
|
|
411
|
+
and(lhs, rhs) {
|
|
412
|
+
if (!lhs) {
|
|
413
|
+
return rhs;
|
|
414
|
+
}
|
|
415
|
+
if (!rhs) {
|
|
416
|
+
return lhs;
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
kind: "call",
|
|
420
|
+
fn: "and",
|
|
421
|
+
args: [lhs, rhs],
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
//# sourceMappingURL=compile-mel-patch-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-mel-patch-collector.js","sourceRoot":"","sources":["../../src/api/compile-mel-patch-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAUhD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAmBxD,MAAM,OAAO,uBAAuB;IAGL;IAFZ,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAE7D,YAA6B,IAAwB;QAAxB,SAAI,GAAJ,IAAI,CAAoB;IAAG,CAAC;IAEzD,OAAO,CACL,KAA0C,EAC1C,MAAoB,EACpB,OAA4B,EAC5B,eAAwC;QAExC,OAAO,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC;IAC9E,CAAC;IAEO,sBAAsB,CAC5B,KAA0C,EAC1C,MAAoB,EACpB,OAA4B,EAC5B,eAAwC;QAExC,MAAM,eAAe,GAAgC,EAAE,CAAC;QAExD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC1B,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CACjD,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
|
+
export declare function isSyntheticPatchCondition(condition: ExprNode): condition is (ExprNode & {
|
|
4
|
+
kind: "literal";
|
|
5
|
+
literalType: "boolean";
|
|
6
|
+
value: true;
|
|
7
|
+
});
|
|
8
|
+
export declare function toMelExpr(input: ExprNode): MelExprNode;
|
|
9
|
+
//# sourceMappingURL=compile-mel-patch-expr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-mel-patch-expr.d.ts","sourceRoot":"","sources":["../../src/api/compile-mel-patch-expr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,QAAQ,GAClB,SAAS,IAAI,CAAC,QAAQ,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAMpF;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,WAAW,CA8FtD"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
export function isSyntheticPatchCondition(condition) {
|
|
2
|
+
return (condition.kind === "literal" &&
|
|
3
|
+
condition.literalType === "boolean" &&
|
|
4
|
+
condition.value === true);
|
|
5
|
+
}
|
|
6
|
+
export function toMelExpr(input) {
|
|
7
|
+
switch (input.kind) {
|
|
8
|
+
case "literal":
|
|
9
|
+
return { kind: "lit", value: toMelPrimitive(input.value, input.literalType) };
|
|
10
|
+
case "identifier":
|
|
11
|
+
return {
|
|
12
|
+
kind: "get",
|
|
13
|
+
path: [{ kind: "prop", name: input.name }],
|
|
14
|
+
};
|
|
15
|
+
case "systemIdent":
|
|
16
|
+
return { kind: "sys", path: input.path };
|
|
17
|
+
case "iterationVar":
|
|
18
|
+
return { kind: "var", name: input.name };
|
|
19
|
+
case "propertyAccess": {
|
|
20
|
+
const path = collectStaticMelExpr(input);
|
|
21
|
+
if (path) {
|
|
22
|
+
return path;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
kind: "call",
|
|
26
|
+
fn: "field",
|
|
27
|
+
args: [toMelExpr(input.object), { kind: "lit", value: input.property }],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case "indexAccess": {
|
|
31
|
+
return {
|
|
32
|
+
kind: "call",
|
|
33
|
+
fn: "at",
|
|
34
|
+
args: [toMelExpr(input.object), toMelExpr(input.index)],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
case "functionCall":
|
|
38
|
+
return {
|
|
39
|
+
kind: "call",
|
|
40
|
+
fn: input.name,
|
|
41
|
+
args: input.args.map(toMelExpr),
|
|
42
|
+
};
|
|
43
|
+
case "unary":
|
|
44
|
+
if (input.operator === "!") {
|
|
45
|
+
return {
|
|
46
|
+
kind: "call",
|
|
47
|
+
fn: "not",
|
|
48
|
+
args: [toMelExpr(input.operand)],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
kind: "call",
|
|
53
|
+
fn: "sub",
|
|
54
|
+
args: [{ kind: "lit", value: 0 }, toMelExpr(input.operand)],
|
|
55
|
+
};
|
|
56
|
+
case "binary":
|
|
57
|
+
return {
|
|
58
|
+
kind: "call",
|
|
59
|
+
fn: toMelBinaryOp(input.operator),
|
|
60
|
+
args: [toMelExpr(input.left), toMelExpr(input.right)],
|
|
61
|
+
};
|
|
62
|
+
case "ternary":
|
|
63
|
+
return {
|
|
64
|
+
kind: "call",
|
|
65
|
+
fn: "if",
|
|
66
|
+
args: [
|
|
67
|
+
toMelExpr(input.condition),
|
|
68
|
+
toMelExpr(input.consequent),
|
|
69
|
+
toMelExpr(input.alternate),
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
case "objectLiteral":
|
|
73
|
+
return {
|
|
74
|
+
kind: "obj",
|
|
75
|
+
fields: input.properties.map((property) => ({
|
|
76
|
+
key: property.key,
|
|
77
|
+
value: toMelExpr(property.value),
|
|
78
|
+
})),
|
|
79
|
+
};
|
|
80
|
+
case "arrayLiteral":
|
|
81
|
+
return {
|
|
82
|
+
kind: "arr",
|
|
83
|
+
elements: input.elements.map(toMelExpr),
|
|
84
|
+
};
|
|
85
|
+
default:
|
|
86
|
+
throw new Error(`Unsupported expression kind '${input.kind}'`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function toMelPrimitive(value, literalType) {
|
|
90
|
+
if (literalType === "null") {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (literalType === "number") {
|
|
94
|
+
if (typeof value === "number") {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "bigint") {
|
|
98
|
+
return Number(value);
|
|
99
|
+
}
|
|
100
|
+
if (typeof value === "string" && value.length > 0) {
|
|
101
|
+
const parsed = Number(value);
|
|
102
|
+
if (!Number.isNaN(parsed)) {
|
|
103
|
+
return parsed;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw new Error("Invalid number literal");
|
|
107
|
+
}
|
|
108
|
+
if (literalType === "string") {
|
|
109
|
+
if (typeof value === "string") {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
throw new Error("Invalid string literal");
|
|
113
|
+
}
|
|
114
|
+
if (literalType === "boolean") {
|
|
115
|
+
if (typeof value === "boolean") {
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
throw new Error("Invalid boolean literal");
|
|
119
|
+
}
|
|
120
|
+
throw new Error("Unsupported literal type");
|
|
121
|
+
}
|
|
122
|
+
function collectStaticMelExpr(expr) {
|
|
123
|
+
if (expr.kind === "identifier") {
|
|
124
|
+
return { kind: "get", path: [{ kind: "prop", name: expr.name }] };
|
|
125
|
+
}
|
|
126
|
+
if (expr.kind === "iterationVar") {
|
|
127
|
+
if (expr.name !== "item") {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return { kind: "var", name: "item" };
|
|
131
|
+
}
|
|
132
|
+
if (expr.kind === "propertyAccess") {
|
|
133
|
+
const basePath = collectStaticMelExpr(expr.object);
|
|
134
|
+
if (!basePath) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
kind: "call",
|
|
139
|
+
fn: "field",
|
|
140
|
+
args: [basePath, { kind: "lit", value: expr.property }],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
function toMelBinaryOp(op) {
|
|
146
|
+
switch (op) {
|
|
147
|
+
case "+":
|
|
148
|
+
return "add";
|
|
149
|
+
case "-":
|
|
150
|
+
return "sub";
|
|
151
|
+
case "*":
|
|
152
|
+
return "mul";
|
|
153
|
+
case "/":
|
|
154
|
+
return "div";
|
|
155
|
+
case "%":
|
|
156
|
+
return "mod";
|
|
157
|
+
case "==":
|
|
158
|
+
return "eq";
|
|
159
|
+
case "!=":
|
|
160
|
+
return "neq";
|
|
161
|
+
case "<":
|
|
162
|
+
return "lt";
|
|
163
|
+
case "<=":
|
|
164
|
+
return "lte";
|
|
165
|
+
case ">":
|
|
166
|
+
return "gt";
|
|
167
|
+
case ">=":
|
|
168
|
+
return "gte";
|
|
169
|
+
case "&&":
|
|
170
|
+
return "and";
|
|
171
|
+
case "||":
|
|
172
|
+
return "or";
|
|
173
|
+
case "??":
|
|
174
|
+
return "coalesce";
|
|
175
|
+
default:
|
|
176
|
+
throw new Error(`Unsupported binary operator '${op}'`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=compile-mel-patch-expr.js.map
|