@torpor/view 1.2.5 → 1.3.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.
Files changed (44) hide show
  1. package/dist/{AsyncOptions-ClS1_ERX.d.mts → AsyncOptions-BDtArmeL.d.mts} +2 -8
  2. package/dist/AsyncOptions-BDtArmeL.d.mts.map +1 -0
  3. package/dist/{AsyncOptions-BtMe2PAd.d.cts → AsyncOptions-C_7mWR6F.d.cts} +2 -8
  4. package/dist/AsyncOptions-C_7mWR6F.d.cts.map +1 -0
  5. package/dist/{Effect-DazmAdyC.d.mts → Effect-99HYQdzZ.d.mts} +50 -33
  6. package/dist/Effect-99HYQdzZ.d.mts.map +1 -0
  7. package/dist/{Effect-Dewn7MLc.d.cts → Effect-Bf8fz_zC.d.cts} +50 -33
  8. package/dist/Effect-Bf8fz_zC.d.cts.map +1 -0
  9. package/dist/compile.cjs +1509 -120
  10. package/dist/compile.d.cts +268 -1
  11. package/dist/compile.d.cts.map +1 -1
  12. package/dist/compile.d.mts +268 -1
  13. package/dist/compile.d.mts.map +1 -1
  14. package/dist/compile.mjs +1506 -121
  15. package/dist/compile.mjs.map +1 -1
  16. package/dist/dev.d.cts +1 -1
  17. package/dist/dev.d.mts +1 -1
  18. package/dist/{fromWebSocket-DrN-IduP.cjs → fromWebSocket-Cdoghvmh.cjs} +15 -0
  19. package/dist/{fromWebSocket-CFGoMkV2.mjs → fromWebSocket-ERhd9KZR.mjs} +11 -2
  20. package/dist/fromWebSocket-ERhd9KZR.mjs.map +1 -0
  21. package/dist/index.cjs +223 -158
  22. package/dist/index.d.cts +24 -8
  23. package/dist/index.d.cts.map +1 -1
  24. package/dist/index.d.mts +24 -8
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +223 -158
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/runtime.iife.js +1 -0
  29. package/dist/slotAutoClose-BbKfzpkz.cjs +177 -0
  30. package/dist/slotAutoClose-CgDkf8fM.mjs +156 -0
  31. package/dist/slotAutoClose-CgDkf8fM.mjs.map +1 -0
  32. package/dist/ssr.cjs +57 -3
  33. package/dist/ssr.d.cts +53 -2
  34. package/dist/ssr.d.cts.map +1 -1
  35. package/dist/ssr.d.mts +53 -2
  36. package/dist/ssr.d.mts.map +1 -1
  37. package/dist/ssr.mjs +51 -2
  38. package/dist/ssr.mjs.map +1 -1
  39. package/package.json +8 -5
  40. package/dist/AsyncOptions-BtMe2PAd.d.cts.map +0 -1
  41. package/dist/AsyncOptions-ClS1_ERX.d.mts.map +0 -1
  42. package/dist/Effect-DazmAdyC.d.mts.map +0 -1
  43. package/dist/Effect-Dewn7MLc.d.cts.map +0 -1
  44. package/dist/fromWebSocket-CFGoMkV2.mjs.map +0 -1
@@ -216,6 +216,12 @@ interface BuildResult {
216
216
  }[];
217
217
  map: SourceMapping[];
218
218
  errors: CompileError[];
219
+ /**
220
+ * Non-fatal diagnostics — things that compile and run, but are very
221
+ * likely a mistake (e.g. a plain `let` initialized from `$props` that a
222
+ * template expression reads: silent stale capture in keyed lists).
223
+ */
224
+ warnings: CompileError[];
219
225
  }
220
226
  //#endregion
221
227
  //#region src/compile/build.d.ts
@@ -228,6 +234,211 @@ interface BuildResult {
228
234
  */
229
235
  declare function build(template: Template, options?: BuildOptions): BuildResult;
230
236
  //#endregion
237
+ //#region src/compile/build/restricted/types.d.ts
238
+ /**
239
+ * The restricted-mode instruction format.
240
+ *
241
+ * A restricted artifact's *server* build is a serialized program made of
242
+ * these values: elements, text, control flow, attributes and expressions.
243
+ * It is interpreted by trusted code (see `renderRestricted` in
244
+ * `@torpor/embed`), so nothing here can execute author JavaScript. The
245
+ * expression op set below is deliberately small and is the permanent
246
+ * format API: additions are format decisions, not implementation details.
247
+ */
248
+ /** A JSON-safe literal value. `undefined` is serialized as `null`. */
249
+ type RestrictedLiteral = string | number | boolean | null;
250
+ type RestrictedBinaryOperator = "??" | "||" | "&&" | "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "+" | "-" | "*" | "/" | "%";
251
+ type RestrictedUnaryOperator = "!" | "-" | "+" | "typeof";
252
+ /**
253
+ * A serialized expression over props, data and loop variables.
254
+ *
255
+ * There are deliberately **no calls**: template expressions are a pure
256
+ * presentation layer (reads, literals, operators). Formatting and other
257
+ * computation belongs in the data layer (`derive` requirements), where host
258
+ * functions can run with budgets and the results are shipped to the client
259
+ * with the paint -- so server and client can never disagree about a value.
260
+ * Interpreters must never `eval` any part of this.
261
+ */
262
+ type RestrictedExpr = {
263
+ op: "lit";
264
+ value: RestrictedLiteral;
265
+ } | {
266
+ op: "ref";
267
+ name: string;
268
+ } | {
269
+ op: "get";
270
+ object: RestrictedExpr;
271
+ key: string;
272
+ optional?: boolean;
273
+ } | {
274
+ op: "index";
275
+ object: RestrictedExpr;
276
+ index: RestrictedExpr;
277
+ optional?: boolean;
278
+ } | {
279
+ op: "call";
280
+ name: string;
281
+ args: RestrictedExpr[];
282
+ } | {
283
+ op: "unary";
284
+ operator: RestrictedUnaryOperator;
285
+ operand: RestrictedExpr;
286
+ } | {
287
+ op: "binary";
288
+ operator: RestrictedBinaryOperator;
289
+ left: RestrictedExpr;
290
+ right: RestrictedExpr;
291
+ } | {
292
+ op: "ternary";
293
+ test: RestrictedExpr;
294
+ consequent: RestrictedExpr;
295
+ alternate: RestrictedExpr;
296
+ } | {
297
+ op: "array";
298
+ items: RestrictedExpr[];
299
+ } | {
300
+ op: "object";
301
+ entries: Record<string, RestrictedExpr>;
302
+ };
303
+ /**
304
+ * A static attribute: `name`, optionally with a literal value. A missing
305
+ * value is a boolean attribute (`disabled`).
306
+ */
307
+ interface RestrictedStaticAttribute {
308
+ name: string;
309
+ value?: string;
310
+ /**
311
+ * On component `class` props: the component's style-hash class. The
312
+ * interpreter passes the prop as `[value, scoped]`, matching the JS
313
+ * server build.
314
+ */
315
+ scoped?: string;
316
+ }
317
+ /**
318
+ * A dynamic attribute: the value is an expression evaluated at render time.
319
+ *
320
+ * - `format: "attr"` — set only when truthy, HTML-escaped (matches the JS
321
+ * server build's conditional attribute behavior).
322
+ * - `format: "class"` — class value semantics (arrays/objects); `scoped` is
323
+ * the component's style-hash class to append.
324
+ * - `format: "style"` — style value semantics (objects/arrays).
325
+ *
326
+ * On **component props**, `scoped` has the same meaning but the interpreter
327
+ * passes the prop as `[value, scoped]` (an array), matching the JS builds'
328
+ * scoped class prop contract.
329
+ */
330
+ interface RestrictedDynamicAttribute {
331
+ name: string;
332
+ expr: RestrictedExpr;
333
+ format: "attr" | "class" | "style";
334
+ scoped?: string;
335
+ }
336
+ type RestrictedAttribute = RestrictedStaticAttribute | RestrictedDynamicAttribute;
337
+ type RestrictedNode = {
338
+ t: "el";
339
+ tag: string;
340
+ attrs: RestrictedAttribute[];
341
+ children: RestrictedNode[];
342
+ } | {
343
+ t: "text";
344
+ parts: (string | RestrictedExpr)[];
345
+ } | {
346
+ t: "if";
347
+ branches: {
348
+ test?: RestrictedExpr;
349
+ children: RestrictedNode[];
350
+ }[];
351
+ } | {
352
+ t: "for";
353
+ item: string;
354
+ list: RestrictedExpr;
355
+ /** `@key` expression, when present */
356
+ key?: RestrictedExpr;
357
+ children: RestrictedNode[];
358
+ } | {
359
+ t: "component";
360
+ name: string;
361
+ props: RestrictedAttribute[];
362
+ fills: RestrictedFill[];
363
+ } | {
364
+ t: "slot";
365
+ name: string;
366
+ props: RestrictedAttribute[];
367
+ children: RestrictedNode[];
368
+ autoClose?: string[];
369
+ };
370
+ interface RestrictedFill {
371
+ /** Slot name; "_" is the default fill. */
372
+ name: string;
373
+ children: RestrictedNode[];
374
+ }
375
+ /** A resolved data declaration: kind + inert spec expressions. */
376
+ interface RestrictedRequirement {
377
+ /** The name the template reads as `$data.<name>`. */
378
+ name: string;
379
+ /** The source kind (`http`, a host-registered kind, …). */
380
+ kind: string;
381
+ spec: Record<string, RestrictedExpr>;
382
+ }
383
+ interface RestrictedComponent {
384
+ name?: string;
385
+ default?: boolean;
386
+ markup: RestrictedNode[];
387
+ /**
388
+ * Client state declarations extracted from the component's script:
389
+ * `let $state = $watch(<init>)` where `<init>` is a restricted
390
+ * expression over `$props`. SSR evaluates the initializers for the
391
+ * initial paint; the client build binds the real `$watch` state.
392
+ */
393
+ state?: RestrictedStateInit[];
394
+ }
395
+ interface RestrictedStateInit {
396
+ name: string;
397
+ init: RestrictedExpr;
398
+ }
399
+ interface RestrictedProgram {
400
+ /** File-level requirements, resolved by the host before interpreting. */
401
+ requirements: RestrictedRequirement[];
402
+ components: RestrictedComponent[];
403
+ }
404
+ interface RestrictedBuildResult {
405
+ program: RestrictedProgram;
406
+ styles: {
407
+ style: string;
408
+ hash: string;
409
+ }[];
410
+ errors: CompileError[];
411
+ }
412
+ interface RestrictedRequirementKindContext {
413
+ /** The name this requirement binds. */
414
+ name: string;
415
+ /** Names of requirements declared *before* this one (dependency order). */
416
+ names: string[];
417
+ }
418
+ interface RestrictedSpecEntry {
419
+ key: string;
420
+ expr: RestrictedExpr;
421
+ /** Absolute source indices, for kind validators to report against. */
422
+ keyStart: number;
423
+ valueStart: number;
424
+ valueEnd: number;
425
+ }
426
+ type RestrictedRequirementKindValidator = (spec: RestrictedSpecEntry[], report: (message: string, start: number, end: number) => void, context?: RestrictedRequirementKindContext) => void;
427
+ //#endregion
428
+ //#region src/compile/build/restricted/buildRestricted.d.ts
429
+ interface RestrictedBuildOptions extends BuildOptions {}
430
+ /**
431
+ * Builds a template into a serialized restricted program: the server-side
432
+ * instruction tree interpreted by `renderRestricted` (no `eval`, so it is
433
+ * legal on workerd).
434
+ *
435
+ * Must be called on a **freshly parsed** template: it maps text
436
+ * interpolations through the parse-time source spans. Trimming whitespace
437
+ * nodes here is safe (only whitespace-only nodes change), and matches the
438
+ * JS build; `build()` calling `trimWhitespace` again is idempotent.
439
+ */
440
+ declare function buildRestricted(template: Template, options?: RestrictedBuildOptions): RestrictedBuildResult;
441
+ //#endregion
231
442
  //#region src/compile/buildType.d.ts
232
443
  /**
233
444
  * Builds a component template into a d.ts file
@@ -257,5 +468,61 @@ interface ParseResult {
257
468
  */
258
469
  declare function parse(source: string): ParseResult;
259
470
  //#endregion
260
- export { type Component, type Template, build, buildType, parse };
471
+ //#region src/compile/parse/bindDataTemplate.d.ts
472
+ /**
473
+ * Binds `$data` in a parsed template whose requirements come from an app
474
+ * manifest (see `@torpor/embed/app`): inserts the `let $data = …` chunk
475
+ * after the start-marker chunk and keeps `$props` from being renamed as an
476
+ * unused param. Without it, builds reference an undeclared `$data`.
477
+ */
478
+ declare function bindDataTemplate(template: Template): void;
479
+ //#endregion
480
+ //#region src/compile/build/restricted/parseExpression.d.ts
481
+ /**
482
+ * Parses a restricted template expression into the serialized op set.
483
+ *
484
+ * This is intentionally a small, hand-written parser rather than a general
485
+ * JS parser: the grammar *is* the restricted op set (the permanent format
486
+ * API), so anything outside it is rejected with a positioned error instead
487
+ * of being parsed and then policed. Regex-based tokenizing was rejected --
488
+ * operators inside string literals and operator precedence make it
489
+ * unsound.
490
+ *
491
+ * Supported: literals, identifiers (props/data/loop variables), property
492
+ * and index access, unary `! - + typeof`, arithmetic/comparison/logic
493
+ * (`* / %`, `+ -`, `< <= > >=`, `== != === !==`, `&&`, `||`, `??`),
494
+ * ternaries, and array/object literals.
495
+ *
496
+ * Deliberately not supported (each gets a targeted error): calls (format
497
+ * in `derive` instead), authored functions/arrows, `new`, `await`,
498
+ * assignments and updates, optional chaining, template literals, spread.
499
+ */
500
+ export declare class RestrictedSyntaxError extends Error {
501
+ /** Absolute index (including the parser's offset) where the error starts. */
502
+ start: number;
503
+ /** Absolute index where the error ends. */
504
+ end: number;
505
+ constructor(message: string, start: number, end: number);
506
+ }
507
+ interface ParsedExpressionPrefix {
508
+ expression: RestrictedExpr;
509
+ /** Absolute source index where the expression ends (the next token). */
510
+ end: number;
511
+ }
512
+ interface ParseExpressionOptions {
513
+ /**
514
+ * Allow calls to named host functions (`format($item.due)`). Data-layer
515
+ * specs (requirement values, derive expressions) allow them; template
516
+ * expressions do not, so rendering stays pure.
517
+ */
518
+ allowCalls?: boolean;
519
+ }
520
+ /**
521
+ * Parses an expression that is followed by more text (e.g. a requirement
522
+ * spec's `,` or the end of the spec). Returns where the expression ended so
523
+ * callers can continue scanning.
524
+ */
525
+ export declare function parseExpressionPrefix(source: string, offset?: number, options?: ParseExpressionOptions): ParsedExpressionPrefix;
526
+ //#endregion
527
+ export { type CompileError, type Component, type RestrictedAttribute, type RestrictedBuildOptions, type RestrictedBuildResult, type RestrictedComponent, type RestrictedDynamicAttribute, type RestrictedExpr, type RestrictedNode, type RestrictedProgram, type RestrictedRequirement, type RestrictedRequirementKindValidator, type RestrictedSpecEntry, type RestrictedStaticAttribute, type Template, bindDataTemplate, build, buildRestricted, buildType, parse };
261
528
  //# sourceMappingURL=compile.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.cts","names":[],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAAU;EACV;;;;UCFwB;EACxB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA,SAAS;;EAET,QAAQ;;EAER;EACA,OAAO;EACP,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UC1BwB;EACxB,SAAS;EACT,QAAQ;EACR,YAAY;;;;UCVY;;;;EAIxB;;;;EAIA;;;;EAIA;;;;;;;EAOA;;;;EAIA;;;;;;;;EAQA;;;;;;EAMA;;;;UCrCwB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA,QAAQ;EACR,UAAU;;;;UCFc;EACxB;EACA;IACC;IACA;;EAED,KAAK;EACL,QAAQ;;;;;;;;;;;iBCOe,MAAM,UAAU,UAAU,UAAU,eAAe;;;;;;;;;;;iBCLnD,UAAU,UAAU,UAAU,UAAU;;;UCTvC;EACxB;EACA,QAAQ;EACR,WAAW;;;;;;;;;;;;iBCKY,MAAM,iBAAiB"}
1
+ {"version":3,"file":"compile.d.cts","names":["_$______types_CompileError0.default"],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/build/restricted/types.ts","../src/compile/build/restricted/buildRestricted.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts","../src/compile/parse/bindDataTemplate.ts","../src/compile/build/restricted/parseExpression.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAAU;EACV;;;;UCFwB;EACxB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA,SAAS;;EAET,QAAQ;;EAER;EACA,OAAO;EACP,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UC1BwB;EACxB,SAAS;EACT,QAAQ;EACR,YAAY;;;;UCVY;;;;EAIxB;;;;EAIA;;;;EAIA;;;;;;;EAOA;;;;EAIA;;;;;;;;EAQA;;;;;;EAMA;;;;UCrCwB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA,QAAQ;EACR,UAAU;;;;UCFc;EACxB;EACA;IACC;IACA;;EAED,KAAK;EACL,QAAQ;;;;;;EAMR,UAAU;;;;;;;;;;;iBCCa,MAAM,UAAU,UAAU,UAAU,eAAe;;;;;;;;;;;;;;KCL/D;KACA;KAkBA;;;;;;;;;;;KAYA;EACP;EAAW,OAAO;;EAClB;EAAW;;EACX;EAAW,QAAQ;EAAgB;EAAa;;EAChD;EAAa,QAAQ;EAAgB,OAAO;EAAgB;;EAK5D;EAAY;EAAc,MAAM;;EAChC;EAAa,UAAU;EAAyB,SAAS;;EAE3D;EACA,UAAU;EACV,MAAM;EACN,OAAO;;EAEL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Mapping[];
218
218
  errors: CompileError[];
219
+ /**
220
+ * Non-fatal diagnostics — things that compile and run, but are very
221
+ * likely a mistake (e.g. a plain `let` initialized from `$props` that a
222
+ * template expression reads: silent stale capture in keyed lists).
223
+ */
224
+ warnings: CompileError[];
219
225
  }
220
226
  //#endregion
221
227
  //#region src/compile/build.d.ts
@@ -228,6 +234,211 @@ interface BuildResult {
228
234
  */
229
235
  declare function build(template: Template, options?: BuildOptions): BuildResult;
230
236
  //#endregion
237
+ //#region src/compile/build/restricted/types.d.ts
238
+ /**
239
+ * The restricted-mode instruction format.
240
+ *
241
+ * A restricted artifact's *server* build is a serialized program made of
242
+ * these values: elements, text, control flow, attributes and expressions.
243
+ * It is interpreted by trusted code (see `renderRestricted` in
244
+ * `@torpor/embed`), so nothing here can execute author JavaScript. The
245
+ * expression op set below is deliberately small and is the permanent
246
+ * format API: additions are format decisions, not implementation details.
247
+ */
248
+ /** A JSON-safe literal value. `undefined` is serialized as `null`. */
249
+ type RestrictedLiteral = string | number | boolean | null;
250
+ type RestrictedBinaryOperator = "??" | "||" | "&&" | "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "+" | "-" | "*" | "/" | "%";
251
+ type RestrictedUnaryOperator = "!" | "-" | "+" | "typeof";
252
+ /**
253
+ * A serialized expression over props, data and loop variables.
254
+ *
255
+ * There are deliberately **no calls**: template expressions are a pure
256
+ * presentation layer (reads, literals, operators). Formatting and other
257
+ * computation belongs in the data layer (`derive` requirements), where host
258
+ * functions can run with budgets and the results are shipped to the client
259
+ * with the paint -- so server and client can never disagree about a value.
260
+ * Interpreters must never `eval` any part of this.
261
+ */
262
+ type RestrictedExpr = {
263
+ op: "lit";
264
+ value: RestrictedLiteral;
265
+ } | {
266
+ op: "ref";
267
+ name: string;
268
+ } | {
269
+ op: "get";
270
+ object: RestrictedExpr;
271
+ key: string;
272
+ optional?: boolean;
273
+ } | {
274
+ op: "index";
275
+ object: RestrictedExpr;
276
+ index: RestrictedExpr;
277
+ optional?: boolean;
278
+ } | {
279
+ op: "call";
280
+ name: string;
281
+ args: RestrictedExpr[];
282
+ } | {
283
+ op: "unary";
284
+ operator: RestrictedUnaryOperator;
285
+ operand: RestrictedExpr;
286
+ } | {
287
+ op: "binary";
288
+ operator: RestrictedBinaryOperator;
289
+ left: RestrictedExpr;
290
+ right: RestrictedExpr;
291
+ } | {
292
+ op: "ternary";
293
+ test: RestrictedExpr;
294
+ consequent: RestrictedExpr;
295
+ alternate: RestrictedExpr;
296
+ } | {
297
+ op: "array";
298
+ items: RestrictedExpr[];
299
+ } | {
300
+ op: "object";
301
+ entries: Record<string, RestrictedExpr>;
302
+ };
303
+ /**
304
+ * A static attribute: `name`, optionally with a literal value. A missing
305
+ * value is a boolean attribute (`disabled`).
306
+ */
307
+ interface RestrictedStaticAttribute {
308
+ name: string;
309
+ value?: string;
310
+ /**
311
+ * On component `class` props: the component's style-hash class. The
312
+ * interpreter passes the prop as `[value, scoped]`, matching the JS
313
+ * server build.
314
+ */
315
+ scoped?: string;
316
+ }
317
+ /**
318
+ * A dynamic attribute: the value is an expression evaluated at render time.
319
+ *
320
+ * - `format: "attr"` — set only when truthy, HTML-escaped (matches the JS
321
+ * server build's conditional attribute behavior).
322
+ * - `format: "class"` — class value semantics (arrays/objects); `scoped` is
323
+ * the component's style-hash class to append.
324
+ * - `format: "style"` — style value semantics (objects/arrays).
325
+ *
326
+ * On **component props**, `scoped` has the same meaning but the interpreter
327
+ * passes the prop as `[value, scoped]` (an array), matching the JS builds'
328
+ * scoped class prop contract.
329
+ */
330
+ interface RestrictedDynamicAttribute {
331
+ name: string;
332
+ expr: RestrictedExpr;
333
+ format: "attr" | "class" | "style";
334
+ scoped?: string;
335
+ }
336
+ type RestrictedAttribute = RestrictedStaticAttribute | RestrictedDynamicAttribute;
337
+ type RestrictedNode = {
338
+ t: "el";
339
+ tag: string;
340
+ attrs: RestrictedAttribute[];
341
+ children: RestrictedNode[];
342
+ } | {
343
+ t: "text";
344
+ parts: (string | RestrictedExpr)[];
345
+ } | {
346
+ t: "if";
347
+ branches: {
348
+ test?: RestrictedExpr;
349
+ children: RestrictedNode[];
350
+ }[];
351
+ } | {
352
+ t: "for";
353
+ item: string;
354
+ list: RestrictedExpr;
355
+ /** `@key` expression, when present */
356
+ key?: RestrictedExpr;
357
+ children: RestrictedNode[];
358
+ } | {
359
+ t: "component";
360
+ name: string;
361
+ props: RestrictedAttribute[];
362
+ fills: RestrictedFill[];
363
+ } | {
364
+ t: "slot";
365
+ name: string;
366
+ props: RestrictedAttribute[];
367
+ children: RestrictedNode[];
368
+ autoClose?: string[];
369
+ };
370
+ interface RestrictedFill {
371
+ /** Slot name; "_" is the default fill. */
372
+ name: string;
373
+ children: RestrictedNode[];
374
+ }
375
+ /** A resolved data declaration: kind + inert spec expressions. */
376
+ interface RestrictedRequirement {
377
+ /** The name the template reads as `$data.<name>`. */
378
+ name: string;
379
+ /** The source kind (`http`, a host-registered kind, …). */
380
+ kind: string;
381
+ spec: Record<string, RestrictedExpr>;
382
+ }
383
+ interface RestrictedComponent {
384
+ name?: string;
385
+ default?: boolean;
386
+ markup: RestrictedNode[];
387
+ /**
388
+ * Client state declarations extracted from the component's script:
389
+ * `let $state = $watch(<init>)` where `<init>` is a restricted
390
+ * expression over `$props`. SSR evaluates the initializers for the
391
+ * initial paint; the client build binds the real `$watch` state.
392
+ */
393
+ state?: RestrictedStateInit[];
394
+ }
395
+ interface RestrictedStateInit {
396
+ name: string;
397
+ init: RestrictedExpr;
398
+ }
399
+ interface RestrictedProgram {
400
+ /** File-level requirements, resolved by the host before interpreting. */
401
+ requirements: RestrictedRequirement[];
402
+ components: RestrictedComponent[];
403
+ }
404
+ interface RestrictedBuildResult {
405
+ program: RestrictedProgram;
406
+ styles: {
407
+ style: string;
408
+ hash: string;
409
+ }[];
410
+ errors: CompileError[];
411
+ }
412
+ interface RestrictedRequirementKindContext {
413
+ /** The name this requirement binds. */
414
+ name: string;
415
+ /** Names of requirements declared *before* this one (dependency order). */
416
+ names: string[];
417
+ }
418
+ interface RestrictedSpecEntry {
419
+ key: string;
420
+ expr: RestrictedExpr;
421
+ /** Absolute source indices, for kind validators to report against. */
422
+ keyStart: number;
423
+ valueStart: number;
424
+ valueEnd: number;
425
+ }
426
+ type RestrictedRequirementKindValidator = (spec: RestrictedSpecEntry[], report: (message: string, start: number, end: number) => void, context?: RestrictedRequirementKindContext) => void;
427
+ //#endregion
428
+ //#region src/compile/build/restricted/buildRestricted.d.ts
429
+ interface RestrictedBuildOptions extends BuildOptions {}
430
+ /**
431
+ * Builds a template into a serialized restricted program: the server-side
432
+ * instruction tree interpreted by `renderRestricted` (no `eval`, so it is
433
+ * legal on workerd).
434
+ *
435
+ * Must be called on a **freshly parsed** template: it maps text
436
+ * interpolations through the parse-time source spans. Trimming whitespace
437
+ * nodes here is safe (only whitespace-only nodes change), and matches the
438
+ * JS build; `build()` calling `trimWhitespace` again is idempotent.
439
+ */
440
+ declare function buildRestricted(template: Template, options?: RestrictedBuildOptions): RestrictedBuildResult;
441
+ //#endregion
231
442
  //#region src/compile/buildType.d.ts
232
443
  /**
233
444
  * Builds a component template into a d.ts file
@@ -257,5 +468,61 @@ interface ParseResult {
257
468
  */
258
469
  declare function parse(source: string): ParseResult;
259
470
  //#endregion
260
- export { type Component, type Template, build, buildType, parse };
471
+ //#region src/compile/parse/bindDataTemplate.d.ts
472
+ /**
473
+ * Binds `$data` in a parsed template whose requirements come from an app
474
+ * manifest (see `@torpor/embed/app`): inserts the `let $data = …` chunk
475
+ * after the start-marker chunk and keeps `$props` from being renamed as an
476
+ * unused param. Without it, builds reference an undeclared `$data`.
477
+ */
478
+ declare function bindDataTemplate(template: Template): void;
479
+ //#endregion
480
+ //#region src/compile/build/restricted/parseExpression.d.ts
481
+ /**
482
+ * Parses a restricted template expression into the serialized op set.
483
+ *
484
+ * This is intentionally a small, hand-written parser rather than a general
485
+ * JS parser: the grammar *is* the restricted op set (the permanent format
486
+ * API), so anything outside it is rejected with a positioned error instead
487
+ * of being parsed and then policed. Regex-based tokenizing was rejected --
488
+ * operators inside string literals and operator precedence make it
489
+ * unsound.
490
+ *
491
+ * Supported: literals, identifiers (props/data/loop variables), property
492
+ * and index access, unary `! - + typeof`, arithmetic/comparison/logic
493
+ * (`* / %`, `+ -`, `< <= > >=`, `== != === !==`, `&&`, `||`, `??`),
494
+ * ternaries, and array/object literals.
495
+ *
496
+ * Deliberately not supported (each gets a targeted error): calls (format
497
+ * in `derive` instead), authored functions/arrows, `new`, `await`,
498
+ * assignments and updates, optional chaining, template literals, spread.
499
+ */
500
+ export declare class RestrictedSyntaxError extends Error {
501
+ /** Absolute index (including the parser's offset) where the error starts. */
502
+ start: number;
503
+ /** Absolute index where the error ends. */
504
+ end: number;
505
+ constructor(message: string, start: number, end: number);
506
+ }
507
+ interface ParsedExpressionPrefix {
508
+ expression: RestrictedExpr;
509
+ /** Absolute source index where the expression ends (the next token). */
510
+ end: number;
511
+ }
512
+ interface ParseExpressionOptions {
513
+ /**
514
+ * Allow calls to named host functions (`format($item.due)`). Data-layer
515
+ * specs (requirement values, derive expressions) allow them; template
516
+ * expressions do not, so rendering stays pure.
517
+ */
518
+ allowCalls?: boolean;
519
+ }
520
+ /**
521
+ * Parses an expression that is followed by more text (e.g. a requirement
522
+ * spec's `,` or the end of the spec). Returns where the expression ended so
523
+ * callers can continue scanning.
524
+ */
525
+ export declare function parseExpressionPrefix(source: string, offset?: number, options?: ParseExpressionOptions): ParsedExpressionPrefix;
526
+ //#endregion
527
+ export { type CompileError, type Component, type RestrictedAttribute, type RestrictedBuildOptions, type RestrictedBuildResult, type RestrictedComponent, type RestrictedDynamicAttribute, type RestrictedExpr, type RestrictedNode, type RestrictedProgram, type RestrictedRequirement, type RestrictedRequirementKindValidator, type RestrictedSpecEntry, type RestrictedStaticAttribute, type Template, bindDataTemplate, build, buildRestricted, buildType, parse };
261
528
  //# sourceMappingURL=compile.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.mts","names":[],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAAU;EACV;;;;UCFwB;EACxB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA,SAAS;;EAET,QAAQ;;EAER;EACA,OAAO;EACP,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UC1BwB;EACxB,SAAS;EACT,QAAQ;EACR,YAAY;;;;UCVY;;;;EAIxB;;;;EAIA;;;;EAIA;;;;;;;EAOA;;;;EAIA;;;;;;;;EAQA;;;;;;EAMA;;;;UCrCwB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA,QAAQ;EACR,UAAU;;;;UCFc;EACxB;EACA;IACC;IACA;;EAED,KAAK;EACL,QAAQ;;;;;;;;;;;iBCOe,MAAM,UAAU,UAAU,UAAU,eAAe;;;;;;;;;;;iBCLnD,UAAU,UAAU,UAAU,UAAU;;;UCTvC;EACxB;EACA,QAAQ;EACR,WAAW;;;;;;;;;;;;iBCKY,MAAM,iBAAiB"}
1
+ {"version":3,"file":"compile.d.mts","names":["_$______types_CompileError0.default"],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/build/restricted/types.ts","../src/compile/build/restricted/buildRestricted.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts","../src/compile/parse/bindDataTemplate.ts","../src/compile/build/restricted/parseExpression.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAAU;EACV;;;;UCFwB;EACxB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;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