brumate 0.2.0 → 0.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 (101) hide show
  1. package/dist/{boot-D-IdPy7B.d.ts → boot-C25Sa6vq.d.ts} +5 -2
  2. package/dist/cli.js +2 -2
  3. package/dist/{client-C0UCNL3J.js → client-BD6XT-s5.js} +435 -110
  4. package/dist/client-BD6XT-s5.js.map +1 -0
  5. package/dist/{client-MD0ZmcFR.d.ts → client-D0CqSxoO.d.ts} +114 -8
  6. package/dist/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
  7. package/dist/cookies-BzllthiF.js.map +1 -0
  8. package/dist/{defer-D0bo1Gqx.js → defer-BbD7JQhj.js} +6 -2
  9. package/dist/defer-BbD7JQhj.js.map +1 -0
  10. package/dist/devtools-CQgD7NPB.js +623 -0
  11. package/dist/devtools-CQgD7NPB.js.map +1 -0
  12. package/dist/devtools-panel-BVB-W5q4.js +1930 -0
  13. package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
  14. package/dist/events-CSs7OwIC.js +85 -0
  15. package/dist/events-CSs7OwIC.js.map +1 -0
  16. package/dist/{files-Bnn1JqHx.js → files-BXSSrQgc.js} +18 -5
  17. package/dist/files-BXSSrQgc.js.map +1 -0
  18. package/dist/forms-Bg-CwGqX.js +406 -0
  19. package/dist/forms-Bg-CwGqX.js.map +1 -0
  20. package/dist/forms-Cl21hkHt.d.ts +281 -0
  21. package/dist/highlight.d.ts +17 -0
  22. package/dist/highlight.js +269 -0
  23. package/dist/highlight.js.map +1 -0
  24. package/dist/{html-y1q7-t7D.d.ts → html-Bq1rFxX_.d.ts} +36 -4
  25. package/dist/{html-bHZbkK-h.js → html-mNTKzaDD.js} +79 -8
  26. package/dist/html-mNTKzaDD.js.map +1 -0
  27. package/dist/index.d.ts +47 -2
  28. package/dist/index.js +3 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/{inspect-BJtACnQp.js → inspect-BHpOw1LF.js} +625 -48
  31. package/dist/inspect-BHpOw1LF.js.map +1 -0
  32. package/dist/{loader-B18i3_-T.js → loader-Dos_3NP0.js} +5 -4
  33. package/dist/loader-Dos_3NP0.js.map +1 -0
  34. package/dist/{navigate-BwuZveDF.js → navigate-O78d_zGN.js} +45 -2
  35. package/dist/navigate-O78d_zGN.js.map +1 -0
  36. package/dist/{produce-D4K7qpaL.d.ts → produce-D0V0ICkz.d.ts} +45 -3
  37. package/dist/{produce-CWfJ4byV.js → produce-Doc91GkX.js} +113 -6
  38. package/dist/produce-Doc91GkX.js.map +1 -0
  39. package/dist/{rpc-B-Zkn6Ch.js → rpc-ygMRPmN4.js} +20 -10
  40. package/dist/rpc-ygMRPmN4.js.map +1 -0
  41. package/dist/runtime/client.d.ts +4 -4
  42. package/dist/runtime/client.js +4 -4
  43. package/dist/runtime/devtools.d.ts +188 -3
  44. package/dist/runtime/devtools.js +1 -1
  45. package/dist/runtime/events.d.ts +15 -0
  46. package/dist/runtime/events.js +1 -1
  47. package/dist/runtime/forms.d.ts +2 -0
  48. package/dist/runtime/forms.js +1 -0
  49. package/dist/runtime/gather.d.ts +25 -0
  50. package/dist/runtime/gather.js +33 -0
  51. package/dist/runtime/gather.js.map +1 -0
  52. package/dist/runtime/hot.d.ts +1 -1
  53. package/dist/runtime/html.d.ts +2 -2
  54. package/dist/runtime/html.js +1 -1
  55. package/dist/runtime/loader.d.ts +2 -2
  56. package/dist/runtime/loader.js +2 -2
  57. package/dist/runtime/server.d.ts +5 -4
  58. package/dist/runtime/server.js +5 -5
  59. package/dist/runtime/signals.d.ts +38 -2
  60. package/dist/runtime/signals.js +12 -2
  61. package/dist/runtime/signals.js.map +1 -1
  62. package/dist/runtime/static-loader.d.ts +2 -2
  63. package/dist/runtime/static-loader.js +1 -1
  64. package/dist/runtime/testing.d.ts +2 -2
  65. package/dist/runtime/testing.js +2 -2
  66. package/dist/runtime/values.d.ts +2 -0
  67. package/dist/runtime/values.js +24 -0
  68. package/dist/runtime/values.js.map +1 -0
  69. package/dist/{server-BqfM95r1.js → server-CxVDYE_V.js} +776 -121
  70. package/dist/server-CxVDYE_V.js.map +1 -0
  71. package/dist/{server-BA9SJ2Vm.d.ts → server-DuFYRXrd.d.ts} +284 -15
  72. package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-Drpr0AzI.d.ts} +2 -2
  73. package/dist/{static-loader-DOygOFj5.js → static-loader-nZssh66R.js} +168 -51
  74. package/dist/static-loader-nZssh66R.js.map +1 -0
  75. package/dist/{stream-JaMHMdBD.js → stream-DCYZO4IF.js} +89 -10
  76. package/dist/stream-DCYZO4IF.js.map +1 -0
  77. package/dist/values-B8C7CLvG.d.ts +63 -0
  78. package/dist/vite.d.ts +8 -1
  79. package/dist/vite.js +170 -20
  80. package/dist/vite.js.map +1 -1
  81. package/forms/forms.brm.ts +141 -0
  82. package/package.json +31 -2
  83. package/dist/client-C0UCNL3J.js.map +0 -1
  84. package/dist/cookies-Av5WFmcf.js.map +0 -1
  85. package/dist/defer-D0bo1Gqx.js.map +0 -1
  86. package/dist/devtools-C50VH8gZ.js +0 -113
  87. package/dist/devtools-C50VH8gZ.js.map +0 -1
  88. package/dist/devtools-panel-AYjfwPhj.js +0 -435
  89. package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
  90. package/dist/events-BKWRqtMg.js +0 -52
  91. package/dist/events-BKWRqtMg.js.map +0 -1
  92. package/dist/files-Bnn1JqHx.js.map +0 -1
  93. package/dist/html-bHZbkK-h.js.map +0 -1
  94. package/dist/inspect-BJtACnQp.js.map +0 -1
  95. package/dist/loader-B18i3_-T.js.map +0 -1
  96. package/dist/navigate-BwuZveDF.js.map +0 -1
  97. package/dist/produce-CWfJ4byV.js.map +0 -1
  98. package/dist/rpc-B-Zkn6Ch.js.map +0 -1
  99. package/dist/server-BqfM95r1.js.map +0 -1
  100. package/dist/static-loader-DOygOFj5.js.map +0 -1
  101. package/dist/stream-JaMHMdBD.js.map +0 -1
@@ -77,13 +77,51 @@ function styleValue(value) {
77
77
  if (typeof value === "object" && value !== null) return Object.entries(value).filter(([, item]) => item !== null && item !== void 0 && item !== false).map(([name, item]) => `${toKebabCase(name)}:${String(item)}`).join(";");
78
78
  return String(value);
79
79
  }
80
+ /** The brand of a binding of `$bind`, under the key of the registry. See `Binding`. */
81
+ const BOUND = Symbol.for("brumate.binding");
82
+ /** The words of an attribute that says `true` or `false` in its value. */
83
+ const TRUE_FALSE = ["true", "false"];
84
+ /**
85
+ * Attributes whose two states are words in the value, not whether the
86
+ * attribute is there, by their words for `true` and `false`. A missing
87
+ * attribute means a third state, such as the default of the element, so
88
+ * `false` must not remove it. `aria-*` and `data-*` are such attributes too.
89
+ */
90
+ const SWITCHES = /* @__PURE__ */ new Map([
91
+ ["contenteditable", TRUE_FALSE],
92
+ ["draggable", TRUE_FALSE],
93
+ ["spellcheck", TRUE_FALSE],
94
+ ["writingsuggestions", TRUE_FALSE],
95
+ ["focusable", TRUE_FALSE],
96
+ ["translate", ["yes", "no"]],
97
+ ["autocomplete", ["on", "off"]],
98
+ ["autocorrect", ["on", "off"]]
99
+ ]);
100
+ /** The words of `true` and `false` for an attribute that says them in its value, or undefined. */
101
+ function switchWords(name) {
102
+ const lower = name.toLowerCase();
103
+ if (lower.startsWith("aria-") || lower.startsWith("data-")) return TRUE_FALSE;
104
+ return SWITCHES.get(lower);
105
+ }
80
106
  /**
81
107
  * Returns the text of an attribute, or undefined if the attribute is not
82
- * rendered. `true` renders as an empty value.
108
+ * rendered.
109
+ *
110
+ * - `null` and `undefined` leave the attribute out.
111
+ * - For an attribute whose value says its state, such as `aria-expanded`,
112
+ * `draggable` or `translate`, `true` and `false` render as its words:
113
+ * `"true"` and `"false"`, or `"yes"` and `"no"`, or `"on"` and `"off"`.
114
+ * - For other attributes, such as `disabled`, `true` renders the attribute
115
+ * without a value, and `false` leaves it out.
83
116
  */
84
117
  function attributeText(name, value) {
85
- if (value === null || value === void 0 || value === false || typeof value === "function") return;
86
- if (value === true) return "";
118
+ if (typeof value === "object" && value !== null && BOUND in value) value = value.value;
119
+ if (value === null || value === void 0 || typeof value === "function") return;
120
+ if (typeof value === "boolean") {
121
+ const words = switchWords(name);
122
+ if (words) return value ? words[0] : words[1];
123
+ return value ? "" : void 0;
124
+ }
87
125
  if (name === "class") {
88
126
  const text = classValue(value);
89
127
  return text === "" ? void 0 : text;
@@ -100,7 +138,7 @@ const ATTRIBUTE_NAME = /^[^\s"'>/=\x00-\x1f\x7f]+$/;
100
138
  function attribute(name, value) {
101
139
  const text = attributeText(name, value);
102
140
  if (text === void 0 || !ATTRIBUTE_NAME.test(name)) return "";
103
- return value === true ? ` ${name}` : ` ${name}="${escapeAttribute(text)}"`;
141
+ return value === true && text === "" ? ` ${name}` : ` ${name}="${escapeAttribute(text)}"`;
104
142
  }
105
143
  /**
106
144
  * Returns the value of a style variable with text around it, such as `12px`
@@ -130,6 +168,39 @@ function mergeAttributes(parts) {
130
168
  for (const part of parts) for (const [name, value] of Object.entries(part ?? {})) result[name] = name === "class" && result.class !== void 0 && value !== void 0 ? [result.class, value] : value;
131
169
  return result;
132
170
  }
171
+ /**
172
+ * The `b-on` entry of a handler that a spread passes on, such as
173
+ * `click:prevent=Parent#h1@3`: its event, the modifiers of its wrappers, its
174
+ * client function and the scope it runs in. A handler that `$handler` made
175
+ * has its arguments after another `@`, encoded so that they hold no space.
176
+ */
177
+ function handlerEntry(name, ref, scope, modifiers = [], args) {
178
+ const bound = args === void 0 ? "" : `@${encodeURIComponent(JSON.stringify(args))}`;
179
+ return `${[name.slice(2).toLowerCase(), ...modifiers].join(":")}=${ref}@${scope}${bound}`;
180
+ }
181
+ /**
182
+ * The `b-on` entry of a binding that a spread puts on `value` or `checked`
183
+ * of an element. It names the scope of the slot, or of the setter of
184
+ * `$bind(name, fn)`, after `@`. A box writes on `change`.
185
+ */
186
+ function bindEntry(name, ref, setter) {
187
+ const event = name === "checked" ? "change" : "input";
188
+ return setter ? `${event}=$set:${setter.ref}@${setter.scope}` : `${event}=$bind#0.${ref.slot}@${ref.scope}`;
189
+ }
190
+ /**
191
+ * The `b-on` attribute of an element with spreads: the bindings of its
192
+ * spreads, so its handlers read the new value, then its own handlers, then
193
+ * those of its spreads.
194
+ */
195
+ function onAttribute(on, own) {
196
+ const bindings = on.filter((entry) => /=\$(bind#|set:)/.test(entry));
197
+ const value = [
198
+ ...bindings,
199
+ own,
200
+ ...on.filter((entry) => !bindings.includes(entry))
201
+ ].filter(Boolean).join(" ");
202
+ return value ? ` b-on="${escapeAttribute(value)}"` : "";
203
+ }
133
204
  /** Renders an object of attributes. */
134
205
  function spread(attributes) {
135
206
  let result = "";
@@ -158,13 +229,13 @@ const VOID_ELEMENTS = /* @__PURE__ */ new Set([
158
229
  * of the build of the page, which the URL carries as `__build`, so the
159
230
  * server can tell a post from before a deploy without scripts.
160
231
  */
161
- function actionAttributes(prefix, name, id, method, result, build) {
232
+ function actionAttributes(prefix, name, id, method, result, build, key) {
162
233
  const methodText = method ? ` ${method}="post"` : "";
163
- const query = build === void 0 ? "" : `__build=${encodeURIComponent(build)}`;
234
+ const query = [build === void 0 ? "" : `__build=${encodeURIComponent(build)}`, key === void 0 ? "" : `__key=${key}`].filter(Boolean).join("&");
164
235
  if (result !== void 0) return ` ${name}="${escapeAttribute(`?__action=${encodeURIComponent(id)}${query ? `&${query}` : ""}`)}"${methodText} b-action="${escapeAttribute(id)}" b-result="${escapeAttribute(result)}"`;
165
236
  return ` ${name}="${escapeAttribute(`${prefix}/${encodeURIComponent(id)}${query ? `?${query}` : ""}`)}"${methodText}`;
166
237
  }
167
238
  //#endregion
168
- export { textValue as _, attributeText as a, escape as c, isRaw as d, mergeAttributes as f, styleElement as g, spread as h, attribute as i, escapeAttribute as l, rawHTML as m, actionAttributes as n, classAttribute as o, raw as p, affix as r, classValue as s, VOID_ELEMENTS as t, insertValue as u, vars as v };
239
+ export { rawHTML as _, attributeText as a, textValue as b, classValue as c, handlerEntry as d, insertValue as f, raw as g, onAttribute as h, attribute as i, escape as l, mergeAttributes as m, actionAttributes as n, bindEntry as o, isRaw as p, affix as r, classAttribute as s, VOID_ELEMENTS as t, escapeAttribute as u, spread as v, vars as x, styleElement as y };
169
240
 
170
- //# sourceMappingURL=html-bHZbkK-h.js.map
241
+ //# sourceMappingURL=html-mNTKzaDD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-mNTKzaDD.js","names":[],"sources":["../src/runtime/html.ts"],"sourcesContent":["// HTML string helpers that the server and the client both use.\n\nconst RAW: unique symbol = Symbol.for('brumate.raw');\n\n/** HTML that is inserted as it is, such as the output of a template. */\nexport interface Raw {\n [RAW]: string;\n}\n\n// A class, not an object literal, so serializers can skip their test for raw HTML on plain objects.\nclass RawHTML implements Raw {\n readonly [RAW]: string;\n\n constructor(html: string) {\n this[RAW] = html;\n }\n}\n\nexport function raw(html: string): Raw {\n return new RawHTML(html);\n}\n\nexport function isRaw(value: unknown): value is Raw {\n return typeof value === 'object' && value !== null && RAW in value;\n}\n\nexport function rawHTML(value: Raw): string {\n return value[RAW];\n}\n\nconst ESCAPES: Record<string, string> = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;' };\n\nconst toEscape = (char: string): string => ESCAPES[char]!;\n\n// Most text has nothing to escape, so a test without the global flag skips the replace.\nexport function escape(value: string): string {\n return /[&<>]/.test(value) ? value.replace(/[&<>]/g, toEscape) : value;\n}\n\nexport function escapeAttribute(value: string): string {\n return /[&<\"]/.test(value) ? value.replace(/[&<\"]/g, toEscape) : value;\n}\n\n/** Renders a value inserted in markup. Promises are not awaited. */\nexport function insertValue(value: unknown): string {\n if (isRaw(value)) {\n return value[RAW];\n }\n if (value === null || value === undefined || typeof value === 'boolean') {\n return '';\n }\n if (Array.isArray(value)) {\n return value.map(insertValue).join('');\n }\n return escape(String(value));\n}\n\n/**\n * Renders a value as the text of an element whose content is text, such as\n * a `<textarea>`, as `insertValue` does but without escaping.\n */\nexport function textValue(value: unknown): string {\n if (isRaw(value)) {\n return value[RAW];\n }\n if (value === null || value === undefined || typeof value === 'boolean') {\n return '';\n }\n if (Array.isArray(value)) {\n return value.map(textValue).join('');\n }\n return String(value);\n}\n\nfunction toKebabCase(name: string): string {\n return name.startsWith('--') ? name : name.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);\n}\n\nexport function classValue(value: unknown): string {\n if (typeof value !== 'object' || value === null) {\n return value ? String(value) : '';\n }\n let text = '';\n if (Array.isArray(value)) {\n for (const item of value) {\n const part = classValue(item);\n if (part !== '') {\n text = text === '' ? part : `${text} ${part}`;\n }\n }\n return text;\n }\n // An empty name still adds a space between its neighbours, as in a join.\n let first = true;\n for (const name in value) {\n if (Object.hasOwn(value, name) && (value as Record<string, unknown>)[name]) {\n text = first ? name : `${text} ${name}`;\n first = false;\n }\n }\n return text;\n}\n\n/**\n * Renders a `class` attribute from classes that each have a space before\n * them, which the compiler builds from a literal class value. The classes\n * are escaped already. No class renders nothing.\n */\nexport function classAttribute(classes: string): string {\n return classes === '' ? '' : ` class=\"${classes.slice(1)}\"`;\n}\n\nfunction styleValue(value: unknown): string {\n if (typeof value === 'object' && value !== null) {\n return Object.entries(value)\n .filter(([, item]) => item !== null && item !== undefined && item !== false)\n .map(([name, item]) => `${toKebabCase(name)}:${String(item)}`)\n .join(';');\n }\n return String(value);\n}\n\n/** The brand of a binding of `$bind`, under the key of the registry. See `Binding`. */\nconst BOUND = Symbol.for('brumate.binding');\n\n/** The words of an attribute that says `true` or `false` in its value. */\nconst TRUE_FALSE = ['true', 'false'] as const;\n\n/**\n * Attributes whose two states are words in the value, not whether the\n * attribute is there, by their words for `true` and `false`. A missing\n * attribute means a third state, such as the default of the element, so\n * `false` must not remove it. `aria-*` and `data-*` are such attributes too.\n */\nconst SWITCHES = new Map<string, readonly [string, string]>([\n ['contenteditable', TRUE_FALSE],\n ['draggable', TRUE_FALSE],\n ['spellcheck', TRUE_FALSE],\n ['writingsuggestions', TRUE_FALSE],\n // SVG.\n ['focusable', TRUE_FALSE],\n ['translate', ['yes', 'no']],\n ['autocomplete', ['on', 'off']],\n ['autocorrect', ['on', 'off']],\n]);\n\n/** The words of `true` and `false` for an attribute that says them in its value, or undefined. */\nfunction switchWords(name: string): readonly [string, string] | undefined {\n const lower = name.toLowerCase();\n if (lower.startsWith('aria-') || lower.startsWith('data-')) {\n return TRUE_FALSE;\n }\n return SWITCHES.get(lower);\n}\n\n/**\n * Returns the text of an attribute, or undefined if the attribute is not\n * rendered.\n *\n * - `null` and `undefined` leave the attribute out.\n * - For an attribute whose value says its state, such as `aria-expanded`,\n * `draggable` or `translate`, `true` and `false` render as its words:\n * `\"true\"` and `\"false\"`, or `\"yes\"` and `\"no\"`, or `\"on\"` and `\"off\"`.\n * - For other attributes, such as `disabled`, `true` renders the attribute\n * without a value, and `false` leaves it out.\n */\nexport function attributeText(name: string, value: unknown): string | undefined {\n // `value=$bind(name)` on an element renders the value of the name.\n if (typeof value === 'object' && value !== null && BOUND in value) {\n value = (value as unknown as { value: unknown }).value;\n }\n if (value === null || value === undefined || typeof value === 'function') {\n return undefined;\n }\n if (typeof value === 'boolean') {\n const words = switchWords(name);\n if (words) {\n return value ? words[0] : words[1];\n }\n return value ? '' : undefined;\n }\n if (name === 'class') {\n const text = classValue(value);\n return text === '' ? undefined : text;\n }\n return name === 'style' ? styleValue(value) : String(value);\n}\n\n/**\n * A name that HTML reads as one attribute. A spread takes its names from\n * data, so a name with a space, a quote, `>`, `/` or `=` could write other\n * attributes or markup.\n */\n// oxlint-disable-next-line no-control-regex -- HTML reads no control character in a name.\nconst ATTRIBUTE_NAME = /^[^\\s\"'>/=\\x00-\\x1f\\x7f]+$/;\n\n/** Renders one attribute, with a leading space. A name that is not one attribute renders nothing. */\nexport function attribute(name: string, value: unknown): string {\n const text = attributeText(name, value);\n if (text === undefined || !ATTRIBUTE_NAME.test(name)) {\n return '';\n }\n return value === true && text === '' ? ` ${name}` : ` ${name}=\"${escapeAttribute(text)}\"`;\n}\n\n/**\n * Returns the value of a style variable with text around it, such as `12px`\n * for `${size}px`. A value that sets no variable stays as it is.\n */\nexport function affix(prefix: string, value: unknown, suffix: string): unknown {\n return value === null || value === undefined || value === false\n ? value\n : `${prefix}${String(value)}${suffix}`;\n}\n\n/** Returns a style with custom properties before an element's own style. */\nexport function vars(variables: Record<string, unknown>, own: unknown): string {\n const parts: string[] = [];\n for (const [name, value] of Object.entries(variables)) {\n if (value !== null && value !== undefined && value !== false) {\n parts.push(`${name}:${String(value)}`);\n }\n }\n const rest = own === null || own === undefined || own === false ? '' : styleValue(own);\n if (rest) {\n parts.push(rest);\n }\n return parts.join(';');\n}\n\n/** Returns a `<style>` element for a component's stylesheet. */\nexport function styleElement(id: string, css: string): string {\n return `<style b-style=\"${escapeAttribute(id)}\">${css.replace(/<\\/style/gi, '<\\\\/style')}</style>`;\n}\n\n/**\n * Merges the attributes of an element that has spreads, in their order: a\n * later value wins, except `class`, whose values all apply.\n */\nexport function mergeAttributes(parts: Record<string, unknown>[]): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const part of parts) {\n for (const [name, value] of Object.entries(part ?? {})) {\n result[name] =\n name === 'class' && result.class !== undefined && value !== undefined\n ? [result.class, value]\n : value;\n }\n }\n return result;\n}\n\n/**\n * The `b-on` entry of a handler that a spread passes on, such as\n * `click:prevent=Parent#h1@3`: its event, the modifiers of its wrappers, its\n * client function and the scope it runs in. A handler that `$handler` made\n * has its arguments after another `@`, encoded so that they hold no space.\n */\nexport function handlerEntry(\n name: string,\n ref: string,\n scope: number | string,\n modifiers: readonly string[] = [],\n args?: unknown[],\n): string {\n const bound = args === undefined ? '' : `@${encodeURIComponent(JSON.stringify(args))}`;\n return `${[name.slice(2).toLowerCase(), ...modifiers].join(':')}=${ref}@${scope}${bound}`;\n}\n\n/**\n * The `b-on` entry of a binding that a spread puts on `value` or `checked`\n * of an element. It names the scope of the slot, or of the setter of\n * `$bind(name, fn)`, after `@`. A box writes on `change`.\n */\nexport function bindEntry(\n name: string,\n ref: { scope: number | string; slot: number },\n setter?: { ref: string; scope: number | string },\n): string {\n const event = name === 'checked' ? 'change' : 'input';\n return setter\n ? `${event}=$set:${setter.ref}@${setter.scope}`\n : `${event}=$bind#0.${ref.slot}@${ref.scope}`;\n}\n\n/**\n * The `b-on` attribute of an element with spreads: the bindings of its\n * spreads, so its handlers read the new value, then its own handlers, then\n * those of its spreads.\n */\nexport function onAttribute(on: string[], own: string): string {\n const bindings = on.filter((entry) => /=\\$(bind#|set:)/.test(entry));\n const value = [...bindings, own, ...on.filter((entry) => !bindings.includes(entry))]\n .filter(Boolean)\n .join(' ');\n return value ? ` b-on=\"${escapeAttribute(value)}\"` : '';\n}\n\n/** Renders an object of attributes. */\nexport function spread(attributes: Record<string, unknown>): string {\n let result = '';\n for (const [name, value] of Object.entries(attributes)) {\n if (name !== 'children' && !/^on[A-Z]/.test(name)) {\n result += attribute(name, value);\n }\n }\n return result;\n}\n\nexport const VOID_ELEMENTS: Set<string> = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'source',\n 'track',\n 'wbr',\n]);\n\n/**\n * Renders the attributes of a form that posts to a server function, such as\n * ` action=\"/_brumate/App_1abc%23save\" method=\"post\"`. `method` is the name of\n * the method attribute to add, if the element has none. `build` is the ID\n * of the build of the page, which the URL carries as `__build`, so the\n * server can tell a post from before a deploy without scripts.\n */\nexport function actionAttributes(\n prefix: string,\n name: string,\n id: string,\n method?: string,\n result?: string,\n build?: string,\n key?: string,\n): string {\n const methodText = method ? ` ${method}=\"post\"` : '';\n // The key of a form of a function that `idempotent` made, so a second post gets the first result.\n const query = [\n build === undefined ? '' : `__build=${encodeURIComponent(build)}`,\n key === undefined ? '' : `__key=${key}`,\n ]\n .filter(Boolean)\n .join('&');\n if (result !== undefined) {\n // The form posts to its page, which renders with the result. With the\n // loader, the result is written into the `$action` at `result` instead.\n const url = `?__action=${encodeURIComponent(id)}${query ? `&${query}` : ''}`;\n return ` ${name}=\"${escapeAttribute(url)}\"${methodText} b-action=\"${escapeAttribute(id)}\" b-result=\"${escapeAttribute(result)}\"`;\n }\n const url = `${prefix}/${encodeURIComponent(id)}${query ? `?${query}` : ''}`;\n return ` ${name}=\"${escapeAttribute(url)}\"${methodText}`;\n}\n"],"mappings":";AAEA,MAAM,MAAqB,OAAO,IAAI,aAAa;AAQnD,IAAM,UAAN,MAA6B;CAC3B,CAAU;CAEV,YAAY,MAAc;EACxB,KAAK,OAAO;CACd;AACF;AAEA,SAAgB,IAAI,MAAmB;CACrC,OAAO,IAAI,QAAQ,IAAI;AACzB;AAEA,SAAgB,MAAM,OAA8B;CAClD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO;AAC/D;AAEA,SAAgB,QAAQ,OAAoB;CAC1C,OAAO,MAAM;AACf;AAEA,MAAM,UAAkC;CAAE,KAAK;CAAS,KAAK;CAAQ,KAAK;CAAQ,MAAK;AAAS;AAEhG,MAAM,YAAY,SAAyB,QAAQ;AAGnD,SAAgB,OAAO,OAAuB;CAC5C,OAAO,QAAQ,KAAK,KAAK,IAAI,MAAM,QAAQ,UAAU,QAAQ,IAAI;AACnE;AAEA,SAAgB,gBAAgB,OAAuB;CACrD,OAAO,QAAQ,KAAK,KAAK,IAAI,MAAM,QAAQ,UAAU,QAAQ,IAAI;AACnE;;AAGA,SAAgB,YAAY,OAAwB;CAClD,IAAI,MAAM,KAAK,GACb,OAAO,MAAM;CAEf,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,OAAO,UAAU,WAC5D,OAAO;CAET,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,WAAW,CAAC,CAAC,KAAK,EAAE;CAEvC,OAAO,OAAO,OAAO,KAAK,CAAC;AAC7B;;;;;AAMA,SAAgB,UAAU,OAAwB;CAChD,IAAI,MAAM,KAAK,GACb,OAAO,MAAM;CAEf,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,OAAO,UAAU,WAC5D,OAAO;CAET,IAA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AG,mBAAmB,EAAE,IAAI,QAAQ,IAAI,UAAU,IACjC,EAAE,GAAG;AAC9C"}
package/dist/index.d.ts CHANGED
@@ -1372,6 +1372,18 @@ interface DynamicTagNode extends Range {
1372
1372
  interface FragmentNode extends Range {
1373
1373
  kind: "fragment";
1374
1374
  children: Markup[];
1375
+ /**
1376
+ * For `#reveal`: the order in which the server shows the `#loading` bodies
1377
+ * inside, and whether only the next fallback shows. Elsewhere the children
1378
+ * render as they are.
1379
+ */
1380
+ reveal?: Reveal;
1381
+ }
1382
+ /** The order of `#reveal`, as its header writes it. */
1383
+ type RevealOrder = "sequential" | "backwards" | "together" | "natural";
1384
+ interface Reveal {
1385
+ order: RevealOrder;
1386
+ collapsed: boolean;
1375
1387
  }
1376
1388
  interface GlobalListenerNode extends Range {
1377
1389
  kind: "listener";
@@ -1587,8 +1599,13 @@ interface Declaration {
1587
1599
  };
1588
1600
  /** For `let name = $signal(value)`, the value. */
1589
1601
  init?: Node;
1590
- /** True for a memo declared with `$optimistic`, before its source is known. */
1602
+ /**
1603
+ * True for a memo declared with `$optimistic`, before its source is known,
1604
+ * and for a prop that the component destructures with `let`.
1605
+ */
1591
1606
  writable?: boolean;
1607
+ /** True for a signal or a writable prop that `$bind` passes to a child, which needs a slot. */
1608
+ bound?: boolean;
1592
1609
  /** True for `const name = await $memo(value)`: the render waits for the memo where it is declared. */
1593
1610
  awaited?: boolean;
1594
1611
  /** For `const name = $id()`, the position of the call among the `$id` calls of its scope. */
@@ -1652,6 +1669,13 @@ interface Site {
1652
1669
  awaits: boolean;
1653
1670
  /** More code of the site, such as the context of `$setContext(context, value)`. */
1654
1671
  extra?: Node[];
1672
+ /**
1673
+ * For the function of `$handler(fn, ...args)`, the call, which the server
1674
+ * turns into a reference that a spread can pass on, with its arguments.
1675
+ */
1676
+ handler?: CallExpression;
1677
+ /** For the function of `$bind(name, fn)`, the call, which passes it as the setter of the binding. */
1678
+ setter?: CallExpression;
1655
1679
  }
1656
1680
  type Severity = "error" | "warning";
1657
1681
  interface Diagnostic {
@@ -1665,6 +1689,13 @@ interface SemanticModel {
1665
1689
  scopes: Scope[];
1666
1690
  declarations: Declaration[];
1667
1691
  sites: Site[];
1692
+ /** The `$bind(name)` calls, with the declaration of their name. */
1693
+ /** The `$bind` calls, with the declaration of their name and the site of their setter. */
1694
+ bindings: {
1695
+ call: CallExpression;
1696
+ declaration: Declaration;
1697
+ setter?: Site;
1698
+ }[];
1668
1699
  diagnostics: Diagnostic[];
1669
1700
  }
1670
1701
  /** Returns true if `scope` is `ancestor` or inside it. */
@@ -1825,6 +1856,8 @@ interface Plan {
1825
1856
  bodyScopes: Map<Body, Scope>;
1826
1857
  /** The anchor index of a node within its scope. */
1827
1858
  anchors: Map<AnchorTarget, number>;
1859
+ /** The scope of each anchor, for the devtools, which find an element by its scope and anchor. */
1860
+ anchorScopes: Map<AnchorTarget, Scope>;
1828
1861
  /**
1829
1862
  * Inserts that are the only content of their element. They share the
1830
1863
  * element's anchor and update its children, so they have no markers.
@@ -1916,6 +1949,13 @@ interface CompileOptions {
1916
1949
  * server function calls `refresh` with it. The Vite plugin passes it.
1917
1950
  */
1918
1951
  serverImport?: (specifier: string, name: string) => string | undefined;
1952
+ /**
1953
+ * The names of the server functions that the project passes to
1954
+ * `refresh`, from `refreshedNames`. A memo that calls an imported server
1955
+ * function outside it renders on the server only. Without it, any imported
1956
+ * server function can be refreshed.
1957
+ */
1958
+ refreshed?: ReadonlySet<string>;
1919
1959
  /**
1920
1960
  * The names of the server environment variables that an import gives,
1921
1961
  * such as `import env from './env.ts'`, or undefined for other imports.
@@ -1923,6 +1963,11 @@ interface CompileOptions {
1923
1963
  * it for the imports that resolve to the env file.
1924
1964
  */
1925
1965
  envImport?: EnvImport;
1966
+ /**
1967
+ * Classes that the plugins of the serial entry send, such as `Money`, so a
1968
+ * signal can hold an instance. The Vite plugin reads them from the entry.
1969
+ */
1970
+ sendableClasses?: readonly string[];
1926
1971
  /**
1927
1972
  * Server function IDs use a hash of each function's name instead of the
1928
1973
  * name, so the browser does not see it. The Vite plugin sets it in builds.
@@ -2134,5 +2179,5 @@ export declare function inspect(source: string, options?: InspectOptions): {
2134
2179
  text: string;
2135
2180
  };
2136
2181
  //#endregion
2137
- export type { AnchorTarget, Attribute, Block, Body, Branch, CheckMapping, CheckOutput, ClientBlock, ClientTrigger, CompileOptions, CompileResult, ComponentNode, ComponentUsage, ComputedAttribute, Declaration, DeclarationKind, DeferBlock, Diagnostic, DynamicTagNode, Edge, ElementNode, EventAttribute, Expression, ForBlock, FragmentNode, GlobalListenerNode, Graph, GraphNode, GraphOptions, HeadBlock, IfBlock, InsertNode, InspectEntry, InspectOptions, InspectReport, KeyBlock, LoadingBlock, Location, Markup, Modifier, OffscreenBlock, ParseOptions, Plan, PortalBlock, PrefetchAttribute, PrefetchStrategy, ProjectProps, Range, ReactiveModule, RefAttribute, Reference, RepeatBlock, Resolve, ResolveModule, SFCFile, Scope, ScopeKind, ScopePlan, Script, SemanticModel, Severity, SharedSite, Site, SiteKind, SourceMap, SpreadAttribute, StaticAttribute, Style, SwitchBlock, TemplateDecl, TextNode, TryBlock, ValueAttribute, upstreamMemos };
2182
+ export type { AnchorTarget, Attribute, Block, Body, Branch, CheckMapping, CheckOutput, ClientBlock, ClientTrigger, CompileOptions, CompileResult, ComponentNode, ComponentUsage, ComputedAttribute, Declaration, DeclarationKind, DeferBlock, Diagnostic, DynamicTagNode, Edge, ElementNode, EventAttribute, Expression, ForBlock, FragmentNode, GlobalListenerNode, Graph, GraphNode, GraphOptions, HeadBlock, IfBlock, InsertNode, InspectEntry, InspectOptions, InspectReport, KeyBlock, LoadingBlock, Location, Markup, Modifier, OffscreenBlock, ParseOptions, Plan, PortalBlock, PrefetchAttribute, PrefetchStrategy, ProjectProps, Range, ReactiveModule, RefAttribute, Reference, RepeatBlock, Resolve, ResolveModule, Reveal, RevealOrder, SFCFile, Scope, ScopeKind, ScopePlan, Script, SemanticModel, Severity, SharedSite, Site, SiteKind, SourceMap, SpreadAttribute, StaticAttribute, Style, SwitchBlock, TemplateDecl, TextNode, TryBlock, ValueAttribute, upstreamMemos };
2138
2183
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as summarize, D as analyzeProjectProps, E as analyzeProject, F as analyze, I as isWithin, L as lookup, M as buildGraph, N as BrumateError, P as getLocation, T as unmarked, _ as getComponentName, a as CompileError, b as generateShared, c as generateClient$1, h as createPlan, j as parse, k as resolveRelative, l as generateRender$1, m as clientState, n as inspect, o as compile, p as blockBodies, r as report, t as formatReport, u as generateServer$1, x as sharedSites, y as SHARED_QUERY } from "./inspect-BJtACnQp.js";
1
+ import { A as analyzeProject, B as isWithin, D as unmarked, F as parse, I as buildGraph, L as BrumateError, N as resolveRelative, P as summarize, R as getLocation, S as sharedSites, V as lookup, b as SHARED_QUERY, d as generateServer$1, g as createPlan, h as clientState, i as report, j as analyzeProjectProps, l as generateClient$1, m as blockBodies, n as formatReport, o as CompileError, r as inspect, s as compile, u as generateRender$1, v as getComponentName, x as generateShared, z as analyze } from "./inspect-BHpOw1LF.js";
2
2
  //#region src/print.ts
3
3
  function at(source, range) {
4
4
  const { line, column } = getLocation(source, range.start);
@@ -109,7 +109,7 @@ function printAST(file) {
109
109
  nodes(item.children, depth + 1);
110
110
  break;
111
111
  case "fragment":
112
- write(depth, "fragment");
112
+ write(depth, item.reveal ? `reveal ('${item.reveal.order}'${item.reveal.collapsed ? ", collapsed" : ""})` : "fragment");
113
113
  nodes(item.children, depth + 1);
114
114
  break;
115
115
  case "listener":
@@ -240,7 +240,7 @@ declare function $$onWindow<K extends string>(event: K, handler: (event: $$Event
240
240
  declare function $$onDocument<K extends string>(event: K, handler: (event: $$Event<K, DocumentEventMap> & { currentTarget: Document }) => unknown): void;
241
241
  declare function $$use(...values: unknown[]): void;
242
242
  type $$Plain = string | number | boolean | bigint | null | undefined | Date | Error | URL | URLSearchParams | ArrayBuffer | ArrayBufferView | Headers | FormData | Request | Response | ReadableStream<any> | AbortSignal | Event | DOMException | ImageData;
243
- type $$Sendable<T> = T extends $$Plain ? T : T extends { brumateId: string } ? T : T extends RegExp ? { 'A regular expression cannot be sent to the client. Send its source and flags': never } : T extends (...args: any[]) => any ? { 'A function cannot be sent to the client. Keep it out of the signal or memo': never } : T extends Promise<infer U> ? Promise<$$Sendable<U>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<$$Sendable<K>, $$Sendable<V>> : T extends ReadonlySet<infer V> ? ReadonlySet<$$Sendable<V>> : T extends object ? { [K in keyof T]: $$Sendable<T[K]> } : T;
243
+ type $$Sendable<T> = T extends $$Plain | import('brumate/serial').AppValue ? T : T extends { brumateId: string } ? T : T extends RegExp ? { 'A regular expression cannot be sent to the client. Send its source and flags': never } : T extends (...args: any[]) => any ? { 'A function cannot be sent to the client. Keep it out of the signal or memo': never } : T extends Promise<infer U> ? Promise<$$Sendable<U>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<$$Sendable<K>, $$Sendable<V>> : T extends ReadonlySet<infer V> ? ReadonlySet<$$Sendable<V>> : T extends object ? { [K in keyof T]: $$Sendable<T[K]> } : T;
244
244
  /** Checks a value that the page state sends to the client. */
245
245
  declare function $$sendable<T>(value: T & $$Sendable<T>): void;
246
246
  `;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["server","render","client"],"sources":["../src/print.ts","../src/generate.ts","../src/check.ts"],"sourcesContent":["import type { Attribute, Block, Body, Markup, Range, SFCFile } from './ast.ts';\nimport { getLocation } from './error.ts';\nimport type { Graph, GraphNode } from './graph.ts';\nimport type { Diagnostic, Scope, SemanticModel, Site } from './model.ts';\n\nfunction at(source: string, range: Range): string {\n const { line, column } = getLocation(source, range.start);\n return `${line}:${column}`;\n}\n\nfunction quote(text: string): string {\n return JSON.stringify(text);\n}\n\nfunction printAttribute(item: Attribute): string {\n switch (item.kind) {\n case 'static':\n return item.value === true ? item.name : `${item.name}=${quote(item.value)}`;\n case 'value':\n return `${item.name}=(${item.value.code})`;\n case 'event':\n return `${item.name}${item.modifiers.map((modifier) => `:${modifier}`).join('')}=(${item.handler.code})`;\n case 'ref':\n return `ref=${item.target}`;\n case 'prefetch':\n return `prefetch=${quote(item.strategy)}`;\n case 'spread':\n return `{...${item.value.code}}`;\n case 'computed':\n return `[${item.name.code}]${item.value === true ? '' : `=(${item.value.code})`}`;\n }\n}\n\n/** Prints the syntax tree, one node per line. */\nexport function printAST(file: SFCFile): string {\n const lines: string[] = [];\n const write = (depth: number, text: string): void => {\n lines.push(`${' '.repeat(depth)}${text}`);\n };\n\n const body = (item: Body, depth: number, label: string): void => {\n write(depth, label);\n if (item.script) {\n write(depth + 1, 'script');\n }\n for (const template of item.templates) {\n write(depth + 1, `template ${template.name}`);\n body(template.body, depth + 2, 'body');\n }\n nodes(item.children, depth + 1);\n };\n\n const block = (item: Block, depth: number): void => {\n switch (item.kind) {\n case 'if':\n write(depth, 'if');\n for (const branch of item.branches) {\n body(branch.body, depth + 1, `branch (${branch.condition.code})`);\n }\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n case 'for': {\n const key =\n item.key === undefined ? '' : ` by ${item.key === 'index' ? 'index' : item.key.code}`;\n const index = item.index ? `, ${item.index.name}` : '';\n const itemCode = file.source.slice(item.item.start, item.item.end);\n write(depth, `for (${itemCode}${index} of ${item.list.code.trim()}${key})`);\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n }\n case 'repeat':\n write(\n depth,\n `repeat (${item.index ? `${item.index.name} of ` : ''}${item.count.code.trim()})`,\n );\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n case 'switch':\n write(depth, 'switch');\n for (const branch of item.cases) {\n body(branch.body, depth + 1, `case (${branch.condition.code})`);\n }\n if (item.fallback) {\n body(item.fallback, depth + 1, 'default');\n }\n break;\n case 'key':\n write(depth, `key (${item.value.code})`);\n body(item.body, depth + 1, 'body');\n break;\n case 'offscreen':\n write(depth, `offscreen (${item.visible.code})`);\n body(item.body, depth + 1, 'body');\n break;\n case 'try': {\n write(depth, 'try');\n body(item.body, depth + 1, 'body');\n const names = [item.error?.name, item.reset?.name].filter(Boolean).join(', ');\n body(item.fallback, depth + 1, names ? `catch (${names})` : 'catch');\n break;\n }\n case 'loading':\n write(depth, item.on ? `loading (${item.on.code})` : 'loading');\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n case 'head':\n write(depth, 'head');\n body(item.body, depth + 1, 'body');\n break;\n case 'portal':\n write(depth, item.target ? `portal (${item.target.code})` : 'portal');\n body(item.body, depth + 1, 'body');\n break;\n case 'client':\n case 'defer':\n write(depth, `${item.kind} (${item.trigger})`);\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n }\n };\n\n const node = (item: Markup, depth: number): void => {\n switch (item.kind) {\n case 'element':\n case 'component': {\n const name = item.kind === 'element' ? item.tag : item.name;\n const attributes = item.attributes.map((value) => ` ${printAttribute(value)}`).join('');\n write(depth, `${item.kind} <${name}${attributes}>`);\n nodes(item.children, depth + 1);\n break;\n }\n case 'dynamic':\n write(\n depth,\n `dynamic <{${item.tag.code}}${item.attributes.map((value) => ` ${printAttribute(value)}`).join('')}>`,\n );\n nodes(item.children, depth + 1);\n break;\n case 'fragment':\n write(depth, 'fragment');\n nodes(item.children, depth + 1);\n break;\n case 'listener':\n write(\n depth,\n `listener <${item.target}${item.attributes.map((value) => ` ${printAttribute(value)}`).join('')}>`,\n );\n break;\n case 'text':\n write(depth, `text ${quote(item.value)}`);\n break;\n case 'insert':\n write(depth, `insert {${item.expression.code}}`);\n break;\n default:\n block(item, depth);\n }\n };\n\n const nodes = (items: Markup[], depth: number): void => {\n for (const item of items) {\n node(item, depth);\n }\n };\n\n if (file.moduleScript) {\n write(0, 'script module');\n }\n if (file.instanceScript) {\n write(0, file.generics ? `script generics=${quote(file.generics)}` : 'script');\n }\n for (const style of file.styles) {\n write(0, `style ${style.lang}`);\n for (const variable of style.variables) {\n write(1, `variable (${variable.code})`);\n }\n }\n for (const template of file.templates) {\n write(0, `template ${template.name}`);\n body(template.body, 1, 'body');\n }\n nodes(file.children, 0);\n return lines.join('\\n');\n}\n\nfunction scopeLabel(source: string, scope: Scope): string {\n if (scope.kind === 'body' && scope.block) {\n return `${scope.id} body (${scope.block.kind} ${at(source, scope.block)})`;\n }\n if (scope.kind === 'template' && scope.template) {\n return `${scope.id} template ${scope.template.name}`;\n }\n return `${scope.id} ${scope.kind}`;\n}\n\nfunction siteLabel(source: string, site: Site): string {\n return `${site.label} (${at(source, site.range)})`;\n}\n\nfunction printDiagnostics(source: string, diagnostics: Diagnostic[], lines: string[]): void {\n if (diagnostics.length === 0) {\n return;\n }\n lines.push('diagnostics');\n for (const diagnostic of diagnostics) {\n lines.push(` ${diagnostic.severity} ${diagnostic.message} (${at(source, diagnostic.range)})`);\n }\n}\n\n/** Prints scopes, declarations, sites and diagnostics. */\nexport function printModel(source: string, model: SemanticModel): string {\n const lines: string[] = [];\n for (const scope of model.scopes) {\n lines.push(`scope ${scopeLabel(source, scope)}`);\n for (const declaration of scope.declarations.values()) {\n lines.push(` ${declaration.kind} ${declaration.name}`);\n }\n }\n lines.push('sites');\n for (const site of model.sites) {\n const parts = [siteLabel(source, site)];\n const reads = [\n ...new Set(site.reads.map((read) => (read.tracked ? '' : '~') + read.declaration.name)),\n ];\n const writes = [...new Set(site.writes.map((write) => write.declaration.name))];\n const calls = [...site.calls].map((declaration) => declaration.name);\n if (reads.length > 0) {\n parts.push(`reads ${reads.join(', ')}`);\n }\n if (writes.length > 0) {\n parts.push(`writes ${writes.join(', ')}`);\n }\n if (calls.length > 0) {\n parts.push(`calls ${calls.join(', ')}`);\n }\n lines.push(` ${parts.join(' ')}`);\n }\n printDiagnostics(source, model.diagnostics, lines);\n return lines.join('\\n');\n}\n\nfunction nodeLabel(source: string, node: GraphNode): string {\n switch (node.kind) {\n case 'source':\n return `${node.declaration.kind} ${node.declaration.name}`;\n case 'memo':\n return `${node.declaration.kind} ${node.declaration.name}`;\n default:\n return siteLabel(source, node.site);\n }\n}\n\n/** Prints the graph: nodes, what is live, what runs on the client and which scopes it creates. */\nexport function printGraph(source: string, graph: Graph): string {\n const lines: string[] = ['nodes'];\n for (const node of graph.nodes) {\n const from = graph.edges\n .filter((edge) => edge.to === node)\n .map((edge) => nodeLabel(source, edge.from));\n const state = graph.live.has(node) ? 'live' : 'static';\n lines.push(\n ` ${nodeLabel(source, node)} ${state}${from.length > 0 ? ` <- ${from.join(', ')}` : ''}`,\n );\n }\n lines.push('client');\n for (const site of graph.model.sites) {\n if (graph.reached.has(site)) {\n lines.push(` ${siteLabel(source, site)}${site.kind === 'server-function' ? ' (stub)' : ''}`);\n }\n }\n const created = graph.model.scopes.filter((scope) => graph.created.has(scope));\n if (created.length > 0) {\n lines.push('created');\n for (const scope of created) {\n lines.push(` ${scopeLabel(source, scope)}`);\n }\n }\n printDiagnostics(source, [...graph.model.diagnostics, ...graph.diagnostics], lines);\n return lines.join('\\n');\n}\n","// The code generators, for callers that compile without `compile`. Their\n// output carries the marks that `compile` turns into source maps, so these\n// remove them.\n\nimport type { SFCFile } from './ast.ts';\nimport { generateClient as client } from './codegen/client.ts';\nimport { generateRender as render } from './codegen/render.ts';\nimport { generateServer as server } from './codegen/server.ts';\nimport type { Plan } from './plan.ts';\nimport { unmarked } from './sourcemap.ts';\n\n/** Generates the server module. */\nexport function generateServer(file: SFCFile, plan: Plan): string {\n return unmarked(server(file, plan));\n}\n\n/** Generates the render module. */\nexport function generateRender(file: SFCFile, plan: Plan): string {\n return unmarked(render(file, plan));\n}\n\n/** Generates the client entry and its parts. */\nexport function generateClient(\n file: SFCFile,\n plan: Plan,\n merge?: number,\n): ReturnType<typeof client> {\n const result = client(file, plan, merge);\n return {\n ...result,\n code: unmarked(result.code),\n parts: Object.fromEntries(\n Object.entries(result.parts).map(([name, code]) => [name, unmarked(code)]),\n ),\n };\n}\n","// Turns a `.brm` file into TypeScript, so a type checker and an editor can\n// check it. The scripts and every expression of the markup are copied, with\n// mappings back to the file. The markup becomes statements in blocks that\n// match its control flow, so names are in scope where the markup reads them.\n\nimport type {\n Attribute,\n Block,\n Body,\n ComponentNode,\n Expression,\n Markup,\n Range,\n SFCFile,\n TemplateDecl,\n} from './ast.ts';\nimport { BrumateError } from './error.ts';\nimport type { oxc } from './oxc.ts';\nimport { parse } from './parser.ts';\nimport { analyze } from './analyze.ts';\nimport { buildGraph } from './graph.ts';\nimport type { Declaration } from './model.ts';\nimport { blockBodies, clientState } from './plan.ts';\n\n/**\n * The name of the component function. A file can import the name that its\n * file name gives the component, such as `SignIn` in `sign-in.brm`.\n */\nconst COMPONENT = '$$Component';\n\n/** A range of the generated code that is copied from the file. */\nexport interface CheckMapping {\n /** Offset in the `.brm` file. */\n source: number;\n /** Offset in the generated code. */\n generated: number;\n length: number;\n}\n\nexport interface CheckOutput {\n code: string;\n mappings: CheckMapping[];\n /** The syntax error of the file. The code then holds only its scripts. */\n error?: BrumateError;\n}\n\n/**\n * Declarations that the generated code calls to check the markup. They are\n * local to each generated file.\n */\nconst HELPERS = `/// <reference types=\"brumate/types\" />\ntype $$Component<P> = (props: P, ...rest: any[]) => unknown;\ndeclare function $$component<P>(component: $$Component<P>, props: P): void;\ndeclare function $$dynamic(tag: string | $$Component<any>, props: Record<string, unknown>): void;\ntype $$Event<K, M> = K extends keyof M ? M[K] : Event;\ntype $$Element<T> = T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : T extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[T] : HTMLElement;\ndeclare function $$on<T extends string, K extends string>(tag: T, event: K, handler: (event: $$Event<K, HTMLElementEventMap> & { currentTarget: $$Element<T> }) => unknown): void;\ndeclare function $$onWindow<K extends string>(event: K, handler: (event: $$Event<K, WindowEventMap> & { currentTarget: Window }) => unknown): void;\ndeclare function $$onDocument<K extends string>(event: K, handler: (event: $$Event<K, DocumentEventMap> & { currentTarget: Document }) => unknown): void;\ndeclare function $$use(...values: unknown[]): void;\ntype $$Plain = string | number | boolean | bigint | null | undefined | Date | Error | URL | URLSearchParams | ArrayBuffer | ArrayBufferView | Headers | FormData | Request | Response | ReadableStream<any> | AbortSignal | Event | DOMException | ImageData;\ntype $$Sendable<T> = T extends $$Plain ? T : T extends { brumateId: string } ? T : T extends RegExp ? { 'A regular expression cannot be sent to the client. Send its source and flags': never } : T extends (...args: any[]) => any ? { 'A function cannot be sent to the client. Keep it out of the signal or memo': never } : T extends Promise<infer U> ? Promise<$$Sendable<U>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<$$Sendable<K>, $$Sendable<V>> : T extends ReadonlySet<infer V> ? ReadonlySet<$$Sendable<V>> : T extends object ? { [K in keyof T]: $$Sendable<T[K]> } : T;\n/** Checks a value that the page state sends to the client. */\ndeclare function $$sendable<T>(value: T & $$Sendable<T>): void;\n`;\n\nclass Writer {\n code = '';\n readonly mappings: CheckMapping[] = [];\n private readonly source: string;\n\n constructor(source: string) {\n this.source = source;\n }\n\n text(value: string): void {\n this.code += value;\n }\n\n /** Copies a range of the file, and maps it. */\n copy(range: Range): void {\n if (range.end > range.start) {\n this.mappings.push({\n source: range.start,\n generated: this.code.length,\n length: range.end - range.start,\n });\n }\n this.code += this.source.slice(range.start, range.end);\n }\n\n /** Writes text in place of a range of the file of the same length, and maps it there. */\n stand(range: Range, text: string): void {\n this.mappings.push({ source: range.start, generated: this.code.length, length: text.length });\n this.code += text;\n }\n\n /** Copies an expression in parentheses. */\n expression(expression: Expression): void {\n this.text('(');\n this.copy(expression);\n this.text(')');\n }\n}\n\nfunction isTopLevel(statement: oxc.Node): boolean {\n return (\n statement.type === 'ImportDeclaration' ||\n statement.type === 'TSTypeAliasDeclaration' ||\n statement.type === 'TSInterfaceDeclaration' ||\n (statement.type === 'ExportNamedDeclaration' &&\n (statement.exportKind === 'type' ||\n statement.declaration?.type === 'TSTypeAliasDeclaration' ||\n statement.declaration?.type === 'TSInterfaceDeclaration'))\n );\n}\n\n/** Finds the type argument of `$props<T>()`, as a range of the file. */\nfunction propsType(program: oxc.Program | undefined): Range | undefined {\n let found: Range | undefined;\n const visit = (node: unknown): void => {\n if (found || typeof node !== 'object' || node === null) {\n return;\n }\n const value = node as oxc.Node & {\n callee?: oxc.Node & { name?: string };\n typeArguments?: { params: Range[] };\n };\n if (\n value.type === 'CallExpression' &&\n value.callee?.type === 'Identifier' &&\n value.callee.name === '$props' &&\n value.typeArguments?.params[0]\n ) {\n found = value.typeArguments.params[0];\n return;\n }\n for (const child of Object.values(value)) {\n if (Array.isArray(child)) {\n child.forEach(visit);\n } else if (typeof child === 'object') {\n visit(child);\n }\n }\n };\n visit(program);\n return found;\n}\n\n/**\n * Returns the signals and memos whose values the page state sends to the\n * client, because client code reads them. Element refs are sent as\n * references, so they are left out.\n */\nfunction sentDeclarations(file: SFCFile): Declaration[] {\n try {\n const { slots } = clientState(buildGraph(analyze(file)));\n return [...slots.values()]\n .flat()\n .filter(\n (declaration) =>\n (declaration.kind === 'signal' ||\n declaration.kind === 'memo' ||\n declaration.kind === 'async-memo') &&\n declaration.refs.length === 0,\n );\n } catch {\n // A file that the analyzer cannot read is still checked as TypeScript.\n return [];\n }\n}\n\nclass Generator {\n private readonly file: SFCFile;\n private readonly out: Writer;\n private readonly hoisted: oxc.Node[] = [];\n private readonly sent: Declaration[];\n\n constructor(file: SFCFile, out: Writer) {\n this.file = file;\n this.out = out;\n this.sent = sentDeclarations(file);\n }\n\n /** Copies a statement, and checks the values it declares that the client receives. */\n private statement(statement: oxc.Node): void {\n const { out } = this;\n out.copy(statement);\n out.text('\\n');\n for (const declaration of this.sent) {\n if (declaration.range.start >= statement.start && declaration.range.end <= statement.end) {\n out.text('$$sendable(');\n out.copy(declaration.range);\n out.text(');\\n');\n }\n }\n }\n\n generate(): void {\n const { file, out } = this;\n out.text(HELPERS);\n for (const statement of file.moduleScript?.program.body ?? []) {\n out.copy(statement);\n out.text('\\n');\n }\n const body = file.instanceScript?.program.body ?? [];\n for (const statement of body) {\n if (isTopLevel(statement)) {\n out.copy(statement);\n out.text('\\n');\n }\n }\n // Imports in the scripts of blocks are module imports too.\n this.collectBodyImports(file.children);\n for (const statement of this.hoisted) {\n out.copy(statement);\n out.text('\\n');\n }\n const type = propsType(file.instanceScript?.program);\n // The function has a name of its own, so the component name of the file can be imported.\n out.text(`\\nexport default ${COMPONENT};\\nasync function ${COMPONENT}`);\n if (file.generics) {\n out.text(`<${file.generics}>`);\n }\n out.text('($$props: ');\n if (type) {\n out.copy(type);\n } else {\n out.text('Record<string, any>');\n }\n out.text(\", $$ctx?: import('brumate/server').Context): Promise<string> {\\n\");\n out.text('$$use($$props, $$ctx);\\n');\n for (const statement of body) {\n if (!isTopLevel(statement)) {\n this.statement(statement);\n }\n }\n for (const style of file.styles) {\n for (const variable of style.variables) {\n out.text('$$use(');\n out.expression(variable);\n out.text(');\\n');\n }\n }\n this.templates(file.templates);\n this.nodes(file.children);\n out.text(\"return '';\\n}\\n\");\n // Components are sent to the client by their ID, as the compiled ones are.\n out.text(`${COMPONENT}.brumateId = '';\\n`);\n }\n\n private collectBodyImports(nodes: Markup[]): void {\n for (const node of nodes) {\n if ('children' in node) {\n this.collectBodyImports(node.children);\n }\n if (isBlock(node)) {\n for (const body of blockBodies(node)) {\n for (const statement of body.script?.program.body ?? []) {\n if (statement.type === 'ImportDeclaration') {\n this.hoisted.push(statement);\n }\n }\n this.collectBodyImports(body.children);\n for (const template of body.templates) {\n this.collectBodyImports(template.body.children);\n }\n }\n }\n }\n for (const template of this.file.templates) {\n if (nodes === this.file.children) {\n this.collectBodyImports(template.body.children);\n }\n }\n }\n\n private templates(templates: TemplateDecl[]): void {\n const { out } = this;\n for (const template of templates) {\n // Templates can await memos, as the component function can.\n out.text('async function ');\n out.copy(template.nameRange);\n out.text('(');\n if (template.params.length > 0) {\n out.copy({ start: template.params[0]!.start, end: template.params.at(-1)!.end });\n }\n out.text(') {\\n');\n this.body(template.body);\n out.text('}\\n');\n }\n }\n\n private body(body: Body): void {\n for (const statement of body.script?.program.body ?? []) {\n if (statement.type !== 'ImportDeclaration') {\n this.statement(statement);\n }\n }\n this.templates(body.templates);\n this.nodes(body.children);\n }\n\n private nodes(nodes: Markup[]): void {\n for (const node of nodes) {\n this.node(node);\n }\n }\n\n private node(node: Markup): void {\n const { out } = this;\n switch (node.kind) {\n case 'text':\n return;\n case 'insert':\n out.text('$$use(');\n out.expression(node.expression);\n out.text(');\\n');\n return;\n case 'element':\n this.elementAttributes(node.tag, node.attributes);\n this.nodes(node.children);\n return;\n case 'component':\n this.component(node);\n this.nodes(node.children);\n return;\n case 'dynamic':\n out.text('$$dynamic(');\n out.expression(node.tag);\n out.text(', {');\n this.props(node.attributes);\n out.text('});\\n');\n this.nodes(node.children);\n return;\n case 'fragment':\n this.nodes(node.children);\n return;\n case 'listener': {\n const helper = node.target === 'window' ? '$$onWindow' : '$$onDocument';\n for (const attribute of node.attributes) {\n out.text(`${helper}(${JSON.stringify(attribute.event)}, `);\n out.expression(attribute.handler);\n out.text(');\\n');\n }\n return;\n }\n default:\n this.block(node);\n }\n }\n\n private elementAttributes(tag: string, attributes: Attribute[]): void {\n const { out } = this;\n for (const attribute of attributes) {\n switch (attribute.kind) {\n case 'value':\n case 'spread':\n out.text('$$use(');\n out.expression(attribute.value);\n out.text(');\\n');\n break;\n case 'event':\n out.text(`$$on(${JSON.stringify(tag)}, ${JSON.stringify(attribute.event)}, `);\n out.expression(attribute.handler);\n out.text(');\\n');\n break;\n case 'ref':\n out.text('$$use(');\n out.copy(attribute.targetRange);\n out.text(');\\n');\n break;\n case 'computed':\n out.text('$$use(');\n out.expression(attribute.name);\n if (attribute.value !== true) {\n out.text(', ');\n out.expression(attribute.value);\n }\n out.text(');\\n');\n break;\n default:\n break;\n }\n }\n }\n\n /** Writes a prop name, mapped to the attribute, so errors about the prop point at it. */\n private propName(attribute: Range & { name: string }): void {\n const { out } = this;\n out.text(' ');\n if (/^[A-Za-z_$][\\w$]*$/.test(attribute.name)) {\n out.copy({ start: attribute.start, end: attribute.start + attribute.name.length });\n } else {\n out.text(JSON.stringify(attribute.name));\n }\n out.text(': ');\n }\n\n /** Writes the attributes of a component or a dynamic tag as the properties of an object. */\n private props(attributes: Attribute[], children = false): void {\n const { out } = this;\n for (const attribute of attributes) {\n switch (attribute.kind) {\n case 'static':\n this.propName(attribute);\n out.text(`${attribute.value === true ? 'true' : JSON.stringify(attribute.value)},`);\n break;\n case 'value':\n this.propName(attribute);\n out.expression(attribute.value);\n out.text(',');\n break;\n case 'event':\n this.propName(attribute);\n out.expression(attribute.handler);\n out.text(',');\n break;\n case 'spread':\n out.text(' ...');\n out.expression(attribute.value);\n out.text(',');\n break;\n default:\n break;\n }\n }\n if (children) {\n out.text(' children: undefined as any,');\n }\n }\n\n private component(node: ComponentNode): void {\n const { out } = this;\n const nameStart = node.start + 1;\n out.text('$$component(');\n out.copy({ start: nameStart, end: nameStart + node.name.length });\n out.text(', ');\n // A missing prop is reported on the object, so its brace stands for the `<` of the tag.\n out.stand({ start: node.start, end: node.start + 1 }, '{');\n this.props(node.attributes, node.children.length > 0);\n // The closing brace stands for the end of the opening tag, so the error spans the tag.\n out.text(' ');\n out.stand({ start: this.openTagEnd(node) - 1, end: this.openTagEnd(node) }, '}');\n out.text(');\\n');\n }\n\n /** The offset after the `>` that ends the opening tag of a component. */\n private openTagEnd(node: ComponentNode): number {\n const last = node.attributes.at(-1)?.end ?? node.start + 1 + node.name.length;\n return this.file.source.indexOf('>', last) + 1;\n }\n\n private block(block: Block): void {\n const { out } = this;\n switch (block.kind) {\n case 'if':\n case 'switch': {\n const branches = block.kind === 'if' ? block.branches : block.cases;\n branches.forEach((branch, index) => {\n out.text(index === 0 ? 'if ' : ' else if ');\n out.expression(branch.condition);\n out.text(' {\\n');\n this.body(branch.body);\n out.text('}');\n });\n if (block.fallback) {\n out.text(' else {\\n');\n this.body(block.fallback);\n out.text('}');\n }\n out.text('\\n');\n return;\n }\n case 'for': {\n out.text('for (const ');\n out.copy(block.item);\n out.text(' of ');\n out.expression(block.list);\n out.text(') {\\n');\n if (block.index) {\n out.text('const ');\n out.copy(block.index);\n out.text(' = 0 as number;\\n');\n }\n if (block.key && block.key !== 'index') {\n out.text('$$use(');\n out.expression(block.key);\n out.text(');\\n');\n }\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n }\n case 'repeat': {\n out.text('for (let $$i = 0; $$i < ');\n out.expression(block.count);\n out.text('; $$i++) {\\n');\n if (block.index) {\n out.text('const ');\n out.copy(block.index);\n out.text(' = $$i;\\n');\n }\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n }\n case 'key':\n out.text('$$use(');\n out.expression(block.value);\n out.text(');\\n{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'offscreen':\n out.text('$$use(');\n out.expression(block.visible);\n out.text(');\\n{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'try':\n out.text('try {\\n');\n this.body(block.body);\n out.text('} catch (');\n if (block.error) {\n out.copy(block.error);\n } else {\n out.text('$$error');\n }\n out.text(') {\\n');\n if (block.reset) {\n out.text('const ');\n out.copy(block.reset);\n out.text(' = (): void => {};\\n');\n }\n this.body(block.fallback);\n out.text('}\\n');\n return;\n case 'loading':\n if (block.on) {\n out.text('$$use(');\n out.expression(block.on);\n out.text(');\\n');\n }\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n case 'portal':\n if (block.target) {\n out.text('$$use(');\n out.expression(block.target);\n out.text(');\\n');\n }\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'head':\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'client':\n case 'defer':\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n }\n }\n\n private fallback(body: Body | undefined): void {\n if (body) {\n this.out.text('{\\n');\n this.body(body);\n this.out.text('}\\n');\n }\n }\n}\n\nfunction isBlock(node: Markup): node is Block {\n return !['element', 'component', 'dynamic', 'fragment', 'listener', 'text', 'insert'].includes(\n node.kind,\n );\n}\n\n/** Finds the `<script>` blocks at the top level, without parsing the markup. */\nfunction scriptRanges(source: string): Range[] {\n const ranges: Range[] = [];\n for (const match of source.matchAll(/^<script(\\s[^>]*)?>([\\s\\S]*?)<\\/script\\s*>/gm)) {\n const start = match.index + match[0].indexOf('>') + 1;\n ranges.push({ start, end: start + match[2]!.length });\n }\n return ranges;\n}\n\n/**\n * Generates TypeScript for a `.brm` file. With a syntax error, the code holds\n * the scripts only, so they still get type information.\n */\nexport function toTypeScript(source: string, filename = 'Component.brm'): CheckOutput {\n const out = new Writer(source);\n let file: SFCFile;\n try {\n file = parse(source, { filename });\n } catch (error) {\n if (!(error instanceof BrumateError)) {\n throw error;\n }\n out.text(HELPERS);\n for (const range of scriptRanges(source)) {\n out.copy(range);\n out.text('\\n');\n }\n out.text(\n `export default async function ${COMPONENT}(..._: any[]): Promise<string> {\\n return '';\\n}\\n`,\n );\n return { code: out.code, mappings: out.mappings, error };\n }\n new Generator(file, out).generate();\n return { code: out.code, mappings: out.mappings };\n}\n"],"mappings":";;AAKA,SAAS,GAAG,QAAgB,OAAsB;CAChD,MAAM,EAAE,MAAM,WAAW,YAAY,QAAQ,MAAM,KAAK;CACxD,OAAO,GAAG,KAAK,GAAG;AACpB;AAEA,SAAS,MAAM,MAAsB;CACnC,OAAO,KAAK,UAAU,IAAI;AAC5B;AAEA,SAAS,eAAe,MAAyB;CAC/C,QAAQ,KAAK,MAAb;EACE,KAAK,UACH,OAAO,KAAK,UAAU,OAAO,KAAK,OAAO,GAAG,KAAK,KAAK,GAAG,MAAM,KAAK,KAAK;EAC3E,KAAK,SACH,OAAO,GAAG,KAAK,KAAK,IAAI,KAAK,MAAM,KAAK;EAC1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;GACxC,IAAI,KAAK,KAAK;GACd,IAAI,KAAK,IAAI;EACf;EACA,IAAI,KACF,iCAAiC,UAAU,oDAC7C;EACA,OAAO;GAAE,MAAM,IAAI;GAAM,UAAU,IAAI;GAAU;EAAM;CACzD;CACA,IAAI,UAAU,MAAM,GAAG,CAAC,CAAC,SAAS;CAClC,OAAO;EAAE,MAAM,IAAI;EAAM,UAAU,IAAI;CAAS;AAClD"}
1
+ {"version":3,"file":"index.js","names":["server","render","client"],"sources":["../src/print.ts","../src/generate.ts","../src/check.ts"],"sourcesContent":["import type { Attribute, Block, Body, Markup, Range, SFCFile } from './ast.ts';\nimport { getLocation } from './error.ts';\nimport type { Graph, GraphNode } from './graph.ts';\nimport type { Diagnostic, Scope, SemanticModel, Site } from './model.ts';\n\nfunction at(source: string, range: Range): string {\n const { line, column } = getLocation(source, range.start);\n return `${line}:${column}`;\n}\n\nfunction quote(text: string): string {\n return JSON.stringify(text);\n}\n\nfunction printAttribute(item: Attribute): string {\n switch (item.kind) {\n case 'static':\n return item.value === true ? item.name : `${item.name}=${quote(item.value)}`;\n case 'value':\n return `${item.name}=(${item.value.code})`;\n case 'event':\n return `${item.name}${item.modifiers.map((modifier) => `:${modifier}`).join('')}=(${item.handler.code})`;\n case 'ref':\n return `ref=${item.target}`;\n case 'prefetch':\n return `prefetch=${quote(item.strategy)}`;\n case 'spread':\n return `{...${item.value.code}}`;\n case 'computed':\n return `[${item.name.code}]${item.value === true ? '' : `=(${item.value.code})`}`;\n }\n}\n\n/** Prints the syntax tree, one node per line. */\nexport function printAST(file: SFCFile): string {\n const lines: string[] = [];\n const write = (depth: number, text: string): void => {\n lines.push(`${' '.repeat(depth)}${text}`);\n };\n\n const body = (item: Body, depth: number, label: string): void => {\n write(depth, label);\n if (item.script) {\n write(depth + 1, 'script');\n }\n for (const template of item.templates) {\n write(depth + 1, `template ${template.name}`);\n body(template.body, depth + 2, 'body');\n }\n nodes(item.children, depth + 1);\n };\n\n const block = (item: Block, depth: number): void => {\n switch (item.kind) {\n case 'if':\n write(depth, 'if');\n for (const branch of item.branches) {\n body(branch.body, depth + 1, `branch (${branch.condition.code})`);\n }\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n case 'for': {\n const key =\n item.key === undefined ? '' : ` by ${item.key === 'index' ? 'index' : item.key.code}`;\n const index = item.index ? `, ${item.index.name}` : '';\n const itemCode = file.source.slice(item.item.start, item.item.end);\n write(depth, `for (${itemCode}${index} of ${item.list.code.trim()}${key})`);\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n }\n case 'repeat':\n write(\n depth,\n `repeat (${item.index ? `${item.index.name} of ` : ''}${item.count.code.trim()})`,\n );\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n case 'switch':\n write(depth, 'switch');\n for (const branch of item.cases) {\n body(branch.body, depth + 1, `case (${branch.condition.code})`);\n }\n if (item.fallback) {\n body(item.fallback, depth + 1, 'default');\n }\n break;\n case 'key':\n write(depth, `key (${item.value.code})`);\n body(item.body, depth + 1, 'body');\n break;\n case 'offscreen':\n write(depth, `offscreen (${item.visible.code})`);\n body(item.body, depth + 1, 'body');\n break;\n case 'try': {\n write(depth, 'try');\n body(item.body, depth + 1, 'body');\n const names = [item.error?.name, item.reset?.name].filter(Boolean).join(', ');\n body(item.fallback, depth + 1, names ? `catch (${names})` : 'catch');\n break;\n }\n case 'loading':\n write(depth, item.on ? `loading (${item.on.code})` : 'loading');\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n case 'head':\n write(depth, 'head');\n body(item.body, depth + 1, 'body');\n break;\n case 'portal':\n write(depth, item.target ? `portal (${item.target.code})` : 'portal');\n body(item.body, depth + 1, 'body');\n break;\n case 'client':\n case 'defer':\n write(depth, `${item.kind} (${item.trigger})`);\n body(item.body, depth + 1, 'body');\n if (item.fallback) {\n body(item.fallback, depth + 1, 'else');\n }\n break;\n }\n };\n\n const node = (item: Markup, depth: number): void => {\n switch (item.kind) {\n case 'element':\n case 'component': {\n const name = item.kind === 'element' ? item.tag : item.name;\n const attributes = item.attributes.map((value) => ` ${printAttribute(value)}`).join('');\n write(depth, `${item.kind} <${name}${attributes}>`);\n nodes(item.children, depth + 1);\n break;\n }\n case 'dynamic':\n write(\n depth,\n `dynamic <{${item.tag.code}}${item.attributes.map((value) => ` ${printAttribute(value)}`).join('')}>`,\n );\n nodes(item.children, depth + 1);\n break;\n case 'fragment':\n write(\n depth,\n item.reveal\n ? `reveal ('${item.reveal.order}'${item.reveal.collapsed ? ', collapsed' : ''})`\n : 'fragment',\n );\n nodes(item.children, depth + 1);\n break;\n case 'listener':\n write(\n depth,\n `listener <${item.target}${item.attributes.map((value) => ` ${printAttribute(value)}`).join('')}>`,\n );\n break;\n case 'text':\n write(depth, `text ${quote(item.value)}`);\n break;\n case 'insert':\n write(depth, `insert {${item.expression.code}}`);\n break;\n default:\n block(item, depth);\n }\n };\n\n const nodes = (items: Markup[], depth: number): void => {\n for (const item of items) {\n node(item, depth);\n }\n };\n\n if (file.moduleScript) {\n write(0, 'script module');\n }\n if (file.instanceScript) {\n write(0, file.generics ? `script generics=${quote(file.generics)}` : 'script');\n }\n for (const style of file.styles) {\n write(0, `style ${style.lang}`);\n for (const variable of style.variables) {\n write(1, `variable (${variable.code})`);\n }\n }\n for (const template of file.templates) {\n write(0, `template ${template.name}`);\n body(template.body, 1, 'body');\n }\n nodes(file.children, 0);\n return lines.join('\\n');\n}\n\nfunction scopeLabel(source: string, scope: Scope): string {\n if (scope.kind === 'body' && scope.block) {\n return `${scope.id} body (${scope.block.kind} ${at(source, scope.block)})`;\n }\n if (scope.kind === 'template' && scope.template) {\n return `${scope.id} template ${scope.template.name}`;\n }\n return `${scope.id} ${scope.kind}`;\n}\n\nfunction siteLabel(source: string, site: Site): string {\n return `${site.label} (${at(source, site.range)})`;\n}\n\nfunction printDiagnostics(source: string, diagnostics: Diagnostic[], lines: string[]): void {\n if (diagnostics.length === 0) {\n return;\n }\n lines.push('diagnostics');\n for (const diagnostic of diagnostics) {\n lines.push(` ${diagnostic.severity} ${diagnostic.message} (${at(source, diagnostic.range)})`);\n }\n}\n\n/** Prints scopes, declarations, sites and diagnostics. */\nexport function printModel(source: string, model: SemanticModel): string {\n const lines: string[] = [];\n for (const scope of model.scopes) {\n lines.push(`scope ${scopeLabel(source, scope)}`);\n for (const declaration of scope.declarations.values()) {\n lines.push(` ${declaration.kind} ${declaration.name}`);\n }\n }\n lines.push('sites');\n for (const site of model.sites) {\n const parts = [siteLabel(source, site)];\n const reads = [\n ...new Set(site.reads.map((read) => (read.tracked ? '' : '~') + read.declaration.name)),\n ];\n const writes = [...new Set(site.writes.map((write) => write.declaration.name))];\n const calls = [...site.calls].map((declaration) => declaration.name);\n if (reads.length > 0) {\n parts.push(`reads ${reads.join(', ')}`);\n }\n if (writes.length > 0) {\n parts.push(`writes ${writes.join(', ')}`);\n }\n if (calls.length > 0) {\n parts.push(`calls ${calls.join(', ')}`);\n }\n lines.push(` ${parts.join(' ')}`);\n }\n printDiagnostics(source, model.diagnostics, lines);\n return lines.join('\\n');\n}\n\nfunction nodeLabel(source: string, node: GraphNode): string {\n switch (node.kind) {\n case 'source':\n return `${node.declaration.kind} ${node.declaration.name}`;\n case 'memo':\n return `${node.declaration.kind} ${node.declaration.name}`;\n default:\n return siteLabel(source, node.site);\n }\n}\n\n/** Prints the graph: nodes, what is live, what runs on the client and which scopes it creates. */\nexport function printGraph(source: string, graph: Graph): string {\n const lines: string[] = ['nodes'];\n for (const node of graph.nodes) {\n const from = graph.edges\n .filter((edge) => edge.to === node)\n .map((edge) => nodeLabel(source, edge.from));\n const state = graph.live.has(node) ? 'live' : 'static';\n lines.push(\n ` ${nodeLabel(source, node)} ${state}${from.length > 0 ? ` <- ${from.join(', ')}` : ''}`,\n );\n }\n lines.push('client');\n for (const site of graph.model.sites) {\n if (graph.reached.has(site)) {\n lines.push(` ${siteLabel(source, site)}${site.kind === 'server-function' ? ' (stub)' : ''}`);\n }\n }\n const created = graph.model.scopes.filter((scope) => graph.created.has(scope));\n if (created.length > 0) {\n lines.push('created');\n for (const scope of created) {\n lines.push(` ${scopeLabel(source, scope)}`);\n }\n }\n printDiagnostics(source, [...graph.model.diagnostics, ...graph.diagnostics], lines);\n return lines.join('\\n');\n}\n","// The code generators, for callers that compile without `compile`. Their\n// output carries the marks that `compile` turns into source maps, so these\n// remove them.\n\nimport type { SFCFile } from './ast.ts';\nimport { generateClient as client } from './codegen/client.ts';\nimport { generateRender as render } from './codegen/render.ts';\nimport { generateServer as server } from './codegen/server.ts';\nimport type { Plan } from './plan.ts';\nimport { unmarked } from './sourcemap.ts';\n\n/** Generates the server module. */\nexport function generateServer(file: SFCFile, plan: Plan): string {\n return unmarked(server(file, plan));\n}\n\n/** Generates the render module. */\nexport function generateRender(file: SFCFile, plan: Plan): string {\n return unmarked(render(file, plan));\n}\n\n/** Generates the client entry and its parts. */\nexport function generateClient(\n file: SFCFile,\n plan: Plan,\n merge?: number,\n): ReturnType<typeof client> {\n const result = client(file, plan, merge);\n return {\n ...result,\n code: unmarked(result.code),\n parts: Object.fromEntries(\n Object.entries(result.parts).map(([name, code]) => [name, unmarked(code)]),\n ),\n };\n}\n","// Turns a `.brm` file into TypeScript, so a type checker and an editor can\n// check it. The scripts and every expression of the markup are copied, with\n// mappings back to the file. The markup becomes statements in blocks that\n// match its control flow, so names are in scope where the markup reads them.\n\nimport type {\n Attribute,\n Block,\n Body,\n ComponentNode,\n Expression,\n Markup,\n Range,\n SFCFile,\n TemplateDecl,\n} from './ast.ts';\nimport { BrumateError } from './error.ts';\nimport type { oxc } from './oxc.ts';\nimport { parse } from './parser.ts';\nimport { analyze } from './analyze.ts';\nimport { buildGraph } from './graph.ts';\nimport type { Declaration } from './model.ts';\nimport { blockBodies, clientState } from './plan.ts';\n\n/**\n * The name of the component function. A file can import the name that its\n * file name gives the component, such as `SignIn` in `sign-in.brm`.\n */\nconst COMPONENT = '$$Component';\n\n/** A range of the generated code that is copied from the file. */\nexport interface CheckMapping {\n /** Offset in the `.brm` file. */\n source: number;\n /** Offset in the generated code. */\n generated: number;\n length: number;\n}\n\nexport interface CheckOutput {\n code: string;\n mappings: CheckMapping[];\n /** The syntax error of the file. The code then holds only its scripts. */\n error?: BrumateError;\n}\n\n/**\n * Declarations that the generated code calls to check the markup. They are\n * local to each generated file.\n */\nconst HELPERS = `/// <reference types=\"brumate/types\" />\ntype $$Component<P> = (props: P, ...rest: any[]) => unknown;\ndeclare function $$component<P>(component: $$Component<P>, props: P): void;\ndeclare function $$dynamic(tag: string | $$Component<any>, props: Record<string, unknown>): void;\ntype $$Event<K, M> = K extends keyof M ? M[K] : Event;\ntype $$Element<T> = T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : T extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[T] : HTMLElement;\ndeclare function $$on<T extends string, K extends string>(tag: T, event: K, handler: (event: $$Event<K, HTMLElementEventMap> & { currentTarget: $$Element<T> }) => unknown): void;\ndeclare function $$onWindow<K extends string>(event: K, handler: (event: $$Event<K, WindowEventMap> & { currentTarget: Window }) => unknown): void;\ndeclare function $$onDocument<K extends string>(event: K, handler: (event: $$Event<K, DocumentEventMap> & { currentTarget: Document }) => unknown): void;\ndeclare function $$use(...values: unknown[]): void;\ntype $$Plain = string | number | boolean | bigint | null | undefined | Date | Error | URL | URLSearchParams | ArrayBuffer | ArrayBufferView | Headers | FormData | Request | Response | ReadableStream<any> | AbortSignal | Event | DOMException | ImageData;\ntype $$Sendable<T> = T extends $$Plain | import('brumate/serial').AppValue ? T : T extends { brumateId: string } ? T : T extends RegExp ? { 'A regular expression cannot be sent to the client. Send its source and flags': never } : T extends (...args: any[]) => any ? { 'A function cannot be sent to the client. Keep it out of the signal or memo': never } : T extends Promise<infer U> ? Promise<$$Sendable<U>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<$$Sendable<K>, $$Sendable<V>> : T extends ReadonlySet<infer V> ? ReadonlySet<$$Sendable<V>> : T extends object ? { [K in keyof T]: $$Sendable<T[K]> } : T;\n/** Checks a value that the page state sends to the client. */\ndeclare function $$sendable<T>(value: T & $$Sendable<T>): void;\n`;\n\nclass Writer {\n code = '';\n readonly mappings: CheckMapping[] = [];\n private readonly source: string;\n\n constructor(source: string) {\n this.source = source;\n }\n\n text(value: string): void {\n this.code += value;\n }\n\n /** Copies a range of the file, and maps it. */\n copy(range: Range): void {\n if (range.end > range.start) {\n this.mappings.push({\n source: range.start,\n generated: this.code.length,\n length: range.end - range.start,\n });\n }\n this.code += this.source.slice(range.start, range.end);\n }\n\n /** Writes text in place of a range of the file of the same length, and maps it there. */\n stand(range: Range, text: string): void {\n this.mappings.push({ source: range.start, generated: this.code.length, length: text.length });\n this.code += text;\n }\n\n /** Copies an expression in parentheses. */\n expression(expression: Expression): void {\n this.text('(');\n this.copy(expression);\n this.text(')');\n }\n}\n\nfunction isTopLevel(statement: oxc.Node): boolean {\n return (\n statement.type === 'ImportDeclaration' ||\n statement.type === 'TSTypeAliasDeclaration' ||\n statement.type === 'TSInterfaceDeclaration' ||\n (statement.type === 'ExportNamedDeclaration' &&\n (statement.exportKind === 'type' ||\n statement.declaration?.type === 'TSTypeAliasDeclaration' ||\n statement.declaration?.type === 'TSInterfaceDeclaration'))\n );\n}\n\n/** Finds the type argument of `$props<T>()`, as a range of the file. */\nfunction propsType(program: oxc.Program | undefined): Range | undefined {\n let found: Range | undefined;\n const visit = (node: unknown): void => {\n if (found || typeof node !== 'object' || node === null) {\n return;\n }\n const value = node as oxc.Node & {\n callee?: oxc.Node & { name?: string };\n typeArguments?: { params: Range[] };\n };\n if (\n value.type === 'CallExpression' &&\n value.callee?.type === 'Identifier' &&\n value.callee.name === '$props' &&\n value.typeArguments?.params[0]\n ) {\n found = value.typeArguments.params[0];\n return;\n }\n for (const child of Object.values(value)) {\n if (Array.isArray(child)) {\n child.forEach(visit);\n } else if (typeof child === 'object') {\n visit(child);\n }\n }\n };\n visit(program);\n return found;\n}\n\n/**\n * Returns the signals and memos whose values the page state sends to the\n * client, because client code reads them. Element refs are sent as\n * references, so they are left out.\n */\nfunction sentDeclarations(file: SFCFile): Declaration[] {\n try {\n const { slots } = clientState(buildGraph(analyze(file)));\n return [...slots.values()]\n .flat()\n .filter(\n (declaration) =>\n (declaration.kind === 'signal' ||\n declaration.kind === 'memo' ||\n declaration.kind === 'async-memo') &&\n declaration.refs.length === 0,\n );\n } catch {\n // A file that the analyzer cannot read is still checked as TypeScript.\n return [];\n }\n}\n\nclass Generator {\n private readonly file: SFCFile;\n private readonly out: Writer;\n private readonly hoisted: oxc.Node[] = [];\n private readonly sent: Declaration[];\n\n constructor(file: SFCFile, out: Writer) {\n this.file = file;\n this.out = out;\n this.sent = sentDeclarations(file);\n }\n\n /** Copies a statement, and checks the values it declares that the client receives. */\n private statement(statement: oxc.Node): void {\n const { out } = this;\n out.copy(statement);\n out.text('\\n');\n for (const declaration of this.sent) {\n if (declaration.range.start >= statement.start && declaration.range.end <= statement.end) {\n out.text('$$sendable(');\n out.copy(declaration.range);\n out.text(');\\n');\n }\n }\n }\n\n generate(): void {\n const { file, out } = this;\n out.text(HELPERS);\n for (const statement of file.moduleScript?.program.body ?? []) {\n out.copy(statement);\n out.text('\\n');\n }\n const body = file.instanceScript?.program.body ?? [];\n for (const statement of body) {\n if (isTopLevel(statement)) {\n out.copy(statement);\n out.text('\\n');\n }\n }\n // Imports in the scripts of blocks are module imports too.\n this.collectBodyImports(file.children);\n for (const statement of this.hoisted) {\n out.copy(statement);\n out.text('\\n');\n }\n const type = propsType(file.instanceScript?.program);\n // The function has a name of its own, so the component name of the file can be imported.\n out.text(`\\nexport default ${COMPONENT};\\nasync function ${COMPONENT}`);\n if (file.generics) {\n out.text(`<${file.generics}>`);\n }\n out.text('($$props: ');\n if (type) {\n out.copy(type);\n } else {\n out.text('Record<string, any>');\n }\n out.text(\", $$ctx?: import('brumate/server').Context): Promise<string> {\\n\");\n out.text('$$use($$props, $$ctx);\\n');\n for (const statement of body) {\n if (!isTopLevel(statement)) {\n this.statement(statement);\n }\n }\n for (const style of file.styles) {\n for (const variable of style.variables) {\n out.text('$$use(');\n out.expression(variable);\n out.text(');\\n');\n }\n }\n this.templates(file.templates);\n this.nodes(file.children);\n out.text(\"return '';\\n}\\n\");\n // Components are sent to the client by their ID, as the compiled ones are.\n out.text(`${COMPONENT}.brumateId = '';\\n`);\n }\n\n private collectBodyImports(nodes: Markup[]): void {\n for (const node of nodes) {\n if ('children' in node) {\n this.collectBodyImports(node.children);\n }\n if (isBlock(node)) {\n for (const body of blockBodies(node)) {\n for (const statement of body.script?.program.body ?? []) {\n if (statement.type === 'ImportDeclaration') {\n this.hoisted.push(statement);\n }\n }\n this.collectBodyImports(body.children);\n for (const template of body.templates) {\n this.collectBodyImports(template.body.children);\n }\n }\n }\n }\n for (const template of this.file.templates) {\n if (nodes === this.file.children) {\n this.collectBodyImports(template.body.children);\n }\n }\n }\n\n private templates(templates: TemplateDecl[]): void {\n const { out } = this;\n for (const template of templates) {\n // Templates can await memos, as the component function can.\n out.text('async function ');\n out.copy(template.nameRange);\n out.text('(');\n if (template.params.length > 0) {\n out.copy({ start: template.params[0]!.start, end: template.params.at(-1)!.end });\n }\n out.text(') {\\n');\n this.body(template.body);\n out.text('}\\n');\n }\n }\n\n private body(body: Body): void {\n for (const statement of body.script?.program.body ?? []) {\n if (statement.type !== 'ImportDeclaration') {\n this.statement(statement);\n }\n }\n this.templates(body.templates);\n this.nodes(body.children);\n }\n\n private nodes(nodes: Markup[]): void {\n for (const node of nodes) {\n this.node(node);\n }\n }\n\n private node(node: Markup): void {\n const { out } = this;\n switch (node.kind) {\n case 'text':\n return;\n case 'insert':\n out.text('$$use(');\n out.expression(node.expression);\n out.text(');\\n');\n return;\n case 'element':\n this.elementAttributes(node.tag, node.attributes);\n this.nodes(node.children);\n return;\n case 'component':\n this.component(node);\n this.nodes(node.children);\n return;\n case 'dynamic':\n out.text('$$dynamic(');\n out.expression(node.tag);\n out.text(', {');\n this.props(node.attributes);\n out.text('});\\n');\n this.nodes(node.children);\n return;\n case 'fragment':\n this.nodes(node.children);\n return;\n case 'listener': {\n const helper = node.target === 'window' ? '$$onWindow' : '$$onDocument';\n for (const attribute of node.attributes) {\n out.text(`${helper}(${JSON.stringify(attribute.event)}, `);\n out.expression(attribute.handler);\n out.text(');\\n');\n }\n return;\n }\n default:\n this.block(node);\n }\n }\n\n private elementAttributes(tag: string, attributes: Attribute[]): void {\n const { out } = this;\n for (const attribute of attributes) {\n switch (attribute.kind) {\n case 'value':\n case 'spread':\n out.text('$$use(');\n out.expression(attribute.value);\n out.text(');\\n');\n break;\n case 'event':\n out.text(`$$on(${JSON.stringify(tag)}, ${JSON.stringify(attribute.event)}, `);\n out.expression(attribute.handler);\n out.text(');\\n');\n break;\n case 'ref':\n out.text('$$use(');\n out.copy(attribute.targetRange);\n out.text(');\\n');\n break;\n case 'computed':\n out.text('$$use(');\n out.expression(attribute.name);\n if (attribute.value !== true) {\n out.text(', ');\n out.expression(attribute.value);\n }\n out.text(');\\n');\n break;\n default:\n break;\n }\n }\n }\n\n /** Writes a prop name, mapped to the attribute, so errors about the prop point at it. */\n private propName(attribute: Range & { name: string }): void {\n const { out } = this;\n out.text(' ');\n if (/^[A-Za-z_$][\\w$]*$/.test(attribute.name)) {\n out.copy({ start: attribute.start, end: attribute.start + attribute.name.length });\n } else {\n out.text(JSON.stringify(attribute.name));\n }\n out.text(': ');\n }\n\n /** Writes the attributes of a component or a dynamic tag as the properties of an object. */\n private props(attributes: Attribute[], children = false): void {\n const { out } = this;\n for (const attribute of attributes) {\n switch (attribute.kind) {\n case 'static':\n this.propName(attribute);\n out.text(`${attribute.value === true ? 'true' : JSON.stringify(attribute.value)},`);\n break;\n case 'value':\n this.propName(attribute);\n out.expression(attribute.value);\n out.text(',');\n break;\n case 'event':\n this.propName(attribute);\n out.expression(attribute.handler);\n out.text(',');\n break;\n case 'spread':\n out.text(' ...');\n out.expression(attribute.value);\n out.text(',');\n break;\n default:\n break;\n }\n }\n if (children) {\n out.text(' children: undefined as any,');\n }\n }\n\n private component(node: ComponentNode): void {\n const { out } = this;\n const nameStart = node.start + 1;\n out.text('$$component(');\n out.copy({ start: nameStart, end: nameStart + node.name.length });\n out.text(', ');\n // A missing prop is reported on the object, so its brace stands for the `<` of the tag.\n out.stand({ start: node.start, end: node.start + 1 }, '{');\n this.props(node.attributes, node.children.length > 0);\n // The closing brace stands for the end of the opening tag, so the error spans the tag.\n out.text(' ');\n out.stand({ start: this.openTagEnd(node) - 1, end: this.openTagEnd(node) }, '}');\n out.text(');\\n');\n }\n\n /** The offset after the `>` that ends the opening tag of a component. */\n private openTagEnd(node: ComponentNode): number {\n const last = node.attributes.at(-1)?.end ?? node.start + 1 + node.name.length;\n return this.file.source.indexOf('>', last) + 1;\n }\n\n private block(block: Block): void {\n const { out } = this;\n switch (block.kind) {\n case 'if':\n case 'switch': {\n const branches = block.kind === 'if' ? block.branches : block.cases;\n branches.forEach((branch, index) => {\n out.text(index === 0 ? 'if ' : ' else if ');\n out.expression(branch.condition);\n out.text(' {\\n');\n this.body(branch.body);\n out.text('}');\n });\n if (block.fallback) {\n out.text(' else {\\n');\n this.body(block.fallback);\n out.text('}');\n }\n out.text('\\n');\n return;\n }\n case 'for': {\n out.text('for (const ');\n out.copy(block.item);\n out.text(' of ');\n out.expression(block.list);\n out.text(') {\\n');\n if (block.index) {\n out.text('const ');\n out.copy(block.index);\n out.text(' = 0 as number;\\n');\n }\n if (block.key && block.key !== 'index') {\n out.text('$$use(');\n out.expression(block.key);\n out.text(');\\n');\n }\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n }\n case 'repeat': {\n out.text('for (let $$i = 0; $$i < ');\n out.expression(block.count);\n out.text('; $$i++) {\\n');\n if (block.index) {\n out.text('const ');\n out.copy(block.index);\n out.text(' = $$i;\\n');\n }\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n }\n case 'key':\n out.text('$$use(');\n out.expression(block.value);\n out.text(');\\n{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'offscreen':\n out.text('$$use(');\n out.expression(block.visible);\n out.text(');\\n{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'try':\n out.text('try {\\n');\n this.body(block.body);\n out.text('} catch (');\n if (block.error) {\n out.copy(block.error);\n } else {\n out.text('$$error');\n }\n out.text(') {\\n');\n if (block.reset) {\n out.text('const ');\n out.copy(block.reset);\n out.text(' = (): void => {};\\n');\n }\n this.body(block.fallback);\n out.text('}\\n');\n return;\n case 'loading':\n if (block.on) {\n out.text('$$use(');\n out.expression(block.on);\n out.text(');\\n');\n }\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n case 'portal':\n if (block.target) {\n out.text('$$use(');\n out.expression(block.target);\n out.text(');\\n');\n }\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'head':\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n return;\n case 'client':\n case 'defer':\n out.text('{\\n');\n this.body(block.body);\n out.text('}\\n');\n this.fallback(block.fallback);\n return;\n }\n }\n\n private fallback(body: Body | undefined): void {\n if (body) {\n this.out.text('{\\n');\n this.body(body);\n this.out.text('}\\n');\n }\n }\n}\n\nfunction isBlock(node: Markup): node is Block {\n return !['element', 'component', 'dynamic', 'fragment', 'listener', 'text', 'insert'].includes(\n node.kind,\n );\n}\n\n/** Finds the `<script>` blocks at the top level, without parsing the markup. */\nfunction scriptRanges(source: string): Range[] {\n const ranges: Range[] = [];\n for (const match of source.matchAll(/^<script(\\s[^>]*)?>([\\s\\S]*?)<\\/script\\s*>/gm)) {\n const start = match.index + match[0].indexOf('>') + 1;\n ranges.push({ start, end: start + match[2]!.length });\n }\n return ranges;\n}\n\n/**\n * Generates TypeScript for a `.brm` file. With a syntax error, the code holds\n * the scripts only, so they still get type information.\n */\nexport function toTypeScript(source: string, filename = 'Component.brm'): CheckOutput {\n const out = new Writer(source);\n let file: SFCFile;\n try {\n file = parse(source, { filename });\n } catch (error) {\n if (!(error instanceof BrumateError)) {\n throw error;\n }\n out.text(HELPERS);\n for (const range of scriptRanges(source)) {\n out.copy(range);\n out.text('\\n');\n }\n out.text(\n `export default async function ${COMPONENT}(..._: any[]): Promise<string> {\\n return '';\\n}\\n`,\n );\n return { code: out.code, mappings: out.mappings, error };\n }\n new Generator(file, out).generate();\n return { code: out.code, mappings: out.mappings };\n}\n"],"mappings":";;AAKA,SAAS,GAAG,QAAgB,OAAsB;CAChD,MAAM,EAAE,MAAM,WAAW,YAAY,QAAQ,MAAM,KAAK;CACxD,OAAO,GAAG,KAAK,GAAG;AACpB;AAEA,SAAS,MAAM,MAAsB;CACnC,OAAO,KAAK,UAAU,IAAI;AAC5B;AAEA,SAAS,eAAe,MAAyB;CAC/C,QAAQ,KAAK,MAAb;EACE,KAAK,UACH,OAAO,KAAK,UAAU,OAAO,KAAK,OAAO,GAAG,KAAK,KAAK,GAAG,MAAM,KAAK,KAAK;EAC3E,KAAK,SACH,OAAO,GAAG,KAAK,KAAK,IAAI,KAAK,MAAM,KAAK;EAC1C,KAAK,SACH,OAAO,GAAG,KAAK,OAAO,KAAK,UAAU,KAAK,aAAa,IAAI,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,IAAI,KAAK,QAAQ,KAAK;EACxG,KAAK,OACH,OAAO,OAAO,KAAK;EACrB,KAAK,YACH,OAAO,YAAY,MAAM,KAAK,QAAQ;EACxC,KAAK,UACH,OAAO,OAAO,KAAK,MAAM,KAAK;EAChC,KAAK,YACH,OAAO,IAAI,KAAK,KAAK,KAAK,GAAG,KAAK,UAAU,OAAO,KAAK,KAAK,KAAK,MAAM,KAAK;CACjF;AACF;;AAGA,SAAgB,SAAS,MAAuB;CAC9C,MAAM,QAAkB,CAAC;CACzB,MAAM,SAAS,OAAe,SAAuB;EACnD,MAAM,KAAK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