brumate 0.4.1 → 0.4.3

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 (61) hide show
  1. package/dist/{boot-SCWYwuUd.d.ts → boot-D3NjfyUX.d.ts} +2 -2
  2. package/dist/cli.js +2 -2
  3. package/dist/{client-BBtVTOIt.js → client-AXNULmRZ.js} +67 -12
  4. package/dist/client-AXNULmRZ.js.map +1 -0
  5. package/dist/{client-Cs3o4key.d.ts → client-DNva05jp.d.ts} +20 -7
  6. package/dist/{defer-BLJjxqVc.js → defer-D3YMPgkX.js} +2 -2
  7. package/dist/{defer-BLJjxqVc.js.map → defer-D3YMPgkX.js.map} +1 -1
  8. package/dist/{devtools-DTpsVFbn.js → devtools-BiP5fDiB.js} +4 -4
  9. package/dist/{devtools-DTpsVFbn.js.map → devtools-BiP5fDiB.js.map} +1 -1
  10. package/dist/{devtools-panel-C1Dfv6nq.js → devtools-panel-EQhLm39H.js} +2 -2
  11. package/dist/{devtools-panel-C1Dfv6nq.js.map → devtools-panel-EQhLm39H.js.map} +1 -1
  12. package/dist/{files-DZIiMDnS.js → files-BUjvEO_o.js} +2 -2
  13. package/dist/{files-DZIiMDnS.js.map → files-BUjvEO_o.js.map} +1 -1
  14. package/dist/{html-DS9B1H-M.js → html-t1JpkODI.js} +6 -4
  15. package/dist/html-t1JpkODI.js.map +1 -0
  16. package/dist/index.d.ts +5 -1
  17. package/dist/index.js +1 -1
  18. package/dist/{inspect-DomFHy5O.js → inspect-BvPTZs6k.js} +235 -67
  19. package/dist/inspect-BvPTZs6k.js.map +1 -0
  20. package/dist/{loader-D62komKu.js → loader-DgMk6p9M.js} +2 -2
  21. package/dist/{loader-D62komKu.js.map → loader-DgMk6p9M.js.map} +1 -1
  22. package/dist/produce-CLABZ8k2.d.ts +11 -0
  23. package/dist/{produce-BNIpmZq2.js → produce-DS-dQaUX.js} +3 -2
  24. package/dist/produce-DS-dQaUX.js.map +1 -0
  25. package/dist/{rpc-BTMb8jap.js → rpc-Bxv7DYGe.js} +3 -3
  26. package/dist/{rpc-BTMb8jap.js.map → rpc-Bxv7DYGe.js.map} +1 -1
  27. package/dist/runtime/client.d.ts +4 -4
  28. package/dist/runtime/client.js +4 -4
  29. package/dist/runtime/devtools.d.ts +2 -2
  30. package/dist/runtime/devtools.js +1 -1
  31. package/dist/runtime/hot.d.ts +1 -1
  32. package/dist/runtime/html.d.ts +1 -1
  33. package/dist/runtime/html.js +1 -1
  34. package/dist/runtime/loader.d.ts +2 -2
  35. package/dist/runtime/loader.js +2 -2
  36. package/dist/runtime/server.d.ts +3 -3
  37. package/dist/runtime/server.js +3 -3
  38. package/dist/runtime/static-loader.d.ts +2 -2
  39. package/dist/runtime/static-loader.js +1 -1
  40. package/dist/runtime/testing.d.ts +2 -2
  41. package/dist/runtime/testing.js +2 -2
  42. package/dist/{server-CYw15Dsg.d.ts → server-BXMH3Z9T.d.ts} +4 -3
  43. package/dist/{server-BTtsQFFw.js → server-O_rC-RRL.js} +11 -9
  44. package/dist/server-O_rC-RRL.js.map +1 -0
  45. package/dist/shared-CzbnWkVA.d.ts +255 -0
  46. package/dist/{static-loader-DVuLmXeu.d.ts → static-loader-BiUaZaag.d.ts} +2 -2
  47. package/dist/{static-loader-C_GYIFtt.js → static-loader-U_x-ctJI.js} +2 -2
  48. package/dist/{static-loader-C_GYIFtt.js.map → static-loader-U_x-ctJI.js.map} +1 -1
  49. package/dist/{stream-r4V5zBKm.js → stream-JGRPr7u5.js} +29 -5
  50. package/dist/stream-JGRPr7u5.js.map +1 -0
  51. package/dist/vite.d.ts +1 -1
  52. package/dist/vite.js +2 -2
  53. package/package.json +1 -1
  54. package/dist/client-BBtVTOIt.js.map +0 -1
  55. package/dist/html-DS9B1H-M.js.map +0 -1
  56. package/dist/html-Gggepsf-.d.ts +0 -109
  57. package/dist/inspect-DomFHy5O.js.map +0 -1
  58. package/dist/produce-BNIpmZq2.js.map +0 -1
  59. package/dist/produce-CRfouraC.d.ts +0 -153
  60. package/dist/server-BTtsQFFw.js.map +0 -1
  61. package/dist/stream-r4V5zBKm.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { i as paragraphComponents, t as checkNesting } from "./nesting-DA5vJw9X.js";
2
2
  import { t as KEY_NAMES } from "./events-LgLdp1R7.js";
3
- import { p as insertValue } from "./html-DS9B1H-M.js";
3
+ import { p as insertValue } from "./html-t1JpkODI.js";
4
4
  import { parseSync } from "oxc-parser";
5
5
  import { parse } from "postcss";
6
6
  import selectorParser from "postcss-selector-parser";
@@ -2055,6 +2055,47 @@ function createFail(source, filename) {
2055
2055
  };
2056
2056
  }
2057
2057
  //#endregion
2058
+ //#region src/ast.ts
2059
+ /** The markup inside a node: the children of an element, or the bodies of a block. */
2060
+ function getChildren(node) {
2061
+ switch (node.kind) {
2062
+ case "element":
2063
+ case "component":
2064
+ case "dynamic":
2065
+ case "fragment": return node.children;
2066
+ case "if": {
2067
+ const children = [];
2068
+ for (const branch of node.branches) children.push(...branch.body.children);
2069
+ children.push(...node.fallback?.children ?? []);
2070
+ return children;
2071
+ }
2072
+ case "switch": {
2073
+ const children = [];
2074
+ for (const branch of node.cases) children.push(...branch.body.children);
2075
+ children.push(...node.fallback?.children ?? []);
2076
+ return children;
2077
+ }
2078
+ case "for":
2079
+ case "repeat":
2080
+ case "loading":
2081
+ case "client":
2082
+ case "defer": return [...node.body.children, ...node.fallback?.children ?? []];
2083
+ case "try": return [...node.body.children, ...node.fallback.children];
2084
+ case "key":
2085
+ case "portal":
2086
+ case "head":
2087
+ case "offscreen": return node.body.children;
2088
+ default: return [];
2089
+ }
2090
+ }
2091
+ /** Visits every markup node of a file, including blocks and templates. */
2092
+ function forEachNode(nodes, visit) {
2093
+ for (const node of nodes) {
2094
+ visit(node);
2095
+ forEachNode(getChildren(node), visit);
2096
+ }
2097
+ }
2098
+ //#endregion
2058
2099
  //#region src/graph.ts
2059
2100
  /** Memos that a server function refreshes are live, so they have client code. */
2060
2101
  function isMemoKind(kind) {
@@ -2118,18 +2159,69 @@ const CLIENT_CODE = /* @__PURE__ */ new Set([
2118
2159
  "effect",
2119
2160
  "client"
2120
2161
  ]);
2162
+ /** True if one of the markup nodes holds a component or a dynamic tag, whose code this file cannot see. */
2163
+ function holdsComponent(nodes) {
2164
+ let found = false;
2165
+ forEachNode(nodes, (node) => {
2166
+ found ||= node.kind === "component" || node.kind === "dynamic";
2167
+ });
2168
+ return found;
2169
+ }
2170
+ /** True if `scope` is inside one of `ancestors`. */
2171
+ function isWithinAny$1(scope, ancestors) {
2172
+ for (const ancestor of ancestors) if (isWithin(scope, ancestor)) return true;
2173
+ return false;
2174
+ }
2175
+ /**
2176
+ * The scopes of the templates declared outside the body of a `#try` that are
2177
+ * called in it, in another such template, or in a function that one of them
2178
+ * calls. A template's scope links to where it is called at runtime, so the
2179
+ * `#try` catches the errors of these calls.
2180
+ */
2181
+ function calledTemplates(model, block) {
2182
+ const body = findBodyScope(model, block);
2183
+ if (body === void 0) return [];
2184
+ const inside = [body];
2185
+ const found = [];
2186
+ const called = /* @__PURE__ */ new Set();
2187
+ let added = true;
2188
+ while (added) {
2189
+ added = false;
2190
+ for (const site of model.sites) {
2191
+ if (!isWithinAny$1(site.scope, inside) && (site.declaration === void 0 || !called.has(site.declaration))) continue;
2192
+ for (const declaration of site.calls) if ((declaration.kind === "function" || declaration.kind === "template") && !called.has(declaration)) {
2193
+ called.add(declaration);
2194
+ added = true;
2195
+ }
2196
+ }
2197
+ for (const scope of model.scopes) {
2198
+ if (scope.kind !== "template" || isWithinAny$1(scope, inside)) continue;
2199
+ const declaration = lookup(scope.parent, scope.template.name);
2200
+ if (declaration && called.has(declaration)) {
2201
+ inside.push(scope);
2202
+ found.push(scope);
2203
+ added = true;
2204
+ }
2205
+ }
2206
+ }
2207
+ return found;
2208
+ }
2121
2209
  /**
2122
2210
  * True if the body of a `#try` holds code that runs in the browser: a
2123
2211
  * handler, an effect, a `$client` callback, a memo that loads, or a read of a
2124
2212
  * memo, which throws when the memo holds an error. An error in it renders
2125
- * the `#catch` body in the browser, so both bodies ship.
2213
+ * the `#catch` body in the browser, so both bodies ship. A component in the
2214
+ * body counts too, since its code can be any of these.
2126
2215
  */
2127
2216
  function tryCatchesClient(model, block) {
2128
2217
  const body = findBodyScope(model, block);
2129
2218
  if (body === void 0) return false;
2130
- for (const site of model.sites) if ((CLIENT_CODE.has(site.kind) || site.kind === "memo" && site.declaration?.kind === "async-memo") && isWithin(site.scope, body)) return true;
2219
+ const inside = [body, ...calledTemplates(model, block)];
2220
+ if (holdsComponent(block.body.children)) return true;
2221
+ for (const scope of model.scopes) if (scope.template && isWithinAny$1(scope, inside) && holdsComponent(scope.template.body.children)) return true;
2222
+ for (const site of model.sites) if ((CLIENT_CODE.has(site.kind) || site.kind === "memo" && site.declaration?.kind === "async-memo") && isWithinAny$1(site.scope, inside)) return true;
2131
2223
  for (const declaration of model.declarations) if (isMemoKind(declaration.kind)) {
2132
- for (const read of declaration.reads) if (isWithin(read.site.scope, body)) return true;
2224
+ for (const read of declaration.reads) if (isWithinAny$1(read.site.scope, inside)) return true;
2133
2225
  }
2134
2226
  return false;
2135
2227
  }
@@ -3601,45 +3693,6 @@ function importedComponents(file) {
3601
3693
  for (const program of [file.moduleScript?.program, file.instanceScript?.program]) for (const statement of program?.body ?? []) if (statement.type === "ImportDeclaration" && statement.source.value.endsWith(".brm")) specifiers.push(statement.source.value);
3602
3694
  return specifiers;
3603
3695
  }
3604
- /** The markup inside a node: the children of an element, or the bodies of a block. */
3605
- function getChildren(node) {
3606
- switch (node.kind) {
3607
- case "element":
3608
- case "component":
3609
- case "dynamic":
3610
- case "fragment": return node.children;
3611
- case "if": {
3612
- const children = [];
3613
- for (const branch of node.branches) children.push(...branch.body.children);
3614
- children.push(...node.fallback?.children ?? []);
3615
- return children;
3616
- }
3617
- case "switch": {
3618
- const children = [];
3619
- for (const branch of node.cases) children.push(...branch.body.children);
3620
- children.push(...node.fallback?.children ?? []);
3621
- return children;
3622
- }
3623
- case "for":
3624
- case "repeat":
3625
- case "loading":
3626
- case "client":
3627
- case "defer": return [...node.body.children, ...node.fallback?.children ?? []];
3628
- case "try": return [...node.body.children, ...node.fallback.children];
3629
- case "key":
3630
- case "portal":
3631
- case "head":
3632
- case "offscreen": return node.body.children;
3633
- default: return [];
3634
- }
3635
- }
3636
- /** Visits every markup node of a file, including blocks and templates. */
3637
- function forEachNode(nodes, visit) {
3638
- for (const node of nodes) {
3639
- visit(node);
3640
- forEachNode(getChildren(node), visit);
3641
- }
3642
- }
3643
3696
  /**
3644
3697
  * The live prop that a dynamic tag gives to the component it names. A spread or a computed name
3645
3698
  * can hold any prop, but `children` come from the body of the tag, so they are left out: `~`.
@@ -6232,6 +6285,7 @@ function createPlan(file, graph, path, hideNames = false) {
6232
6285
  if (!anchors.has(holder)) anchor(holderScope, holder);
6233
6286
  }
6234
6287
  }
6288
+ if (block.kind === "try" && tryCatchesClient(model, block)) scopes.get(bodyScopes.get(block.body)).needsId = true;
6235
6289
  if (live && block.kind === "offscreen") scopes.get(bodyScopes.get(block.body)).needsId = true;
6236
6290
  if (block.kind === "portal" || block.kind === "head") scopes.get(bodyScopes.get(block.body)).needsId = true;
6237
6291
  const inner = block.kind === "portal" || block.kind === "head" ? void 0 : outer;
@@ -6610,7 +6664,8 @@ function clonedTemplate(parts) {
6610
6664
  add({
6611
6665
  kind: "attribute",
6612
6666
  name: attribute[1],
6613
- value: attribute[2]
6667
+ value: attribute[2],
6668
+ settled: part.settled
6614
6669
  });
6615
6670
  continue;
6616
6671
  }
@@ -6629,7 +6684,8 @@ function clonedTemplate(parts) {
6629
6684
  add({
6630
6685
  kind: "content",
6631
6686
  value: insert[1],
6632
- at: insert[2]
6687
+ at: insert[2],
6688
+ settled: part.settled
6633
6689
  });
6634
6690
  continue;
6635
6691
  }
@@ -6670,7 +6726,8 @@ function clonedTemplate(parts) {
6670
6726
  const mark = writes.length;
6671
6727
  writes.push([{
6672
6728
  kind: "component",
6673
- call: code.replace(COMPONENT, "$$$$b.componentNodes(")
6729
+ call: code.replace(COMPONENT, "$$$$b.componentNodes("),
6730
+ settled: part.settled
6674
6731
  }]);
6675
6732
  reader.append(`<!--x${mark}-->`);
6676
6733
  continue;
@@ -6680,7 +6737,8 @@ function clonedTemplate(parts) {
6680
6737
  const mark = writes.length;
6681
6738
  writes.push([{
6682
6739
  kind: "component",
6683
- call: nodes[1]
6740
+ call: nodes[1],
6741
+ settled: part.settled
6684
6742
  }]);
6685
6743
  reader.append(`<!--x${mark}-->`);
6686
6744
  continue;
@@ -6810,7 +6868,8 @@ function clonedTemplate(parts) {
6810
6868
  writes.push([{
6811
6869
  kind: "put",
6812
6870
  value: insert[1],
6813
- at: insert[2]
6871
+ at: insert[2],
6872
+ settled: part.settled
6814
6873
  }]);
6815
6874
  reader.append(`<!--x${mark}-->`);
6816
6875
  continue;
@@ -6900,6 +6959,24 @@ function cloneLines(emitter, hoist, fn = 0) {
6900
6959
  const foreign = found.foreign ? `, ${JSON.stringify(found.foreign)}` : "";
6901
6960
  const lines = [`${indent}const $$e = $$b.clone(${hoist(`$$b.template(${JSON.stringify(found.html)}, ${found.writes.length}${foreign})`)}), $$f = $$e[${found.writes.length}];`];
6902
6961
  const fills = [];
6962
+ const settled = /* @__PURE__ */ new Map();
6963
+ function addLine(line, memos) {
6964
+ if (!memos) {
6965
+ lines.push(`${indent}${line}`);
6966
+ return;
6967
+ }
6968
+ const key = `${memos.scope} ${memos.names.join(" ")}`;
6969
+ let group = settled.get(key);
6970
+ if (!group) {
6971
+ group = {
6972
+ scope: memos.scope,
6973
+ names: memos.names,
6974
+ writes: []
6975
+ };
6976
+ settled.set(key, group);
6977
+ }
6978
+ group.writes.push(line);
6979
+ }
6903
6980
  let missing = false;
6904
6981
  for (const [index, writes] of found.writes.entries()) {
6905
6982
  let anchored;
@@ -6914,17 +6991,21 @@ function cloneLines(emitter, hoist, fn = 0) {
6914
6991
  for (const write of ordered) if (write.kind === "anchor") lines.push(`${indent}$$b.keep(${write.scope}, ${write.anchor}, $$e[${index}]${write.named ? ", true" : ""});`);
6915
6992
  else if (write.kind === "last") lines.push(`${indent}$$b.appendText(${write.scope}, ${write.anchor}, $$e[${index}], ${write.value}${write.at ? `, ${write.at}` : ""});`);
6916
6993
  else if (write.kind === "text") lines.push(`${indent}$$b.keepText(${write.scope}, ${write.anchor}, $$e[${index}], ${write.value}${write.at ? `, ${write.at}` : ""});`);
6917
- else if (write.kind === "attribute") lines.push(`${indent}$$b.setAttr($$e[${index}], ${write.name}, ${write.value});`);
6918
- else if (write.kind === "component") lines.push(`${indent}$$b.place($$e[${index}], ${write.call});`);
6994
+ else if (write.kind === "attribute") addLine(`$$b.setAttr($$e[${index}], ${write.name}, ${write.value});`, write.settled);
6995
+ else if (write.kind === "component") addLine(`$$b.place($$e[${index}], ${write.call});`, write.settled);
6919
6996
  else if (write.kind === "comment") lines.push(`${indent}$$b.nameComment($$e[${index}], ${write.data});`);
6920
- else if (write.kind === "put") lines.push(`${indent}$$b.putText($$e[${index}], ${write.value}${write.at ? `, ${write.at}` : ""});`);
6997
+ else if (write.kind === "put") addLine(`$$b.putText($$e[${index}], ${write.value}${write.at ? `, ${write.at}` : ""});`, write.settled);
6921
6998
  else if (write.kind === "call") lines.push(`${indent}${write.call.replace("$$m", () => `$$e[${index}]`)};`);
6922
6999
  else if (write.kind === "marker") lines.push(`${indent}$$b.markBlock($$e[${index}], ${write.scope}, ${write.anchor}, ${JSON.stringify(write.suffix)});`);
6923
7000
  else if (write.kind === "block") {
6924
7001
  const call = emitter.fills.get(`${write.scope}:${write.anchor}`);
6925
7002
  if (call === void 0) missing = true;
6926
7003
  else fills.push(`${indent}${call.replace("$$m", () => `$$e[${index}]`)};`);
6927
- } else lines.push(`${indent}$$b.setContent($$e[${index}], ${write.value}${write.at ? `, ${write.at}` : at});`);
7004
+ } else addLine(`$$b.setContent($$e[${index}], ${write.value}${write.at ? `, ${write.at}` : at});`, write.settled);
7005
+ }
7006
+ for (const group of settled.values()) {
7007
+ const names = group.names.join(", ");
7008
+ lines.push(`${indent}$$b.fillSettled(${group.scope}, [${names}], (${names}) => { ${group.writes.join(" ")} });`);
6928
7009
  }
6929
7010
  if (missing) return false;
6930
7011
  const sizes = /* @__PURE__ */ new Map();
@@ -7282,6 +7363,21 @@ const TYPE_DECLARATIONS = /* @__PURE__ */ new Set([
7282
7363
  "TSDeclareFunction",
7283
7364
  "TSModuleDeclaration"
7284
7365
  ]);
7366
+ /** Expressions whose value is never a promise, as the memo of a list or a function. */
7367
+ const NEVER_PROMISE = /* @__PURE__ */ new Set([
7368
+ "ArrayExpression",
7369
+ "ArrowFunctionExpression",
7370
+ "FunctionExpression"
7371
+ ]);
7372
+ /**
7373
+ * True for a memo whose value is never a promise in the browser, such as `count * 2`, an array or
7374
+ * a function. A memo with `await` inside is an async function, so its value is a promise whatever
7375
+ * its expression gives, as in ``$memo(`Hi ${(await load()).name}`)`` or `$memo([await load()])`.
7376
+ */
7377
+ function isNeverPromise(declaration) {
7378
+ const node = declaration.site?.node;
7379
+ return declaration.kind === "memo" && node !== void 0 && (isPrimitive(node) || NEVER_PROMISE.has(node.type));
7380
+ }
7285
7381
  /** The static or value attribute named `style`. */
7286
7382
  function findStyleAttribute(attributes) {
7287
7383
  for (const attribute of attributes) if ((attribute.kind === "static" || attribute.kind === "value") && attribute.name === "style") return attribute;
@@ -7300,6 +7396,11 @@ function readsProps(site) {
7300
7396
  for (const read of site?.reads ?? []) if (read.declaration.kind === "prop" || read.declaration.kind === "props-rest") return true;
7301
7397
  return false;
7302
7398
  }
7399
+ /** True if a site calls a template, or a function, which can return the output of one. */
7400
+ function callsTemplate(site) {
7401
+ for (const declaration of site?.calls ?? []) if (declaration.kind === "template" || declaration.kind === "function") return true;
7402
+ return false;
7403
+ }
7303
7404
  /** The name of the compile-time function that a declarator calls, for `$getContext` and `$id`. */
7304
7405
  function specialCall(declarator) {
7305
7406
  const init = declarator.init;
@@ -7436,6 +7537,8 @@ var Emitter = class {
7436
7537
  blocking;
7437
7538
  /** Memos and signals that hold a primitive on the server, so it awaits none of them. */
7438
7539
  inline;
7540
+ /** The sites of the markup that update in the browser. */
7541
+ liveSites = /* @__PURE__ */ new Set();
7439
7542
  parts = [];
7440
7543
  depth = 0;
7441
7544
  /** How many of this component's elements contain the current node. */
@@ -7457,6 +7560,7 @@ var Emitter = class {
7457
7560
  this.blocking = blockingMemos(plan);
7458
7561
  this.inline = options.mode === "server" ? plainValues(plan, this.blocking) : /* @__PURE__ */ new Set();
7459
7562
  for (const site of plan.graph.model.sites) this.sitesByNode.set(site.node, site);
7563
+ for (const node of plan.graph.nodes) if (node.kind !== "source" && plan.graph.live.has(node)) this.liveSites.add(node.site);
7460
7564
  this.addHandlerEdits();
7461
7565
  this.addBindEdits();
7462
7566
  for (const declaration of plan.graph.model.declarations) for (const ref of declaration.refs) this.refTargets.set(ref.attribute, declaration);
@@ -7596,8 +7700,32 @@ var Emitter = class {
7596
7700
  if (last && "static" in last) last.static += text;
7597
7701
  else this.parts.push({ static: text });
7598
7702
  }
7599
- code(code) {
7600
- this.parts.push({ code });
7703
+ code(code, settled) {
7704
+ this.parts.push(settled ? {
7705
+ code,
7706
+ settled
7707
+ } : { code });
7708
+ }
7709
+ /**
7710
+ * In the browser, the memos that values of the markup read that never change and can be a
7711
+ * promise, such as an insert, the headers of a block or the props of a component. No update
7712
+ * writes them when the memos settle, so the clone holds back what reads them.
7713
+ */
7714
+ settledMemos(expressions, scope) {
7715
+ if (this.options.mode !== "client") return;
7716
+ const names = [];
7717
+ for (const expression of expressions) {
7718
+ const site = this.sitesByNode.get(expression.ast);
7719
+ if (!site || this.liveSites.has(site)) return;
7720
+ for (const reference of site.reads) {
7721
+ const declaration = reference.declaration;
7722
+ if (isMemo(declaration) && !isNeverPromise(declaration) && !names.includes(declaration.name)) names.push(declaration.name);
7723
+ }
7724
+ }
7725
+ return names.length > 0 ? {
7726
+ names,
7727
+ scope: this.scopeVar(instanceScope(this.plan, scope))
7728
+ } : void 0;
7601
7729
  }
7602
7730
  flush() {
7603
7731
  if (this.parts.length === 0) return;
@@ -7794,9 +7922,27 @@ var Emitter = class {
7794
7922
  if (!this.options.functions && this.isFunctionStatement(statement)) continue;
7795
7923
  }
7796
7924
  this.raw(this.patch.slice(statement.start, statement.end), statement.start);
7925
+ if (this.options.mode === "client" && statement.type === "VariableDeclaration") this.watchUnreadMemos(statement, scope);
7797
7926
  }
7798
7927
  endRun();
7799
7928
  }
7929
+ /**
7930
+ * In the browser, a memo that nothing reads has no slot, so no load takes its promise. Its
7931
+ * rejection goes to the nearest `#try`, which is where a memo that throws sends its error. A
7932
+ * memo that always gives a primitive, such as `count * 2`, is never a promise, unless it has
7933
+ * `await` inside. `await memo` compiles to a plain read of the promise, which drops it, unless
7934
+ * the read is the whole value of another memo, as in `$memo(await memo)`, which then holds the
7935
+ * same promise.
7936
+ */
7937
+ watchUnreadMemos(statement, scope) {
7938
+ for (const declarator of statement.declarations) {
7939
+ const declaration = declarator.id.type === "Identifier" ? scope.declarations.get(declarator.id.name) : void 0;
7940
+ if (declaration && (declaration.kind === "memo" || declaration.kind === "async-memo") && declaration.reads.every((read) => read.await && (read.site.kind !== "memo" || read.site.node.start !== read.await.start || read.site.node.end !== read.await.end)) && slotIndex(this.plan, declaration) === -1 && !isNeverPromise(declaration)) {
7941
+ const target = this.scopeVar(instanceScope(this.plan, scope));
7942
+ this.line(`$$b.unreadMemo(${target}, ${declaration.name});`);
7943
+ }
7944
+ }
7945
+ }
7800
7946
  source(node) {
7801
7947
  return this.patch.slice(node.start, node.end);
7802
7948
  }
@@ -7975,7 +8121,9 @@ var Emitter = class {
7975
8121
  this.line(`let $$html = '';`);
7976
8122
  this.atTopLevel(() => this.emitBody(template.body));
7977
8123
  this.flush();
7978
- this.line("return $$b.raw($$html);");
8124
+ const scope = this.plan.bodyScopes.get(template.body);
8125
+ const at = this.plan.scopes.get(scope).needsId ? `, ${this.scopeVar(scope)}` : "";
8126
+ this.line(`return $$b.raw($$html${at});`);
7979
8127
  this.close();
7980
8128
  }
7981
8129
  emitNodes(nodes, scope) {
@@ -7996,15 +8144,17 @@ var Emitter = class {
7996
8144
  return;
7997
8145
  case "insert": {
7998
8146
  const anchor = this.anchor(scope, node);
7999
- const readsProp = readsProps(this.sitesByNode.get(node.expression.ast));
8147
+ const site = this.sitesByNode.get(node.expression.ast);
8148
+ const readsProp = readsProps(site);
8000
8149
  const spacer = this.parentSpacer();
8001
8150
  const server = this.options.mode === "server" && readsProp;
8002
8151
  let rest = server && spacer !== void 0 ? `, ${JSON.stringify(spacer)}` : "";
8003
8152
  if (server && anchor) rest = `${rest || ", undefined"}, ${anchor.index}`;
8004
- const at = this.options.mode === "server" || readsProp ? `, ${this.ctxArgument}, ${this.scopeVar(instanceScope(this.plan, scope))}${rest}` : "";
8153
+ const at = this.options.mode === "server" || readsProp || callsTemplate(site) ? `, ${this.ctxArgument}, ${this.scopeVar(instanceScope(this.plan, scope))}${rest}` : "";
8005
8154
  const value = this.isPrimitiveInsert(node.expression) ? `$$b.insert(${this.expression(node.expression)})` : this.ready(`$$b.insert(${this.expression(node.expression)}${at})`);
8006
8155
  const text = literalText(node.expression.ast);
8007
- const emitValue = () => text === void 0 ? this.code(value) : this.html(text);
8156
+ const settled = this.settledMemos([node.expression], scope);
8157
+ const emitValue = () => text === void 0 ? this.code(value, settled) : this.html(text);
8008
8158
  if (anchor && !this.plan.contents.has(node)) {
8009
8159
  this.html("<!--t");
8010
8160
  this.code(anchor.scope);
@@ -8219,7 +8369,7 @@ var Emitter = class {
8219
8369
  this.emitClasses(classes);
8220
8370
  break;
8221
8371
  }
8222
- this.code(`$$b.attribute(${JSON.stringify(attribute.name)}, ${this.expression(attribute.value)})`);
8372
+ this.code(`$$b.attribute(${JSON.stringify(attribute.name)}, ${this.expression(attribute.value)})`, this.settledMemos([attribute.value], scope));
8223
8373
  const bound = this.bindEntry(node, attribute, scope);
8224
8374
  if (bound) events.unshift(bound);
8225
8375
  break;
@@ -8485,7 +8635,17 @@ var Emitter = class {
8485
8635
  const at = `${this.file.filename}:${before.length}:${before.at(-1).length + 1}`;
8486
8636
  link = `${link || ", undefined"}, ${JSON.stringify(`<${node.name}> in ${at}`)}`;
8487
8637
  }
8488
- this.code(`${this.wait}$$b.component(${node.name}, ${props}, ${this.ctxArgument}, ${owner}${link})`);
8638
+ const values = [];
8639
+ for (const attribute of node.attributes) {
8640
+ const type = attribute.kind === "value" ? attribute.value.ast.type : "";
8641
+ if (type === "ArrowFunctionExpression" || type === "FunctionExpression") continue;
8642
+ if (attribute.kind === "value" || attribute.kind === "spread") values.push(attribute.value);
8643
+ else if (attribute.kind === "computed") {
8644
+ values.push(attribute.name);
8645
+ if (attribute.value !== true) values.push(attribute.value);
8646
+ }
8647
+ }
8648
+ this.code(`${this.wait}$$b.component(${node.name}, ${props}, ${this.ctxArgument}, ${owner}${link})`, this.settledMemos(values, scope));
8489
8649
  }
8490
8650
  emitDynamic(node, scope) {
8491
8651
  const childrenName = this.emitChildren(node, scope);
@@ -8739,7 +8899,9 @@ var Emitter = class {
8739
8899
  let index = other ? String(branches.length) : "-1";
8740
8900
  for (let at = branches.length - 1; at >= 0; at--) index = `${this.expression(branches[at].condition)} ? ${at} : ${index}`;
8741
8901
  const names = `[${[...bodies, ...other ? [other] : []].join(", ")}]`;
8742
- this.code(`$$b.nodes($$b.branchNodes(${marks}, ${index}, ${names}))`);
8902
+ const conditions = [];
8903
+ for (const branch of branches) conditions.push(branch.condition);
8904
+ this.code(`$$b.nodes($$b.branchNodes(${marks}, ${index}, ${names}))`, this.settledMemos(conditions, scope));
8743
8905
  return true;
8744
8906
  }
8745
8907
  if (block.kind === "for" || block.kind === "repeat") {
@@ -8749,7 +8911,7 @@ var Emitter = class {
8749
8911
  const fallback = block.fallback;
8750
8912
  const other = fallback && this.bodyFunction("", () => this.emitBody(fallback));
8751
8913
  const items = block.kind === "for" ? `$$b.toList(${this.expression(block.list)})` : `Array.from({ length: ${this.expression(block.count)} }, (_, index) => index)`;
8752
- this.code(`$$b.nodes($$b.listNodes(${marks}, ${items}, ${body}, ${other ?? "undefined"}))`);
8914
+ this.code(`$$b.nodes($$b.listNodes(${marks}, ${items}, ${body}, ${other ?? "undefined"}))`, this.settledMemos([block.kind === "for" ? block.list : block.count], scope));
8753
8915
  return true;
8754
8916
  }
8755
8917
  return false;
@@ -10938,15 +11100,21 @@ var ClientGenerator = class {
10938
11100
  * body, and the kinds of both bodies, and the holder of a block in children.
10939
11101
  */
10940
11102
  triesTable() {
10941
- const entries = [];
11103
+ const bodies = /* @__PURE__ */ new Map();
10942
11104
  for (const scope of this.model.scopes) {
10943
11105
  const block = scope.block;
10944
11106
  if (block?.kind !== "try" || scope.body !== block.body || !this.plan.anchors.has(block) || !tryCatchesClient(this.model, block)) continue;
10945
11107
  const owner = instanceScope(this.plan, scope.parent);
10946
11108
  const fallback = this.plan.bodyScopes.get(block.fallback);
10947
11109
  const held = holderArguments(this.plan, block);
10948
- const entry = `[${owner.id}, ${this.plan.anchors.get(block)}, ${JSON.stringify(`r${scope.id}`)}, ${JSON.stringify(`r${fallback.id}`)}, [${this.kinds(blockBodies(block)).join(", ")}]${held}]`;
10949
- for (const inside of this.model.scopes) if (isWithin(inside, scope)) entries.push(`${inside.id}: ${entry}`);
11110
+ bodies.set(scope, `[${owner.id}, ${this.plan.anchors.get(block)}, ${JSON.stringify(`r${scope.id}`)}, ${JSON.stringify(`r${fallback.id}`)}, [${this.kinds(blockBodies(block)).join(", ")}]${held}]`);
11111
+ }
11112
+ const entries = [];
11113
+ for (const inside of this.model.scopes) {
11114
+ let current = inside;
11115
+ while (current && !bodies.has(current) && current.kind !== "template") current = current.parent;
11116
+ const entry = current && bodies.get(current);
11117
+ if (entry) entries.push(`${inside.id}: ${entry}`);
10950
11118
  }
10951
11119
  return entries.length > 0 ? `{ ${entries.join(", ")} }` : void 0;
10952
11120
  }
@@ -11472,6 +11640,6 @@ function inspect(source, options = {}) {
11472
11640
  };
11473
11641
  }
11474
11642
  //#endregion
11475
- export { analyzeProject as A, getLocation as B, isReactiveModule as C, unmarked as D, originalPosition as E, resolveRelative as F, isWithin as G, findError as H, summarize as I, walk as J, lookup as K, parse$1 as L, forEachNode as M, importSource as N, entryClasses as O, importedComponents as P, buildGraph as R, sharedSites as S, builtin as T, analyze$1 as U, errorLink as V, getPatternNames as W, functionId as _, scopeLabel as a, SHARED_QUERY as b, DEFAULT_MERGE as c, generateServer as d, instanceScope as f, createPlan as g, clientState as h, report as i, analyzeProjectProps as j, refreshedNames as k, generateClient as l, blockBodies as m, formatReport as n, CompileError as o, slotIndex as p, resolveMacros as q, inspect as r, compile as s, anchorLabel as t, generateRender as u, getComponentName as v, resolveFromDisk as w, generateShared as x, hash as y, BrumateError as z };
11643
+ export { analyzeProject as A, getLocation as B, isReactiveModule as C, unmarked as D, originalPosition as E, summarize as F, isWithin as G, findError as H, parse$1 as I, walk as J, lookup as K, buildGraph as L, importSource as M, importedComponents as N, entryClasses as O, resolveRelative as P, forEachNode as R, sharedSites as S, builtin as T, analyze$1 as U, errorLink as V, getPatternNames as W, functionId as _, scopeLabel as a, SHARED_QUERY as b, DEFAULT_MERGE as c, generateServer as d, instanceScope as f, createPlan as g, clientState as h, report as i, analyzeProjectProps as j, refreshedNames as k, generateClient as l, blockBodies as m, formatReport as n, CompileError as o, slotIndex as p, resolveMacros as q, inspect as r, compile as s, anchorLabel as t, generateRender as u, getComponentName as v, resolveFromDisk as w, generateShared as x, hash as y, BrumateError as z };
11476
11644
 
11477
- //# sourceMappingURL=inspect-DomFHy5O.js.map
11645
+ //# sourceMappingURL=inspect-BvPTZs6k.js.map