marko 6.0.0-next.3.26 → 6.0.0-next.3.28

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.
@@ -35,6 +35,7 @@ __export(html_exports, {
35
35
  controllable_textarea_value: () => controllable_textarea_value,
36
36
  createRenderer: () => createRenderer,
37
37
  createTemplate: () => createTemplate,
38
+ debug: () => debug,
38
39
  dynamicTagArgs: () => dynamicTagArgs,
39
40
  dynamicTagInput: () => dynamicTagInput,
40
41
  ensureScopeWithId: () => ensureScopeWithId,
@@ -582,6 +583,17 @@ var Reference = class {
582
583
  init = "";
583
584
  assigns = "";
584
585
  };
586
+ var DEBUG = /* @__PURE__ */ new WeakMap();
587
+ function debug(obj, file, loc, vars) {
588
+ if (true) {
589
+ DEBUG.set(obj, {
590
+ file,
591
+ loc,
592
+ vars
593
+ });
594
+ }
595
+ return obj;
596
+ }
585
597
  var Serializer = class {
586
598
  #state = new State();
587
599
  get flushed() {
@@ -682,6 +694,7 @@ function writeProp(state, val, parent, accessor) {
682
694
  case "object":
683
695
  return writeObject(state, val, parent, accessor);
684
696
  default:
697
+ throwUnserializable(state, val, parent, accessor);
685
698
  return false;
686
699
  }
687
700
  }
@@ -710,6 +723,9 @@ function writeReferenceOr(state, write2, val, parent, accessor) {
710
723
  val,
711
724
  ref = new Reference(parent, accessor, state.flush, state.buf.length)
712
725
  );
726
+ if (true) {
727
+ ref.debug = DEBUG.get(val);
728
+ }
713
729
  if (write2(state, val, ref)) return true;
714
730
  state.refs.delete(ref);
715
731
  return false;
@@ -786,7 +802,8 @@ function writeUnknownSymbol(state) {
786
802
  state.buf.push("Symbol()");
787
803
  return true;
788
804
  }
789
- function writeNever() {
805
+ function writeNever(state, val, ref) {
806
+ throwUnserializable(state, val, ref);
790
807
  return false;
791
808
  }
792
809
  function writeNull(state) {
@@ -867,6 +884,7 @@ function writeUnknownObject(state, val, ref) {
867
884
  case globalThis.Response:
868
885
  return writeResponse(state, val, ref);
869
886
  }
887
+ throwUnserializable(state, val, ref);
870
888
  return false;
871
889
  }
872
890
  function writePlainObject(state, val, ref) {
@@ -1284,6 +1302,45 @@ function writeAsyncCall(state, boundary, ref, method, value, preferredValueId =
1284
1302
  state.buf.push(")");
1285
1303
  boundary.endAsync();
1286
1304
  }
1305
+ function throwUnserializable(state, cause, ref = null, accessor = "") {
1306
+ if (cause !== void 0 && state.boundary?.abort) {
1307
+ let message = "Unable to serialize";
1308
+ let access = "";
1309
+ while (ref?.accessor) {
1310
+ const debug2 = ref.parent?.debug;
1311
+ if (debug2) {
1312
+ const varLoc = debug2.vars?.[ref.accessor];
1313
+ if (varLoc) {
1314
+ if (Array.isArray(varLoc)) {
1315
+ message += ` "${varLoc[0]}" in ${debug2.file}:${varLoc[1]}`;
1316
+ } else {
1317
+ message += ` "${ref.accessor}" in ${debug2.file}:${varLoc}`;
1318
+ }
1319
+ } else {
1320
+ message += ` ${JSON.stringify(ref.accessor)} in ${debug2.file}`;
1321
+ if (debug2.loc) {
1322
+ message += `:${debug2.loc}`;
1323
+ }
1324
+ }
1325
+ break;
1326
+ }
1327
+ access = toAccess(ref.accessor) + access;
1328
+ ref = ref.parent;
1329
+ }
1330
+ if (accessor) {
1331
+ access = toAccess(accessor) + access;
1332
+ }
1333
+ if (access[0] === ".") {
1334
+ access = access.slice(1);
1335
+ }
1336
+ if (access) {
1337
+ message += ` (reading ${access})`;
1338
+ }
1339
+ const err = new TypeError(message, { cause });
1340
+ err.stack = void 0;
1341
+ state.boundary.abort(err);
1342
+ }
1343
+ }
1287
1344
  function isCircular(parent, ref) {
1288
1345
  let cur = parent;
1289
1346
  while (cur) {
@@ -2416,6 +2473,7 @@ function escapeAttrValue(str) {
2416
2473
  var prefix = true ? "$compat_" : "$C_";
2417
2474
  var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
2418
2475
  var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
2476
+ var RENDER_BODY_ID = prefix + (true ? "renderBody" : "b");
2419
2477
 
2420
2478
  // src/common/meta.ts
2421
2479
  var DEFAULT_RUNTIME_ID = "M";
@@ -2602,11 +2660,14 @@ var compat = {
2602
2660
  asyncOut.error(boundary.signal.reason);
2603
2661
  } else {
2604
2662
  queueMicrotask(() => {
2605
- const { scripts, html } = head = prepareChunk(head);
2606
- asyncOut.script(scripts);
2607
- asyncOut.write(html);
2608
- asyncOut.end();
2609
- head.html = head.scripts = "";
2663
+ head = prepareChunk(head);
2664
+ if (boundary.done) {
2665
+ const { scripts, html } = head;
2666
+ asyncOut.script(scripts);
2667
+ asyncOut.write(html);
2668
+ asyncOut.end();
2669
+ head.html = head.scripts = "";
2670
+ }
2610
2671
  });
2611
2672
  }
2612
2673
  }
@@ -2619,6 +2680,9 @@ var compat = {
2619
2680
  register(id, () => {
2620
2681
  })
2621
2682
  );
2683
+ },
2684
+ registerRenderBody(fn) {
2685
+ register(RENDER_BODY_ID, fn);
2622
2686
  }
2623
2687
  };
2624
2688
 
@@ -2713,17 +2777,23 @@ var ServerRenderResult = class {
2713
2777
  done = true;
2714
2778
  if (resolve) {
2715
2779
  resolve({ value, done: !value });
2780
+ value = "";
2716
2781
  }
2717
2782
  }
2718
2783
  );
2719
2784
  return {
2720
2785
  next() {
2721
- if (value) {
2786
+ if (aborted) {
2787
+ return Promise.reject(reason);
2788
+ } else if (value) {
2722
2789
  const result = { value, done: false };
2723
2790
  value = "";
2724
2791
  return Promise.resolve(result);
2792
+ } else if (done) {
2793
+ return Promise.resolve({ value: "", done });
2794
+ } else {
2795
+ return new Promise(exec);
2725
2796
  }
2726
- return done ? Promise.resolve({ value: "", done }) : aborted ? Promise.reject(reason) : new Promise(exec);
2727
2797
  },
2728
2798
  throw(error) {
2729
2799
  if (!(done || aborted)) {
@@ -2803,12 +2873,13 @@ var ServerRenderResult = class {
2803
2873
  }
2804
2874
  const { boundary } = head;
2805
2875
  (boundary.onNext = () => {
2806
- if (boundary.done) {
2807
- if (boundary.signal.aborted) {
2808
- reject(boundary.signal.reason);
2809
- } else {
2810
- head = prepareChunk(head);
2811
- if (boundary.done) resolve(flushChunk(head, true));
2876
+ if (boundary.signal.aborted) {
2877
+ boundary.onNext = NOOP2;
2878
+ reject(boundary.signal.reason);
2879
+ } else if (boundary.done) {
2880
+ head = prepareChunk(head);
2881
+ if (boundary.done) {
2882
+ resolve(flushChunk(head, true));
2812
2883
  }
2813
2884
  }
2814
2885
  })();
@@ -2824,26 +2895,27 @@ var ServerRenderResult = class {
2824
2895
  }
2825
2896
  const { boundary } = head;
2826
2897
  const onNext = boundary.onNext = (write2) => {
2827
- if (write2 || boundary.done) {
2828
- if (boundary.signal.aborted) {
2829
- if (!tick2) offTick(onNext);
2830
- onAbort(boundary.signal.reason);
2831
- return;
2898
+ if (boundary.signal.aborted) {
2899
+ if (!tick2) offTick(onNext);
2900
+ boundary.onNext = NOOP2;
2901
+ onAbort(boundary.signal.reason);
2902
+ } else {
2903
+ if (write2 || boundary.done) {
2904
+ head = prepareChunk(head);
2832
2905
  }
2833
- head = prepareChunk(head);
2834
- }
2835
- if (write2 || boundary.done) {
2836
- const html = flushChunk(head, boundary.done);
2837
- if (html) onWrite(html);
2838
- if (boundary.done) {
2839
- if (!tick2) offTick(onNext);
2840
- onClose();
2841
- } else {
2842
- tick2 = true;
2906
+ if (write2 || boundary.done) {
2907
+ const html = flushChunk(head, boundary.done);
2908
+ if (html) onWrite(html);
2909
+ if (boundary.done) {
2910
+ if (!tick2) offTick(onNext);
2911
+ onClose();
2912
+ } else {
2913
+ tick2 = true;
2914
+ }
2915
+ } else if (tick2) {
2916
+ tick2 = false;
2917
+ queueTick(onNext);
2843
2918
  }
2844
- } else if (tick2) {
2845
- tick2 = false;
2846
- queueTick(onNext);
2847
2919
  }
2848
2920
  };
2849
2921
  onNext();
@@ -2857,6 +2929,8 @@ var ServerRenderResult = class {
2857
2929
  return flushChunk(prepareChunk(head), true);
2858
2930
  }
2859
2931
  };
2932
+ function NOOP2() {
2933
+ }
2860
2934
  // Annotate the CommonJS export names for ESM import in node:
2861
2935
  0 && (module.exports = {
2862
2936
  $global,
@@ -2874,6 +2948,7 @@ var ServerRenderResult = class {
2874
2948
  controllable_textarea_value,
2875
2949
  createRenderer,
2876
2950
  createTemplate,
2951
+ debug,
2877
2952
  dynamicTagArgs,
2878
2953
  dynamicTagInput,
2879
2954
  ensureScopeWithId,
@@ -502,6 +502,17 @@ var Reference = class {
502
502
  init = "";
503
503
  assigns = "";
504
504
  };
505
+ var DEBUG = /* @__PURE__ */ new WeakMap();
506
+ function debug(obj, file, loc, vars) {
507
+ if (true) {
508
+ DEBUG.set(obj, {
509
+ file,
510
+ loc,
511
+ vars
512
+ });
513
+ }
514
+ return obj;
515
+ }
505
516
  var Serializer = class {
506
517
  #state = new State();
507
518
  get flushed() {
@@ -602,6 +613,7 @@ function writeProp(state, val, parent, accessor) {
602
613
  case "object":
603
614
  return writeObject(state, val, parent, accessor);
604
615
  default:
616
+ throwUnserializable(state, val, parent, accessor);
605
617
  return false;
606
618
  }
607
619
  }
@@ -630,6 +642,9 @@ function writeReferenceOr(state, write2, val, parent, accessor) {
630
642
  val,
631
643
  ref = new Reference(parent, accessor, state.flush, state.buf.length)
632
644
  );
645
+ if (true) {
646
+ ref.debug = DEBUG.get(val);
647
+ }
633
648
  if (write2(state, val, ref)) return true;
634
649
  state.refs.delete(ref);
635
650
  return false;
@@ -706,7 +721,8 @@ function writeUnknownSymbol(state) {
706
721
  state.buf.push("Symbol()");
707
722
  return true;
708
723
  }
709
- function writeNever() {
724
+ function writeNever(state, val, ref) {
725
+ throwUnserializable(state, val, ref);
710
726
  return false;
711
727
  }
712
728
  function writeNull(state) {
@@ -787,6 +803,7 @@ function writeUnknownObject(state, val, ref) {
787
803
  case globalThis.Response:
788
804
  return writeResponse(state, val, ref);
789
805
  }
806
+ throwUnserializable(state, val, ref);
790
807
  return false;
791
808
  }
792
809
  function writePlainObject(state, val, ref) {
@@ -1204,6 +1221,45 @@ function writeAsyncCall(state, boundary, ref, method, value, preferredValueId =
1204
1221
  state.buf.push(")");
1205
1222
  boundary.endAsync();
1206
1223
  }
1224
+ function throwUnserializable(state, cause, ref = null, accessor = "") {
1225
+ if (cause !== void 0 && state.boundary?.abort) {
1226
+ let message = "Unable to serialize";
1227
+ let access = "";
1228
+ while (ref?.accessor) {
1229
+ const debug2 = ref.parent?.debug;
1230
+ if (debug2) {
1231
+ const varLoc = debug2.vars?.[ref.accessor];
1232
+ if (varLoc) {
1233
+ if (Array.isArray(varLoc)) {
1234
+ message += ` "${varLoc[0]}" in ${debug2.file}:${varLoc[1]}`;
1235
+ } else {
1236
+ message += ` "${ref.accessor}" in ${debug2.file}:${varLoc}`;
1237
+ }
1238
+ } else {
1239
+ message += ` ${JSON.stringify(ref.accessor)} in ${debug2.file}`;
1240
+ if (debug2.loc) {
1241
+ message += `:${debug2.loc}`;
1242
+ }
1243
+ }
1244
+ break;
1245
+ }
1246
+ access = toAccess(ref.accessor) + access;
1247
+ ref = ref.parent;
1248
+ }
1249
+ if (accessor) {
1250
+ access = toAccess(accessor) + access;
1251
+ }
1252
+ if (access[0] === ".") {
1253
+ access = access.slice(1);
1254
+ }
1255
+ if (access) {
1256
+ message += ` (reading ${access})`;
1257
+ }
1258
+ const err = new TypeError(message, { cause });
1259
+ err.stack = void 0;
1260
+ state.boundary.abort(err);
1261
+ }
1262
+ }
1207
1263
  function isCircular(parent, ref) {
1208
1264
  let cur = parent;
1209
1265
  while (cur) {
@@ -2336,6 +2392,7 @@ function escapeAttrValue(str) {
2336
2392
  var prefix = true ? "$compat_" : "$C_";
2337
2393
  var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
2338
2394
  var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
2395
+ var RENDER_BODY_ID = prefix + (true ? "renderBody" : "b");
2339
2396
 
2340
2397
  // src/common/meta.ts
2341
2398
  var DEFAULT_RUNTIME_ID = "M";
@@ -2522,11 +2579,14 @@ var compat = {
2522
2579
  asyncOut.error(boundary.signal.reason);
2523
2580
  } else {
2524
2581
  queueMicrotask(() => {
2525
- const { scripts, html } = head = prepareChunk(head);
2526
- asyncOut.script(scripts);
2527
- asyncOut.write(html);
2528
- asyncOut.end();
2529
- head.html = head.scripts = "";
2582
+ head = prepareChunk(head);
2583
+ if (boundary.done) {
2584
+ const { scripts, html } = head;
2585
+ asyncOut.script(scripts);
2586
+ asyncOut.write(html);
2587
+ asyncOut.end();
2588
+ head.html = head.scripts = "";
2589
+ }
2530
2590
  });
2531
2591
  }
2532
2592
  }
@@ -2539,6 +2599,9 @@ var compat = {
2539
2599
  register(id, () => {
2540
2600
  })
2541
2601
  );
2602
+ },
2603
+ registerRenderBody(fn) {
2604
+ register(RENDER_BODY_ID, fn);
2542
2605
  }
2543
2606
  };
2544
2607
 
@@ -2633,17 +2696,23 @@ var ServerRenderResult = class {
2633
2696
  done = true;
2634
2697
  if (resolve) {
2635
2698
  resolve({ value, done: !value });
2699
+ value = "";
2636
2700
  }
2637
2701
  }
2638
2702
  );
2639
2703
  return {
2640
2704
  next() {
2641
- if (value) {
2705
+ if (aborted) {
2706
+ return Promise.reject(reason);
2707
+ } else if (value) {
2642
2708
  const result = { value, done: false };
2643
2709
  value = "";
2644
2710
  return Promise.resolve(result);
2711
+ } else if (done) {
2712
+ return Promise.resolve({ value: "", done });
2713
+ } else {
2714
+ return new Promise(exec);
2645
2715
  }
2646
- return done ? Promise.resolve({ value: "", done }) : aborted ? Promise.reject(reason) : new Promise(exec);
2647
2716
  },
2648
2717
  throw(error) {
2649
2718
  if (!(done || aborted)) {
@@ -2723,12 +2792,13 @@ var ServerRenderResult = class {
2723
2792
  }
2724
2793
  const { boundary } = head;
2725
2794
  (boundary.onNext = () => {
2726
- if (boundary.done) {
2727
- if (boundary.signal.aborted) {
2728
- reject(boundary.signal.reason);
2729
- } else {
2730
- head = prepareChunk(head);
2731
- if (boundary.done) resolve(flushChunk(head, true));
2795
+ if (boundary.signal.aborted) {
2796
+ boundary.onNext = NOOP2;
2797
+ reject(boundary.signal.reason);
2798
+ } else if (boundary.done) {
2799
+ head = prepareChunk(head);
2800
+ if (boundary.done) {
2801
+ resolve(flushChunk(head, true));
2732
2802
  }
2733
2803
  }
2734
2804
  })();
@@ -2744,26 +2814,27 @@ var ServerRenderResult = class {
2744
2814
  }
2745
2815
  const { boundary } = head;
2746
2816
  const onNext = boundary.onNext = (write2) => {
2747
- if (write2 || boundary.done) {
2748
- if (boundary.signal.aborted) {
2749
- if (!tick2) offTick(onNext);
2750
- onAbort(boundary.signal.reason);
2751
- return;
2817
+ if (boundary.signal.aborted) {
2818
+ if (!tick2) offTick(onNext);
2819
+ boundary.onNext = NOOP2;
2820
+ onAbort(boundary.signal.reason);
2821
+ } else {
2822
+ if (write2 || boundary.done) {
2823
+ head = prepareChunk(head);
2752
2824
  }
2753
- head = prepareChunk(head);
2754
- }
2755
- if (write2 || boundary.done) {
2756
- const html = flushChunk(head, boundary.done);
2757
- if (html) onWrite(html);
2758
- if (boundary.done) {
2759
- if (!tick2) offTick(onNext);
2760
- onClose();
2761
- } else {
2762
- tick2 = true;
2825
+ if (write2 || boundary.done) {
2826
+ const html = flushChunk(head, boundary.done);
2827
+ if (html) onWrite(html);
2828
+ if (boundary.done) {
2829
+ if (!tick2) offTick(onNext);
2830
+ onClose();
2831
+ } else {
2832
+ tick2 = true;
2833
+ }
2834
+ } else if (tick2) {
2835
+ tick2 = false;
2836
+ queueTick(onNext);
2763
2837
  }
2764
- } else if (tick2) {
2765
- tick2 = false;
2766
- queueTick(onNext);
2767
2838
  }
2768
2839
  };
2769
2840
  onNext();
@@ -2777,6 +2848,8 @@ var ServerRenderResult = class {
2777
2848
  return flushChunk(prepareChunk(head), true);
2778
2849
  }
2779
2850
  };
2851
+ function NOOP2() {
2852
+ }
2780
2853
  export {
2781
2854
  $global,
2782
2855
  attr,
@@ -2793,6 +2866,7 @@ export {
2793
2866
  controllable_textarea_value,
2794
2867
  createRenderer,
2795
2868
  createTemplate,
2869
+ debug,
2796
2870
  dynamicTagArgs,
2797
2871
  dynamicTagInput,
2798
2872
  ensureScopeWithId,
@@ -4,12 +4,12 @@ import { type Renderer } from "./renderer";
4
4
  export declare const compat: {
5
5
  patchConditionals: typeof patchConditionals;
6
6
  queueEffect: typeof queueEffect;
7
- init(): void;
7
+ init(warp10Noop: any): void;
8
8
  registerRenderer(fn: any): void;
9
9
  isOp(value: any): boolean;
10
10
  isRenderer(renderer: any): boolean;
11
- getStartNode(scope: any): any;
12
- setScopeNodes(scope: any, startNode: Node, endNode: Node): void;
11
+ getStartNode(branch: any): any;
12
+ setScopeNodes(branch: any, startNode: Node, endNode: Node): void;
13
13
  runComponentEffects(this: any): void;
14
14
  runComponentDestroy(this: any): void;
15
15
  resolveRegistered(value: any, { runtimeId, componentIdPrefix, }: {
@@ -17,5 +17,5 @@ export declare const compat: {
17
17
  componentIdPrefix: string;
18
18
  }): any;
19
19
  createRenderer(setup: Renderer["___setup"], clone: Renderer["___clone"], args: Renderer["___args"]): Renderer;
20
- render(out: any, component: any, renderer: Renderer, args: any): (Node & ChildNode) | ParentNode | null | undefined;
20
+ render(out: any, component: any, renderer: Renderer, args: any): ChildNode | ParentNode | null | undefined;
21
21
  };
package/dist/dom/dom.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare function textContent(node: ParentNode, value: unknown): void;
9
9
  export declare function attrs(scope: Scope, nodeAccessor: Accessor, nextAttrs: Record<string, unknown>): void;
10
10
  export declare function partialAttrs(scope: Scope, nodeAccessor: Accessor, nextAttrs: Record<string, unknown>, skip: Record<string, 1>): void;
11
11
  export declare function attrsEvents(scope: Scope, nodeAccessor: Accessor): void;
12
- export declare function html(scope: Scope, value: unknown, index: Accessor): void;
12
+ export declare function html(scope: Scope, value: unknown, accessor: Accessor): void;
13
13
  export declare function props(scope: Scope, nodeIndex: number, index: number): void;
14
14
  export declare function normalizeAttrValue(value: unknown): string | undefined;
15
15
  export declare function lifecycle(scope: Scope, index: string | number, thisObj: Record<string, unknown> & {
@@ -17,3 +17,4 @@ export declare function lifecycle(scope: Scope, index: string | number, thisObj:
17
17
  onUpdate?: (this: unknown) => void;
18
18
  onDestroy?: (this: unknown) => void;
19
19
  }): void;
20
+ export declare function removeChildNodes(startNode: ChildNode, endNode: ChildNode): void;
@@ -1,2 +1,2 @@
1
1
  import type { BranchScope } from "../common/types";
2
- export declare function reconcile(parent: Node & ParentNode, oldBranches: BranchScope[], newBranches: BranchScope[], afterReference: Node | null): void;
2
+ export declare function reconcile(parent: ParentNode, oldBranches: BranchScope[], newBranches: BranchScope[], afterReference: Node | null): void;
@@ -4,4 +4,4 @@ export declare function finishPendingScopes(): void;
4
4
  export declare function getEmptyBranch(marker: Comment): BranchScope;
5
5
  export declare function destroyBranch(branch: BranchScope): void;
6
6
  export declare function removeAndDestroyBranch(branch: BranchScope): void;
7
- export declare function insertBranchBefore(branch: BranchScope, parent: Node & ParentNode, nextSibling: Node | null): void;
7
+ export declare function insertBranchBefore(branch: BranchScope, parentNode: ParentNode, nextSibling: Node | null): void;
@@ -1,4 +1,4 @@
1
- import { type Scope } from "../common/types";
1
+ import { type BranchScope } from "../common/types";
2
2
  export declare const walker: TreeWalker;
3
3
  export declare function trimWalkString(walkString: string): string;
4
- export declare function walk(startNode: Node, walkCodes: string, scope: Scope): void;
4
+ export declare function walk(startNode: Node, walkCodes: string, branch: BranchScope): void;