brumate 0.3.0 → 0.4.1

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 (122) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-C25Sa6vq.d.ts → boot-SCWYwuUd.d.ts} +8 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BBtVTOIt.js +3506 -0
  7. package/dist/client-BBtVTOIt.js.map +1 -0
  8. package/dist/{client-D0CqSxoO.d.ts → client-Cs3o4key.d.ts} +390 -181
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-BzllthiF.js → cookies-Cnbf4w-S.js} +14 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-BbD7JQhj.js → defer-BLJjxqVc.js} +4 -4
  14. package/dist/defer-BLJjxqVc.js.map +1 -0
  15. package/dist/{devtools-CQgD7NPB.js → devtools-DTpsVFbn.js} +56 -82
  16. package/dist/devtools-DTpsVFbn.js.map +1 -0
  17. package/dist/{devtools-panel-BVB-W5q4.js → devtools-panel-C1Dfv6nq.js} +397 -333
  18. package/dist/devtools-panel-C1Dfv6nq.js.map +1 -0
  19. package/dist/{events-CSs7OwIC.js → events-LgLdp1R7.js} +34 -5
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-DZIiMDnS.js +506 -0
  24. package/dist/files-DZIiMDnS.js.map +1 -0
  25. package/dist/{forms-Cl21hkHt.d.ts → forms-j1xPAR14.d.ts} +3 -3
  26. package/dist/{forms-Bg-CwGqX.js → forms-nXK7-Lv_.js} +78 -44
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.js +31 -22
  29. package/dist/highlight.js.map +1 -1
  30. package/dist/{html-mNTKzaDD.js → html-DS9B1H-M.js} +92 -22
  31. package/dist/html-DS9B1H-M.js.map +1 -0
  32. package/dist/{html-Bq1rFxX_.d.ts → html-Gggepsf-.d.ts} +22 -5
  33. package/dist/index.d.ts +98 -10
  34. package/dist/index.js +639 -104
  35. package/dist/index.js.map +1 -1
  36. package/dist/{inspect-BHpOw1LF.js → inspect-DomFHy5O.js} +3832 -695
  37. package/dist/inspect-DomFHy5O.js.map +1 -0
  38. package/dist/{loader-Dos_3NP0.js → loader-D62komKu.js} +20 -14
  39. package/dist/loader-D62komKu.js.map +1 -0
  40. package/dist/logo-DQ_OYhBi.js +10 -0
  41. package/dist/logo-DQ_OYhBi.js.map +1 -0
  42. package/dist/{navigate-O78d_zGN.js → navigate-CfOr-TRF.js} +94 -31
  43. package/dist/navigate-CfOr-TRF.js.map +1 -0
  44. package/dist/nesting-DA5vJw9X.js +265 -0
  45. package/dist/nesting-DA5vJw9X.js.map +1 -0
  46. package/dist/{produce-Doc91GkX.js → produce-BNIpmZq2.js} +138 -9
  47. package/dist/produce-BNIpmZq2.js.map +1 -0
  48. package/dist/{produce-D0V0ICkz.d.ts → produce-CRfouraC.d.ts} +44 -5
  49. package/dist/{rpc-ygMRPmN4.js → rpc-BTMb8jap.js} +11 -6
  50. package/dist/rpc-BTMb8jap.js.map +1 -0
  51. package/dist/runtime/batch.js +9 -7
  52. package/dist/runtime/batch.js.map +1 -1
  53. package/dist/runtime/client.d.ts +4 -4
  54. package/dist/runtime/client.js +4 -4
  55. package/dist/runtime/devtools.d.ts +11 -29
  56. package/dist/runtime/devtools.js +3 -1
  57. package/dist/runtime/env.js +14 -2
  58. package/dist/runtime/env.js.map +1 -1
  59. package/dist/runtime/events.d.ts +23 -1
  60. package/dist/runtime/events.js +1 -1
  61. package/dist/runtime/forms.d.ts +2 -2
  62. package/dist/runtime/forms.js +1 -1
  63. package/dist/runtime/hot.d.ts +1 -1
  64. package/dist/runtime/hot.js +5 -2
  65. package/dist/runtime/hot.js.map +1 -1
  66. package/dist/runtime/html.d.ts +2 -2
  67. package/dist/runtime/html.js +1 -1
  68. package/dist/runtime/loader.d.ts +2 -2
  69. package/dist/runtime/loader.js +2 -2
  70. package/dist/runtime/routes.js +4 -1
  71. package/dist/runtime/routes.js.map +1 -1
  72. package/dist/runtime/server.d.ts +5 -5
  73. package/dist/runtime/server.js +5 -5
  74. package/dist/runtime/signals.d.ts +38 -1
  75. package/dist/runtime/signals.js +33 -1
  76. package/dist/runtime/signals.js.map +1 -1
  77. package/dist/runtime/static-loader.d.ts +2 -2
  78. package/dist/runtime/static-loader.js +1 -1
  79. package/dist/runtime/testing.d.ts +18 -3
  80. package/dist/runtime/testing.js +150 -33
  81. package/dist/runtime/testing.js.map +1 -1
  82. package/dist/{server-CxVDYE_V.js → server-BTtsQFFw.js} +633 -163
  83. package/dist/server-BTtsQFFw.js.map +1 -0
  84. package/dist/{server-DuFYRXrd.d.ts → server-CYw15Dsg.d.ts} +103 -22
  85. package/dist/{static-loader-nZssh66R.js → static-loader-C_GYIFtt.js} +79 -99
  86. package/dist/static-loader-C_GYIFtt.js.map +1 -0
  87. package/dist/{static-loader-Drpr0AzI.d.ts → static-loader-DVuLmXeu.d.ts} +2 -2
  88. package/dist/{stream-DCYZO4IF.js → stream-r4V5zBKm.js} +102 -16
  89. package/dist/stream-r4V5zBKm.js.map +1 -0
  90. package/dist/vite.d.ts +13 -20
  91. package/dist/vite.js +1956 -554
  92. package/dist/vite.js.map +1 -1
  93. package/elements.d.ts +951 -0
  94. package/forms/forms.brm.ts +3 -3
  95. package/package.json +12 -3
  96. package/skills/brumate/SKILL.md +58 -0
  97. package/skills/brumate/references/errors.md +2078 -0
  98. package/skills/brumate/references/events.md +117 -0
  99. package/skills/brumate/references/signals.md +61 -0
  100. package/skills/brumate/references/state.md +235 -0
  101. package/skills/brumate/references/syntax.md +250 -0
  102. package/types.d.ts +4 -4
  103. package/dist/client-BD6XT-s5.js +0 -1968
  104. package/dist/client-BD6XT-s5.js.map +0 -1
  105. package/dist/client-routes-JTbGtukf.js.map +0 -1
  106. package/dist/cookies-BzllthiF.js.map +0 -1
  107. package/dist/defer-BbD7JQhj.js.map +0 -1
  108. package/dist/devtools-CQgD7NPB.js.map +0 -1
  109. package/dist/devtools-panel-BVB-W5q4.js.map +0 -1
  110. package/dist/events-CSs7OwIC.js.map +0 -1
  111. package/dist/files-BXSSrQgc.js +0 -205
  112. package/dist/files-BXSSrQgc.js.map +0 -1
  113. package/dist/forms-Bg-CwGqX.js.map +0 -1
  114. package/dist/html-mNTKzaDD.js.map +0 -1
  115. package/dist/inspect-BHpOw1LF.js.map +0 -1
  116. package/dist/loader-Dos_3NP0.js.map +0 -1
  117. package/dist/navigate-O78d_zGN.js.map +0 -1
  118. package/dist/produce-Doc91GkX.js.map +0 -1
  119. package/dist/rpc-ygMRPmN4.js.map +0 -1
  120. package/dist/server-CxVDYE_V.js.map +0 -1
  121. package/dist/static-loader-nZssh66R.js.map +0 -1
  122. package/dist/stream-DCYZO4IF.js.map +0 -1
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(\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,KAA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KAAK,MAAM,SAAS,aAAa,MAAM,GAAG;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 printAttributes(items: Attribute[]): string {\n let text = '';\n for (const item of items) {\n text += ` ${printAttribute(item)}`;\n }\n return text;\n}\n\nfunction printModifiers(modifiers: string[]): string {\n let text = '';\n for (const modifier of modifiers) {\n text += `:${modifier}`;\n }\n return 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}${printModifiers(item.modifiers)}=(${item.handler.code})`;\n case 'ref':\n return `ref=$bind(${item.target})`;\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 function write(depth: number, text: string): void {\n lines.push(`${' '.repeat(depth)}${text}`);\n }\n\n function 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 function 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 found: string[] = [];\n if (item.error?.name) {\n found.push(item.error.name);\n }\n if (item.reset?.name) {\n found.push(item.reset.name);\n }\n const names = found.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 function 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 = printAttributes(item.attributes);\n write(depth, `${item.kind} <${name}${attributes}>`);\n nodes(item.children, depth + 1);\n break;\n }\n case 'dynamic':\n write(depth, `dynamic <{${item.tag.code}}${printAttributes(item.attributes)}>`);\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(depth, `listener <${item.target}${printAttributes(item.attributes)}>`);\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 function 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 readSet = new Set<string>();\n for (const read of site.reads) {\n readSet.add((read.tracked ? '' : '~') + read.declaration.name);\n }\n const reads = [...readSet];\n const writeSet = new Set<string>();\n for (const write of site.writes) {\n writeSet.add(write.declaration.name);\n }\n const writes = [...writeSet];\n const calls: string[] = [];\n for (const declaration of site.calls) {\n calls.push(declaration.name);\n }\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: string[] = [];\n for (const edge of graph.edges) {\n if (edge.to === node) {\n from.push(nodeLabel(source, edge.from));\n }\n }\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: Scope[] = [];\n for (const scope of graph.model.scopes) {\n if (graph.created.has(scope)) {\n created.push(scope);\n }\n }\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 const parts: Record<string, string> = {};\n for (const [name, code] of Object.entries(result.parts)) {\n parts[name] = unmarked(code);\n }\n return {\n ...result,\n code: unmarked(result.code),\n parts,\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 DynamicTagNode,\n ElementNode,\n EventAttribute,\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 { getPatternNames } from './oxc.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;\ntype $$Markup = import('brumate/elements').Markup;\ndeclare const $$markup: $$Markup;\n/** \\`Omit\\` that keeps the index signatures, for the rest of a \\`$props\\` call. */\ntype $$Omit<T, K> = { [P in keyof T as P extends K ? never : P]: T[P] };\ntype $$Elements = import('brumate/elements').Elements;\n/** The values that a spread can get and that spread nothing. */\ntype $$Falsy = false | 0 | '' | 0n | null | undefined;\n// The helpers of elements are curried and constrained by \\`keyof Elements\\`, with a second overload\n// for other tags. A parameter typed from a generic \\`T extends string\\` made TypeScript resolve the\n// attributes of every tag, in the call and in the declaration of each file, which tripled the time.\n/** Checks the attributes of a plain element against its type. A tag that \\`Elements\\` lacks takes any. */\ndeclare function $$element<T extends keyof $$Elements>(tag: T): (attributes: $$Elements[T]) => void;\ndeclare function $$element(tag: string): (attributes: Record<string, unknown>) => void;\n/** Checks the names of a spread onto a plain element, which has no excess check. \\`$$element\\` checks its values. */\ndeclare function $$spread<T extends keyof $$Elements>(tag: T): <S>(value: (S & { [K in Exclude<keyof S, keyof $$Elements[T]>]: { [M in \\`\\${K & string} is not an attribute of <\\${T}>\\`]: never } }) | $$Falsy) => void;\ndeclare function $$spread(tag: string): (value: object | $$Falsy) => void;\n/** A spread value without its falsy part, which spreads nothing, such as \\`false\\` of \\`cond && { ... }\\`. Its object part is checked. */\ndeclare function $$present<T>(value: T): Exclude<T, $$Falsy>;\n/** \\`$bind\\` of a \\`ref\\`, which needs no import in markup. */\ndeclare function $$bind<T>(signal: T): import('brumate/signals').BoundSignal<T>;\n// A dynamic tag. The helpers are curried, as those of elements: an element name checks the\n// attributes of its element, a component its props, and a tag that can be either, such as a\n// generic \\`T extends AsTarget\\`, the global attributes of an HTML or SVG element. A handler is\n// typed by \\`$$handler\\`, since a union of element names gives a union of handlers, which types\n// no parameter. The first overload takes any string, not \\`keyof Elements\\`: a tag such as\n// \\`AsTarget\\` fails it at once, where a failed \\`keyof Elements\\` cost about 50 ms for each call.\n// The types live in \\`brumate/check\\`, so TypeScript resolves them once, not in each file.\ntype $$AnyTag = keyof $$Elements | import('brumate/elements').Component;\ndeclare function $$dynamic<T extends string>(tag: T): (attributes: import('brumate/check').DynamicAttributes<T> & { children?: $$Markup }, ...spreads: import('brumate/check').DynamicAttributes<T>[]) => void;\ndeclare function $$dynamic<P>(tag: $$Component<P>): import('brumate/check').DynamicProps<P>;\n// The spreads of a tag that can be either are not checked: a part spreads its rest, whose type\n// depends on the tag, and attributes of a context, typed as any.\ndeclare function $$dynamic(tag: $$AnyTag): (attributes: import('brumate/check').AnyTagAttributes, ...spreads: object[]) => void;\ndeclare function $$handler<T extends string>(tag: T): import('brumate/check').DynamicHandle<$$Element<T>>;\ndeclare function $$handler(tag: $$Component<never>): <H>(event: string, handler: H) => H;\ndeclare function $$handler(tag: $$AnyTag): import('brumate/check').DynamicHandle<HTMLElement | SVGElement>;\ntype $$Events = import('brumate/elements').ElementEvents;\ntype $$Element<T> = T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : T extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[T] : HTMLElement;\ndeclare function $$on<T extends string, K extends keyof $$Events & string>(tag: T, event: K, handler: (event: $$Events[K] & { currentTarget: $$Element<T> }) => unknown): void;\ndeclare function $$onWindow<K extends keyof WindowEventMap & string>(event: K, handler: (event: WindowEventMap[K] & { currentTarget: Window }) => unknown): void;\ndeclare function $$onDocument<K extends keyof DocumentEventMap & string>(event: K, handler: (event: DocumentEventMap[K] & { currentTarget: Document }) => unknown): void;\ndeclare function $$use(...values: unknown[]): void;\n/** The type of the name of a template that is written at each use. Only its name is read. */\ndeclare const $$template: (...args: any[]) => Promise<$$Markup>;\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/** Checks a signal that only a ref binds: the browser fills it with an element, and anything else is sent. */\ntype $$SendableRef<T> = T extends Element | null | undefined ? T : $$Sendable<T>;\ndeclare function $$sendableRef<T>(value: T & $$SendableRef<T>): void;\n`;\n\nclass Writer {\n code = '';\n mappings: CheckMapping[] = [];\n private readonly source: string;\n\n constructor(source: string) {\n this.source = source;\n }\n\n /** Starts the code again, to write the file another way. */\n reset(): void {\n this.code = '';\n this.mappings = [];\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 /**\n * Writes the name of an event as a string. It stands in place of the attribute name, which has\n * the same length, so that the error of an unknown event is at the attribute.\n */\n event(attribute: EventAttribute): void {\n const start = this.source[attribute.start] === '{' ? attribute.handler.start : attribute.start;\n this.stand({ start, end: start + attribute.name.length }, JSON.stringify(attribute.event));\n }\n\n /**\n * Writes a property name that stands for a range of the file. A name that is not an identifier\n * is quoted, and its quotes are mapped to the first and last characters of the range, so an\n * error at the name spans the range. So is a name whose length differs from the range, such as\n * `children` for the children of a component.\n */\n key(range: Range, name: string): void {\n if (/^[A-Za-z_$][\\w$]*$/.test(name) && this.source.slice(range.start, range.end) === name) {\n this.copy(range);\n return;\n }\n const text = /^[A-Za-z_$][\\w$]*$/.test(name) ? name : JSON.stringify(name);\n this.stand({ start: range.start, end: range.start + 1 }, text[0]!);\n this.text(text.slice(1, -1));\n this.stand({ start: range.end - 1, end: range.end }, text.at(-1)!);\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/**\n * Finds the type arguments of the calls of `$props<T>()`, as ranges of the file. A component can\n * call it more than once, such as once with `const` and once with `let` for its bindable props.\n */\nfunction propsTypes(program: oxc.Program | undefined): Range[] {\n const found: Range[] = [];\n function visit(node: unknown): void {\n if (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.push(value.typeArguments.params[0]);\n return;\n }\n for (const child of Object.values(value)) {\n if (Array.isArray(child)) {\n for (const item of child) {\n visit(item);\n }\n } else if (typeof child === 'object') {\n visit(child);\n }\n }\n }\n visit(program);\n return found;\n}\n\n/**\n * Finds the `$props<T>()` calls whose pattern has a rest element, and the names that the other\n * calls destructure. At runtime the rest leaves those names out, so the type of the call leaves\n * them out too: a rest that is spread onto an element must not carry a prop of another call.\n * Returns the names by the range of the type argument.\n */\nfunction restOmits(program: oxc.Program | undefined): Map<Range, string[]> {\n const names = new Map<oxc.Node, string[]>();\n const types = new Map<oxc.Node, Range>();\n const rests = new Set<oxc.Node>();\n for (const statement of program?.body ?? []) {\n if (statement.type !== 'VariableDeclaration') {\n continue;\n }\n for (const declarator of statement.declarations) {\n const init = declarator.init;\n if (\n init?.type !== 'CallExpression' ||\n init.callee.type !== 'Identifier' ||\n init.callee.name !== '$props' ||\n declarator.id.type !== 'ObjectPattern'\n ) {\n continue;\n }\n const own: string[] = [];\n for (const property of declarator.id.properties) {\n if (property.type === 'RestElement') {\n rests.add(init);\n } else if (!property.computed && property.key.type === 'Identifier') {\n own.push(property.key.name);\n } else if (!property.computed && property.key.type === 'Literal') {\n own.push(String(property.key.value));\n }\n }\n names.set(init, own);\n const type = (init as { typeArguments?: { params: Range[] } }).typeArguments?.params[0];\n if (type) {\n types.set(init, type);\n }\n }\n }\n const omits = new Map<Range, string[]>();\n for (const call of rests) {\n const type = types.get(call);\n const own = new Set(names.get(call));\n const others = new Set<string>();\n for (const [other, list] of names) {\n if (other !== call) {\n for (const name of list) {\n if (!own.has(name)) {\n others.add(name);\n }\n }\n }\n }\n if (type && others.size > 0) {\n omits.set(type, [...others]);\n }\n }\n return omits;\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)), file);\n const sent: Declaration[] = [];\n for (const declaration of [...slots.values()].flat()) {\n if (\n (declaration.kind === 'signal' ||\n declaration.kind === 'memo' ||\n declaration.kind === 'async-memo') &&\n declaration.refs.length === 0\n ) {\n sent.push(declaration);\n }\n }\n return sent;\n } catch {\n // A file that the analyzer cannot read is still checked as TypeScript.\n return [];\n }\n}\n\n/**\n * Visits the nodes of the file and of the oxc trees in it. `visit` returns false to skip the\n * children of a node.\n */\nfunction walk(node: unknown, visit: (node: Record<string, unknown>) => boolean): void {\n if (typeof node !== 'object' || node === null) {\n return;\n }\n if (Array.isArray(node)) {\n for (const item of node) {\n walk(item, visit);\n }\n return;\n }\n const value = node as Record<string, unknown>;\n if (visit(value) === false) {\n return;\n }\n for (const key in value) {\n if (key !== 'parent') {\n walk(value[key], visit);\n }\n }\n}\n\n/** The names that a node reads or declares, as identifiers and component tags. */\nfunction namesIn(node: unknown): Set<string> {\n const found = new Set<string>();\n walk(node, (value) => {\n if (value.type === 'Identifier' && typeof value.name === 'string') {\n found.add(value.name);\n } else if (value.kind === 'component' && typeof value.name === 'string') {\n found.add(value.name.split('.')[0]!);\n }\n return true;\n });\n return found;\n}\n\n/** The names that the parameters of a template declare. */\nfunction paramNames(template: TemplateDecl): string[] {\n const found: string[] = [];\n for (const param of template.params) {\n const pattern = param.type === 'TSParameterProperty' ? param.parameter : param;\n for (const name of getPatternNames(\n pattern.type === 'RestElement' ? pattern.argument : pattern,\n )) {\n found.push(name.name);\n }\n }\n return found;\n}\n\n/** Whether a parameter of a template has no type, so it can only get one from where it is passed. */\nfunction untyped(template: TemplateDecl): boolean {\n for (const param of template.params) {\n const pattern = (param.type === 'AssignmentPattern' ? param.left : param) as {\n typeAnnotation?: unknown;\n };\n if (!pattern.typeAnnotation) {\n return true;\n }\n }\n return false;\n}\n\n/** The name of a template that an attribute value passes as it is, such as `item=row`. */\nfunction passedName(value: Expression): string | undefined {\n return passedIdentifier(value)?.name;\n}\n\n/** The identifier of `passedName`, with its range in the file. */\nfunction passedIdentifier(value: Expression): (Range & { name: string }) | undefined {\n let node: oxc.Node = value.ast;\n while (node.type === 'ParenthesizedExpression') {\n node = node.expression;\n }\n return node.type === 'Identifier' ? node : undefined;\n}\n\n/**\n * Finds the templates with an untyped parameter whose every use passes it to a prop of a component,\n * such as `item=row`. They are written at each use, so the prop types the parameter. A template\n * that the code reads in another way, or passes to an element, keeps its function declaration.\n */\nfunction inlineTemplates(file: SFCFile): Set<TemplateDecl> {\n const found = new Set<TemplateDecl>();\n function scope(root: unknown, templates: TemplateDecl[]): void {\n for (const template of templates) {\n if (template.params.length === 0 || !untyped(template)) {\n continue;\n }\n let reads = 0;\n let passed = 0;\n walk(root, (value) => {\n // A body that declares a template of the same name hides this one.\n if (value !== root && Array.isArray(value.templates)) {\n for (const other of value.templates as TemplateDecl[]) {\n if (other !== template && other.name === template.name) {\n return false;\n }\n }\n }\n // So does a parameter of the same name, such as `#template item(item)`, in its template.\n if (\n value.kind === 'template' &&\n paramNames(value as unknown as TemplateDecl).includes(template.name)\n ) {\n return false;\n }\n if (value.type === 'Identifier' && value.name === template.name) {\n reads++;\n } else if (value.kind === 'component' && value.name === template.name) {\n reads++;\n }\n if (value.kind === 'component' || value.kind === 'dynamic') {\n for (const attribute of value.attributes as Attribute[]) {\n if (attribute.kind === 'value' && passedName(attribute.value) === template.name) {\n passed++;\n }\n }\n }\n return true;\n });\n if (passed > 0 && reads === passed) {\n found.add(template);\n }\n }\n }\n scope(file, file.templates);\n walk(file.children, (value) => {\n if (Array.isArray(value.templates) && Array.isArray(value.children)) {\n scope(value, value.templates as TemplateDecl[]);\n }\n return true;\n });\n for (const template of file.templates) {\n walk(template.body, (value) => {\n if (Array.isArray(value.templates) && Array.isArray(value.children)) {\n scope(value, value.templates as TemplateDecl[]);\n }\n return true;\n });\n }\n return found;\n}\n\n/** Thrown when a template cannot be written at a use. It is then written as a declaration. */\nclass Hoist {\n readonly template: TemplateDecl;\n\n constructor(template: TemplateDecl) {\n this.template = template;\n }\n}\n\nfunction namespaced(attribute: Attribute): boolean {\n return (\n (attribute.kind === 'static' || attribute.kind === 'value') && attribute.name.includes(':')\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 private readonly omits: Map<Range, string[]>;\n /** The templates that are written at each use. See `inlineTemplates`. */\n private readonly inline: Set<TemplateDecl>;\n /** The names that each block of the generated code declares, outermost first. */\n private scopes: Set<string>[] = [];\n /** The templates in scope, with the number of blocks at their declaration. */\n private visible: { template: TemplateDecl; depth: number }[] = [];\n /** The templates being written at a use, to find one that passes itself. */\n private writing = new Set<TemplateDecl>();\n\n constructor(file: SFCFile, out: Writer) {\n this.file = file;\n this.out = out;\n this.sent = sentDeclarations(file);\n this.omits = restOmits(file.instanceScript?.program);\n this.inline = inlineTemplates(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 let start = statement.start;\n for (const [type, names] of this.omits) {\n if (type.start >= statement.start && type.end <= statement.end) {\n out.copy({ start, end: type.start });\n out.text('$$Omit<');\n out.copy(type);\n const quoted: string[] = [];\n for (const name of names) {\n quoted.push(JSON.stringify(name));\n }\n out.text(`, ${quoted.join(' | ')}>`);\n start = type.end;\n }\n }\n out.copy({ start, end: statement.end });\n out.text('\\n');\n for (const declaration of this.sent) {\n if (declaration.range.start >= statement.start && declaration.range.end <= statement.end) {\n // The `ref` of a component fills a signal with an element, if that is all that binds it.\n const refOnly = declaration.boundAs?.size === 1 && declaration.boundAs.has('ref');\n out.text(refOnly ? '$$sendableRef(' : '$$sendable(');\n out.copy(declaration.range);\n out.text(');\\n');\n }\n }\n }\n\n generate(): void {\n // A template that cannot be written at one of its uses is declared instead, and the file is\n // written again. Each pass declares one more template, so this ends.\n for (;;) {\n try {\n this.write();\n return;\n } catch (error) {\n if (!(error instanceof Hoist)) {\n throw error;\n }\n this.inline.delete(error.template);\n this.out.reset();\n this.scopes = [];\n this.visible = [];\n this.writing = new Set();\n }\n }\n }\n\n private write(): 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 types = propsTypes(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 (types.length > 0) {\n // The props of the calls together.\n for (const [index, type] of types.entries()) {\n out.text(index > 0 ? ' & (' : '(');\n out.copy(type);\n out.text(')');\n }\n } else {\n out.text('Record<string, any>');\n }\n out.text(\", $$ctx?: import('brumate/server').Context): Promise<$$Markup> {\\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.enter(new Set(), file.templates);\n this.templates(file.templates);\n this.nodes(file.children);\n this.leave();\n out.text('return $$markup;\\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 /** Opens a block of the generated code that declares names and templates. */\n private enter(declared: Set<string>, templates: TemplateDecl[] = []): void {\n for (const template of templates) {\n declared.add(template.name);\n }\n this.scopes.push(declared);\n for (const template of templates) {\n this.visible.push({ template, depth: this.scopes.length });\n }\n }\n\n private leave(): void {\n const depth = this.scopes.length;\n this.scopes.pop();\n while (this.visible.at(-1) && this.visible.at(-1)!.depth >= depth) {\n this.visible.pop();\n }\n }\n\n private templates(templates: TemplateDecl[]): void {\n const { out } = this;\n for (const template of templates) {\n if (this.inline.has(template)) {\n // The name stays declared, so that hover, go to definition, references and rename reach\n // the template from its uses. Its type is not used.\n out.text('const ');\n out.copy(template.nameRange);\n out.text(' = $$template;\\n');\n continue;\n }\n // Templates can await memos, as the component function can.\n out.text('async function ');\n out.copy(template.nameRange);\n this.template(template);\n out.text('\\n');\n }\n }\n\n /** Writes the parameters and the body of a template, after its name or `async`. */\n private template(template: TemplateDecl): void {\n const { out } = this;\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('): Promise<$$Markup> ');\n out.text(this.inline.has(template) ? '=> {\\n' : '{\\n');\n this.enter(new Set(paramNames(template)));\n this.body(template.body);\n this.leave();\n out.text('return $$markup;\\n}');\n }\n\n /**\n * Finds the template that a prop value passes, if it is written at each use. An unannotated\n * parameter of a function declaration has no type, and one of an arrow function in a prop takes\n * the type of the prop, so the template is written there as `async (a) => { ... }`. The body is\n * copied, with its mappings, at each use. Throws `Hoist` if a name declared between the\n * template and the use would hide a name that the template reads, or if the template passes\n * itself.\n */\n private passed(value: Expression): TemplateDecl | undefined {\n const name = passedName(value);\n if (name === undefined) {\n return undefined;\n }\n for (let index = this.visible.length - 1; index >= 0; index--) {\n const { template, depth } = this.visible[index]!;\n if (template.name !== name) {\n continue;\n }\n if (!this.inline.has(template)) {\n return undefined;\n }\n if (this.writing.has(template)) {\n throw new Hoist(template);\n }\n const read = namesIn([template.params, template.body]);\n for (const param of paramNames(template)) {\n read.delete(param);\n }\n for (const scope of this.scopes.slice(depth)) {\n for (const declared of scope) {\n if (declared === name || read.has(declared)) {\n throw new Hoist(template);\n }\n }\n }\n return template;\n }\n return undefined;\n }\n\n private body(body: Body, declared = new Set<string>()): void {\n for (const statement of body.script?.program.body ?? []) {\n if (statement.type === 'VariableDeclaration') {\n for (const declarator of statement.declarations) {\n for (const name of getPatternNames(declarator.id)) {\n declared.add(name.name);\n }\n }\n } else if (\n (statement.type === 'FunctionDeclaration' || statement.type === 'ClassDeclaration') &&\n statement.id\n ) {\n declared.add(statement.id.name);\n }\n }\n this.enter(declared, body.templates);\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 this.leave();\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.element(node);\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 this.dynamic(node);\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}(`);\n out.event(attribute);\n out.text(', ');\n out.expression(attribute.handler);\n out.text(');\\n');\n }\n return;\n }\n default:\n this.block(node);\n }\n }\n\n /**\n * Checks the attributes of a plain element as one object against the type of its tag, so an\n * unknown attribute and a wrong value are errors at the attribute. Handlers are checked apart,\n * by `$$on`, which also checks the name of the event.\n */\n private element(node: ElementNode): void {\n const { out } = this;\n for (const attribute of node.attributes) {\n if (attribute.kind === 'event') {\n out.text(`$$on(${JSON.stringify(node.tag)}, `);\n out.event(attribute);\n out.text(', ');\n out.expression(attribute.handler);\n out.text(');\\n');\n }\n }\n for (const attribute of node.attributes) {\n if (attribute.kind === 'spread') {\n // Without parentheses, so that the error is at the spread.\n out.text(`$$spread(${JSON.stringify(node.tag)})(`);\n out.copy(attribute.value);\n out.text(');\\n');\n // The values, as an object of the spread alone, whose braces are those of the spread.\n out.text(`$$element(${JSON.stringify(node.tag)})(`);\n out.stand({ start: attribute.start, end: attribute.start + 1 }, '{');\n out.text('...$$present(');\n out.copy(attribute.value);\n out.text(') ');\n out.stand({ start: attribute.end - 1, end: attribute.end }, '}');\n out.text(');\\n');\n }\n }\n // A namespaced name, such as `xlink:href` or `xmlns:xlink`, is not in the element types, so\n // only its value is checked.\n for (const attribute of node.attributes) {\n if (namespaced(attribute) && attribute.kind === 'value') {\n out.text('$$use(');\n out.expression(attribute.value);\n out.text(');\\n');\n }\n }\n let checked = false;\n for (const attribute of node.attributes) {\n if (attribute.kind !== 'event' && attribute.kind !== 'spread' && !namespaced(attribute)) {\n checked = true;\n break;\n }\n }\n if (!checked) {\n return;\n }\n out.text(`$$element(${JSON.stringify(node.tag)})(`);\n // An error of the whole object, such as a computed name of any string, spans the opening tag.\n out.stand({ start: node.start, end: node.start + 1 }, '{');\n for (const attribute of node.attributes) {\n switch (attribute.kind) {\n case 'static':\n case 'value':\n if (namespaced(attribute)) {\n break;\n }\n this.propName(attribute);\n if (attribute.kind === 'value') {\n out.expression(attribute.value);\n } else {\n out.text(attribute.value === true ? 'true' : JSON.stringify(attribute.value));\n }\n out.text(',');\n break;\n case 'ref':\n out.text(' ');\n out.stand({ start: attribute.start, end: attribute.start + 3 }, 'ref');\n out.text(': $$bind(');\n out.copy(attribute.targetRange);\n out.text('),');\n break;\n case 'computed': {\n // Without parentheses, so that a name of a literal type is a known property. The\n // brackets are mapped, so an error at the name is at the attribute.\n const close = this.file.source.indexOf(']', attribute.name.end);\n out.text(' ');\n out.stand({ start: attribute.start, end: attribute.start + 1 }, '[');\n out.copy(attribute.name);\n out.stand({ start: close, end: close + 1 }, ']');\n out.text(': ');\n if (attribute.value === true) {\n out.text('true');\n } else {\n out.expression(attribute.value);\n }\n out.text(',');\n break;\n }\n default:\n break;\n }\n }\n out.text(' ');\n const end = this.openTagEnd(node);\n out.stand({ start: end - 1, end }, '}');\n out.text(');\\n');\n }\n\n /**\n * Checks the attributes of a dynamic tag as one object against the type of its tag: the\n * attributes of an element name, or the props of a component. The tag is read once into a\n * constant, so an error in it is reported once. Handlers are typed by `$$handler`. The values\n * of each spread are checked as an argument after the object, but not its names: a check of the\n * names, as `$$spread` does on an element, cost TypeScript ten times the time of the whole check.\n */\n private dynamic(node: DynamicTagNode): void {\n const { out } = this;\n this.passedNames(node.attributes);\n out.text('{\\nconst $$tag = ');\n out.expression(node.tag);\n out.text(';\\n');\n out.text('$$dynamic($$tag)(');\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 for (const attribute of node.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 this.propValue(attribute.value);\n out.text(',');\n break;\n case 'event':\n this.propName(attribute);\n out.text('$$handler($$tag)(');\n out.event(attribute);\n out.text(', ');\n out.expression(attribute.handler);\n out.text('),');\n break;\n case 'ref':\n out.text(' ');\n out.stand({ start: attribute.start, end: attribute.start + 3 }, 'ref');\n out.text(': $$bind(');\n out.copy(attribute.targetRange);\n out.text('),');\n break;\n case 'computed': {\n const close = this.file.source.indexOf(']', attribute.name.end);\n out.text(' ');\n out.stand({ start: attribute.start, end: attribute.start + 1 }, '[');\n out.copy(attribute.name);\n out.stand({ start: close, end: close + 1 }, ']');\n out.text(': ');\n if (attribute.value === true) {\n out.text('true');\n } else {\n out.expression(attribute.value);\n }\n out.text(',');\n break;\n }\n default:\n break;\n }\n }\n if (node.children.length > 0) {\n // Children are markup. The name stands for the children, so a component that takes none\n // reports the error there.\n out.text(' ');\n out.key({ start: node.children[0]!.start, end: node.children.at(-1)!.end }, 'children');\n out.text(': $$markup,');\n }\n out.text(' ');\n const end = this.openTagEnd(node);\n out.stand({ start: end - 1, end }, '}');\n // Each spread is an argument of its own, whose braces stand for the spread, so an error in\n // its values is at the spread. A falsy value spreads nothing, and the object part is checked.\n for (const attribute of node.attributes) {\n if (attribute.kind === 'spread') {\n out.text(', ');\n out.stand({ start: attribute.start, end: attribute.start + 1 }, '{');\n out.text('...$$present(');\n out.copy(attribute.value);\n out.text(') ');\n out.stand({ start: attribute.end - 1, end: attribute.end }, '}');\n }\n }\n out.text(');\\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 // A shorthand, such as `{page}`, has its name after the brace.\n const start =\n this.file.source[attribute.start] === '{'\n ? this.file.source.indexOf(attribute.name, attribute.start)\n : attribute.start;\n out.key({ start, end: start + attribute.name.length }, attribute.name);\n out.text(': ');\n }\n\n /**\n * Writes the value of a prop. A template passed by name is written in its place, so the type of\n * the prop types its parameters.\n */\n private propValue(value: Expression): void {\n const { out } = this;\n const template = this.passed(value);\n if (template) {\n this.writing.add(template);\n out.text('(async ');\n this.template(template);\n out.text(')');\n this.writing.delete(template);\n } else {\n out.expression(value);\n }\n }\n\n /** Writes the attributes of a component as the properties of an object. */\n private props(attributes: Attribute[], children?: Range): 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 this.propValue(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 // Children are markup. The name stands for the children, so a component that takes none,\n // or takes another type, reports the error there.\n out.text(' ');\n out.key(children, 'children');\n out.text(': $$markup,');\n }\n }\n\n /**\n * Reads the name of each template that a prop passes and that is written at the use, mapped to\n * the name at the use, so the use reaches the template in an editor. It is a statement of its own\n * before the call: in the prop, next to the arrow function, it would change how the call infers\n * its type parameters.\n */\n private passedNames(attributes: Attribute[]): void {\n for (const attribute of attributes) {\n if (attribute.kind === 'value' && this.passed(attribute.value)) {\n const name = passedIdentifier(attribute.value)!;\n this.out.text('$$use(');\n this.out.copy(name);\n this.out.text(');\\n');\n }\n }\n }\n\n private component(node: ComponentNode): void {\n const { out } = this;\n this.passedNames(node.attributes);\n const nameStart = node.start + 1;\n // A direct call checks the props as a fresh object, so an unknown prop is reported, and the\n // type parameters of a generic component are inferred from them.\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(\n node.attributes,\n node.children.length > 0\n ? { start: node.children[0]!.start, end: node.children.at(-1)!.end }\n : undefined,\n );\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 an element or a component. */\n private openTagEnd(node: ElementNode | ComponentNode | DynamicTagNode): number {\n let tagEnd: number;\n if (node.kind === 'dynamic') {\n // After the `}` of `<{tag}`.\n tagEnd = this.file.source.indexOf('}', node.tag.end) + 1;\n } else {\n tagEnd = node.start + 1 + (node.kind === 'component' ? node.name : node.tag).length;\n }\n const last = node.attributes.at(-1)?.end ?? tagEnd;\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 for (const [index, branch] of branches.entries()) {\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, namesIn([block.item, block.index]));\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, namesIn(block.index));\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, namesIn([block.error, block.reset]));\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<$$Markup> {\\n return $$markup;\\n}\\n`,\n );\n return { code: out.code, mappings: out.mappings, error };\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