@lucidkiln/core 1.8.0 → 1.9.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.
- package/CHANGELOG.md +5 -0
- package/dist/cli.js +2 -2
- package/dist/{environment-BQipJ3kg.d.ts → environment-DcH713WK.d.ts} +12 -3
- package/dist/environment-DcH713WK.d.ts.map +1 -0
- package/dist/{format-8A_kD0sb.js → format-B5w2QhSr.js} +2 -2
- package/dist/{format-8A_kD0sb.js.map → format-B5w2QhSr.js.map} +1 -1
- package/dist/format.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{source-tVX6J33O.js → source-DcWmJzQW.js} +2 -1
- package/dist/source-DcWmJzQW.js.map +1 -0
- package/package.json +1 -1
- package/dist/environment-BQipJ3kg.d.ts.map +0 -1
- package/dist/source-tVX6J33O.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.9.0
|
|
4
|
+
|
|
5
|
+
- Added `cached` to the render info that `withRender` functions get. It says whether the call runs inside a cached section, so a function can leave out data that changes between requests, such as the query string. ([00b1fbf](https://github.com/buildlucid/kiln/commit/00b1fbfc5b52c3464e92ee4d8bbb191dbf97c4f4))
|
|
6
|
+
- Added `query` to `deferIslands`, so each deferred island's request carries the page's query string. The `<kiln-island>` script has changed, so update any Content Security Policy hash you keep for it. ([00b1fbf](https://github.com/buildlucid/kiln/commit/00b1fbfc5b52c3464e92ee4d8bbb191dbf97c4f4))
|
|
7
|
+
|
|
3
8
|
## 1.8.0
|
|
4
9
|
|
|
5
10
|
- Regenerate precompiled templates after upgrading, as with every release. Modules from earlier versions are refused. ([3c0a5fb](https://github.com/buildlucid/kiln/commit/3c0a5fb24751d289dbd685b57e6d2db5004d2970))
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Fn as KilnSyntaxError } from "./source-
|
|
3
|
-
import { n as format, t as KilnFormatError } from "./format-
|
|
2
|
+
import { Fn as KilnSyntaxError } from "./source-DcWmJzQW.js";
|
|
3
|
+
import { n as format, t as KilnFormatError } from "./format-B5w2QhSr.js";
|
|
4
4
|
import { readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import { join, relative, resolve } from "node:path";
|
|
6
6
|
import process from "node:process";
|
|
@@ -73,6 +73,8 @@ type DeferredIslands = {
|
|
|
73
73
|
readonly url: string;
|
|
74
74
|
/** Whether Kiln writes the `<kiln-island>` script before the first island of each render. */
|
|
75
75
|
readonly script: boolean;
|
|
76
|
+
/** Whether each island's request carries the page's query string, after its own `src`. */
|
|
77
|
+
readonly query: boolean;
|
|
76
78
|
/** Every island deferred so far, by id. */
|
|
77
79
|
readonly manifest: IslandManifest;
|
|
78
80
|
};
|
|
@@ -85,9 +87,10 @@ type DeferredIslands = {
|
|
|
85
87
|
* await writeFile("build/islands.json", JSON.stringify(islands.manifest));
|
|
86
88
|
* ```
|
|
87
89
|
*/
|
|
88
|
-
declare const deferIslands: ({ url, script }: {
|
|
90
|
+
declare const deferIslands: ({ url, script, query }: {
|
|
89
91
|
url: string;
|
|
90
92
|
script?: boolean;
|
|
93
|
+
query?: boolean;
|
|
91
94
|
}) => DeferredIslands;
|
|
92
95
|
/** The `islands` render option for `renderStream`. Make it with `streamIslands`. */
|
|
93
96
|
type StreamedIslands = {
|
|
@@ -113,12 +116,13 @@ type IslandMode = DeferredIslands | StreamedIslands;
|
|
|
113
116
|
* inline scripts, with `script: false`.
|
|
114
117
|
*
|
|
115
118
|
* - A deferred island's element fetches its `src`, and replaces itself with the response when it succeeds and is HTML.
|
|
119
|
+
* With a `query` attribute, the page's query string follows the `src`'s own.
|
|
116
120
|
* - A streamed island's HTML arrives in a `<template>`, followed by `<kiln-island fill="n">`, which moves it in place of
|
|
117
121
|
* `<kiln-island stream="n">` once the template is parsed.
|
|
118
122
|
*
|
|
119
123
|
* Otherwise the fallback stays. Kept short and plain, since it is written into pages.
|
|
120
124
|
*/
|
|
121
|
-
declare const islandScript = "customElements.get(\"kiln-island\")||customElements.define(\"kiln-island\",class extends HTMLElement{connectedCallback(){if(this.k)return;this.k=1;this.style.display=\"contents\";const p=h=>document.createRange().createContextualFragment(h),f=this.getAttribute(\"fill\"),s=this.getAttribute(\"src\");if(f){const t=this.previousElementSibling,e=document.querySelector(`kiln-island[stream=\"${f}\"]`);if(e&&t&&t.localName==\"template\")e.replaceWith(p(t.innerHTML)),t.remove();this.remove()}else if(s)fetch(s).then(r=>r.ok&&/^text\\/html/.test(r.headers.get(\"content-type\"))?r.text():null).then(h=>{if(h!=null)this.replaceWith(p(h))},()=>{})}});";
|
|
125
|
+
declare const islandScript = "customElements.get(\"kiln-island\")||customElements.define(\"kiln-island\",class extends HTMLElement{connectedCallback(){if(this.k)return;this.k=1;this.style.display=\"contents\";const p=h=>document.createRange().createContextualFragment(h),f=this.getAttribute(\"fill\"),s=this.getAttribute(\"src\"),q=this.hasAttribute(\"query\")?location.search.slice(1):\"\";if(f){const t=this.previousElementSibling,e=document.querySelector(`kiln-island[stream=\"${f}\"]`);if(e&&t&&t.localName==\"template\")e.replaceWith(p(t.innerHTML)),t.remove();this.remove()}else if(s)fetch(q?s+(s.includes(\"?\")?\"&\":\"?\")+q:s).then(r=>r.ok&&/^text\\/html/.test(r.headers.get(\"content-type\"))?r.text():null).then(h=>{if(h!=null)this.replaceWith(p(h))},()=>{})}});";
|
|
122
126
|
//#endregion
|
|
123
127
|
//#region src/runtime/types.d.ts
|
|
124
128
|
/**
|
|
@@ -163,6 +167,11 @@ type RenderInfo<State = unknown> = {
|
|
|
163
167
|
/** Resolved name of the template making the call. */
|
|
164
168
|
template: string;
|
|
165
169
|
signal: AbortSignalLike | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Whether the call runs inside a cached section, whose output later renders may reuse, so it mustn't hold data that
|
|
172
|
+
* changes between requests. True even without a store, so templates work the same with and without one.
|
|
173
|
+
*/
|
|
174
|
+
cached: boolean;
|
|
166
175
|
/**
|
|
167
176
|
* Tags the cached section the call runs in, and every cached section around it, so a store can clear its copies
|
|
168
177
|
* when that data changes. Does nothing outside a cached section.
|
|
@@ -539,4 +548,4 @@ declare const memoryCache: ({ max }?: {
|
|
|
539
548
|
};
|
|
540
549
|
//#endregion
|
|
541
550
|
export { Diagnostic as $, HostRender as A, TemplateReference as B, memoryLoader as C, HtmlChecks as D, HtmlCheckLevel as E, AnalysedProp as F, IslandEntry as G, KilnCache as H, Analysis as I, JsonValue as J, IslandManifest as K, CallArgument as L, Markup as M, isSafe as N, PrecompiledTemplate as O, safe as P, streamIslands as Q, FunctionCall as R, memoryCache as S, HtmlCheck as T, RenderInfo as U, AbortSignalLike as V, DeferredIslands as W, deferIslands as X, StreamedIslands as Y, islandScript as Z, TemplateContext as _, KilnGlobals as a, builtins as b, KilnTemplates as c, Limits as d, KilnRenderError as et, LoadedTemplate as f, TemplateBlock as g, RenderOptions as h, KilnFunctions as i, hostComponent as j, HostComponent as k, KilnTests as l, RenderAware as m, KilnCallable as n, TemplateLocation as nt, KilnOptions as o, Loader as p, IslandMode as q, KilnFilters as r, KilnSchema as s, Kiln as t, KilnSyntaxError as tt, KilnTypes as u, TemplateName as v, withRender as w, createKiln as x, TypeChecks as y, TemplateExport as z };
|
|
542
|
-
//# sourceMappingURL=environment-
|
|
551
|
+
//# sourceMappingURL=environment-DcH713WK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-DcH713WK.d.ts","names":[],"sources":["../src/errors.ts","../src/runtime/islands.ts","../src/runtime/types.ts","../src/analyzer.ts","../src/runtime/markup.ts","../src/compiler/host.ts","../src/compiler/precompiled.ts","../src/html/options.ts","../src/environment.ts"],"mappings":";;KAEY;;EAEX;EACA;EACA;;EAEA;EACA,OAAO;EACP,KAAK;;KA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;;EAaiB,UAAA;IAAE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fn as KilnSyntaxError, In as createDiagnostic, r as builtinTests, t as Source, un as BLOCK } from "./source-
|
|
1
|
+
import { Fn as KilnSyntaxError, In as createDiagnostic, r as builtinTests, t as Source, un as BLOCK } from "./source-DcWmJzQW.js";
|
|
2
2
|
import { r as scanControlled, t as parse } from "./parser-CRWl5Lka.js";
|
|
3
3
|
//#region src/formatter/delimiters.ts
|
|
4
4
|
const KEYWORDS = /* @__PURE__ */ new Set([
|
|
@@ -942,4 +942,4 @@ const format = (text, options = {}) => applyEdits(text, formatEdits(text, option
|
|
|
942
942
|
//#endregion
|
|
943
943
|
export { format as n, formatEdits as r, KilnFormatError as t };
|
|
944
944
|
|
|
945
|
-
//# sourceMappingURL=format-
|
|
945
|
+
//# sourceMappingURL=format-B5w2QhSr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-8A_kD0sb.js","names":[],"sources":["../src/formatter/delimiters.ts","../src/formatter/format.ts"],"sourcesContent":["import type { DelimitedPart, Token } from \"../lexer/lexer.js\";\n\n/** A token as the formatter prints it: its source text, unchanged. An interpolated string is one piece. */\ntype Piece = {\n\ttype: Token[\"type\"];\n\ttext: string;\n\tstart: number;\n\tend: number;\n};\n\n/**\n * What a piece does, where that changes its spacing.\n *\n * - `word`: a name, number or string.\n * - `keyword`: a tag's name, or a name such as `and` or `in`. A bracket after it groups rather than calls.\n * - `unary`: a sign that makes a number negative or positive, written against its operand.\n * - `tight`: `.`, `?.`, `..` and a filter's `|`, with no space either side.\n * - `key`: the colon after a key or named argument, or `?` and `?:` marking an optional key in `props`.\n * - `call`: a bracket that calls or indexes the piece before it.\n * - `open`, `close`: other brackets.\n * - `spaced`: operators with a space either side.\n */\ntype Role =\n\t| \"word\"\n\t| \"keyword\"\n\t| \"unary\"\n\t| \"tight\"\n\t| \"key\"\n\t| \"call\"\n\t| \"open\"\n\t| \"close\"\n\t| \"comma\"\n\t| \"spread\"\n\t| \"spaced\";\n\nconst KEYWORDS = new Set([\n\t\"and\",\n\t\"or\",\n\t\"not\",\n\t\"in\",\n\t\"is\",\n\t\"starts\",\n\t\"ends\",\n\t\"with\",\n\t\"as\",\n\t\"import\",\n\t\"ignore\",\n\t\"missing\",\n]);\n\n/** Joins each interpolated string's tokens, from `stringStart` to its matching `stringEnd`, into one piece. */\nconst toPieces = (source: string, tokens: readonly Token[]): Piece[] => {\n\tconst pieces: Piece[] = [];\n\tfor (let index = 0; index < tokens.length; index++) {\n\t\tconst token = tokens[index] as Token;\n\t\tlet end = token.end;\n\t\tif (token.type === \"stringStart\") {\n\t\t\tlet depth = 0;\n\t\t\tfor (; index < tokens.length; index++) {\n\t\t\t\tconst inner = tokens[index] as Token;\n\t\t\t\tif (inner.type === \"stringStart\") depth++;\n\t\t\t\telse if (inner.type === \"stringEnd\" && --depth === 0) break;\n\t\t\t}\n\t\t\tend = (tokens[Math.min(index, tokens.length - 1)] as Token).end;\n\t\t}\n\t\tpieces.push({\n\t\t\ttype: token.type === \"stringStart\" ? \"string\" : token.type,\n\t\t\ttext: source.slice(token.start, end),\n\t\t\tstart: token.start,\n\t\t\tend,\n\t\t});\n\t}\n\treturn pieces;\n};\n\n/** Works out each piece's role. `isTag` means the first piece is a tag's name. */\nconst rolesOf = (pieces: readonly Piece[], isTag: boolean): Role[] => {\n\tconst roles: Role[] = [];\n\t// In `props`, `|` joins types and `?:` marks an optional key, until `=` starts a default value.\n\tconst props = isTag && pieces[0]?.text === \"props\";\n\tlet inDefault = false;\n\t// Open `?`s at each bracket depth, so a conditional's `:` can be told from a key's.\n\tconst conditionals: number[] = [0];\n\n\tfor (const [index, piece] of pieces.entries()) {\n\t\tconst previous = roles[index - 1];\n\t\tconst depth = conditionals.length - 1;\n\t\tconst types = props && !inDefault;\n\t\tlet role: Role;\n\n\t\tif (piece.type !== \"punct\") {\n\t\t\trole =\n\t\t\t\t(isTag && index === 0) ||\n\t\t\t\t(piece.type === \"name\" && KEYWORDS.has(piece.text))\n\t\t\t\t\t? \"keyword\"\n\t\t\t\t\t: \"word\";\n\t\t} else {\n\t\t\tswitch (piece.text) {\n\t\t\t\tcase \"(\":\n\t\t\t\tcase \"[\":\n\t\t\t\t\trole = previous === \"word\" || previous === \"close\" ? \"call\" : \"open\";\n\t\t\t\t\tconditionals.push(0);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"{\":\n\t\t\t\t\trole = \"open\";\n\t\t\t\t\tconditionals.push(0);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \")\":\n\t\t\t\tcase \"]\":\n\t\t\t\tcase \"}\":\n\t\t\t\t\trole = \"close\";\n\t\t\t\t\tif (conditionals.length > 1) conditionals.pop();\n\t\t\t\t\tbreak;\n\t\t\t\tcase \",\":\n\t\t\t\t\trole = \"comma\";\n\t\t\t\t\tif (props && depth === 0) inDefault = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"...\":\n\t\t\t\t\trole = \"spread\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \".\":\n\t\t\t\tcase \"?.\":\n\t\t\t\tcase \"..\":\n\t\t\t\t\trole = \"tight\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"|\":\n\t\t\t\t\trole = types ? \"spaced\" : \"tight\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"-\":\n\t\t\t\tcase \"+\":\n\t\t\t\t\trole =\n\t\t\t\t\t\tprevious === undefined ||\n\t\t\t\t\t\t(previous !== \"word\" && previous !== \"close\")\n\t\t\t\t\t\t\t? \"unary\"\n\t\t\t\t\t\t\t: \"spaced\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"?\":\n\t\t\t\tcase \"?:\":\n\t\t\t\t\trole = types ? \"key\" : \"spaced\";\n\t\t\t\t\tif (piece.text === \"?\" && !types) {\n\t\t\t\t\t\tconditionals[depth] = (conditionals[depth] ?? 0) + 1;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \":\":\n\t\t\t\t\tif ((conditionals[depth] ?? 0) > 0) {\n\t\t\t\t\t\tconditionals[depth] = (conditionals[depth] ?? 0) - 1;\n\t\t\t\t\t\trole = \"spaced\";\n\t\t\t\t\t} else role = \"key\";\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\trole = \"spaced\";\n\t\t\t\t\tif (props && depth === 0 && piece.text === \"=\") inDefault = true;\n\t\t\t}\n\t\t}\n\t\troles.push(role);\n\t}\n\treturn roles;\n};\n\n/** The gap between two pieces: a space or nothing. */\nconst gapBetween = (\n\tprevious: Piece,\n\tpreviousRole: Role,\n\tpiece: Piece,\n\trole: Role,\n): string => {\n\tif (role === \"comma\" || role === \"tight\" || role === \"key\" || role === \"call\")\n\t\treturn \"\";\n\tif (role === \"close\") {\n\t\treturn piece.text === \"}\" && previous.text !== \"{\" ? \" \" : \"\";\n\t}\n\tif (previousRole === \"tight\" || previousRole === \"unary\") return \"\";\n\tif (previousRole === \"spread\") return \"\";\n\tif (previousRole === \"open\" || previousRole === \"call\") {\n\t\treturn previous.text === \"{\" ? \" \" : \"\";\n\t}\n\treturn \" \";\n};\n\n/**\n * Whether `pieces[index]`, a number after a `.`, would join the number before the `.` if printed against it, as `1 . 5`\n * would read as `1.5`. A number right after `.` or `?.` is read as a whole number, so `items.0 . 1` can't join.\n */\nconst joinsNumber = (pieces: readonly Piece[], index: number): boolean => {\n\tconst number = pieces[index - 2];\n\tconst before = pieces[index - 3]?.text;\n\treturn (\n\t\tpieces[index]?.type === \"number\" &&\n\t\tpieces[index - 1]?.text === \".\" &&\n\t\tnumber?.type === \"number\" &&\n\t\t!number.text.includes(\".\") &&\n\t\tbefore !== \".\" &&\n\t\tbefore !== \"?.\"\n\t);\n};\n\n/**\n * Prints one output or tag with normalised spacing. Line breaks between tokens stay; each line after one is indented from `indent`, one step further or to match the brackets it sits inside, using `unit` per step.\n *\n * Returns null for a delimiter that never closed, which the formatter leaves as it is.\n */\nexport const printDelimiter = (\n\tsource: string,\n\tpart: DelimitedPart,\n\tindent: string,\n\tunit: string,\n): string | null => {\n\tconst tokens = part.tokens;\n\tconst open = tokens[0];\n\tconst close = tokens[tokens.length - 1];\n\tif (!open || !close || close.value === \"\" || tokens.length < 3) return null;\n\n\tconst pieces = toPieces(source, tokens.slice(1, -1));\n\tconst roles = rolesOf(pieces, part.kind === \"tag\");\n\tlet out = open.value;\n\tlet previousEnd = part.start + open.value.length;\n\t// The line each open bracket started on. Brackets opened on the same line add one step between them.\n\tconst openedOn: number[] = [];\n\tlet line = 0;\n\t/** Steps of indentation for a new line, once `closers` brackets at its start have closed. */\n\tconst steps = (closers: number) =>\n\t\tnew Set(openedOn.slice(0, openedOn.length - closers)).size;\n\n\tfor (const [index, piece] of pieces.entries()) {\n\t\tconst role = roles[index] as Role;\n\t\tconst gap = source.slice(previousEnd, piece.start);\n\t\tif (gap.includes(\"\\n\")) {\n\t\t\tline++;\n\t\t\t// Closing brackets at the start of a line line up with the line that opened them. Only those on this line count.\n\t\t\tlet closers = 0;\n\t\t\twhile (\n\t\t\t\troles[index + closers] === \"close\" &&\n\t\t\t\t(closers === 0 ||\n\t\t\t\t\t!source\n\t\t\t\t\t\t.slice(\n\t\t\t\t\t\t\t(pieces[index + closers - 1] as Piece).end,\n\t\t\t\t\t\t\t(pieces[index + closers] as Piece).start,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.includes(\"\\n\"))\n\t\t\t) {\n\t\t\t\tclosers++;\n\t\t\t}\n\t\t\tout += `\\n${indent}${unit.repeat(closers > 0 ? steps(closers) : Math.max(steps(0), 1))}`;\n\t\t} else if (index === 0) out += \" \";\n\t\telse if (joinsNumber(pieces, index)) out += \" \";\n\t\telse {\n\t\t\tout += gapBetween(\n\t\t\t\tpieces[index - 1] as Piece,\n\t\t\t\troles[index - 1] as Role,\n\t\t\t\tpiece,\n\t\t\t\trole,\n\t\t\t);\n\t\t}\n\t\tout += piece.text;\n\t\tif (role === \"open\" || role === \"call\") openedOn.push(line);\n\t\telse if (role === \"close\") openedOn.pop();\n\t\tpreviousEnd = piece.end;\n\t}\n\n\tconst closeStart = part.end - close.value.length;\n\tout += source.slice(previousEnd, closeStart).includes(\"\\n\")\n\t\t? `\\n${indent}`\n\t\t: \" \";\n\treturn out + close.value;\n};\n","import { builtinTests } from \"../builtins/functions.js\";\nimport { KilnSyntaxError } from \"../errors.js\";\nimport { createDiagnostic } from \"../errors.js\";\nimport { BLOCK } from \"../html/data.js\";\nimport {\n\ttype DelimitedPart,\n\ttype Part,\n\tscanControlled,\n} from \"../lexer/lexer.js\";\nimport type { Statement, TemplateNode } from \"../parser/ast.js\";\nimport { parse } from \"../parser/parser.js\";\nimport { type Span, Source } from \"../source.js\";\nimport { printDelimiter } from \"./delimiters.js\";\n\nexport type FormatOptions = {\n\t/** Indent with tabs. Default `true`. */\n\tuseTabs?: boolean;\n\t/** Spaces per step without tabs, and the width of a tab when moving lines. A whole number of at least 1. Default `4`. */\n\ttabWidth?: number;\n\t/** Only format lines that overlap this range of offsets. */\n\trange?: { start: number; end: number };\n};\n\n/** Replace `start` to `end` of the original source with `text`. */\nexport type FormatEdit = { start: number; end: number; text: string };\n\n/** Thrown when formatting would have changed what a template renders. That is a bug in the formatter. */\nexport class KilnFormatError extends Error {\n\toverride name = \"KilnFormatError\";\n}\n\n/**\n * How the formatter treats one line.\n *\n * - `indent`: set its indentation to `level` steps.\n * - `shift`: move it by as much as line `anchor` moved, keeping its own indentation relative to it. For scripts, styles and comments.\n * - `keep`: leave it alone, for `<pre>`, `<textarea>`, `verbatim`, text inside attribute values, and the body of a `set` or `apply` whose tag shares its line.\n * - `inside`: it starts inside an output or tag, which `printDelimiter` indents.\n */\ntype Line =\n\t| { kind: \"indent\"; start: number; level: number }\n\t| { kind: \"shift\"; start: number; anchor: number }\n\t| { kind: \"keep\" | \"inside\"; start: number };\n\ntype Frame = { kind: \"kiln\" | \"html\"; name: string };\n\n/**\n * Where the scanner is in the HTML.\n *\n * - `tag`: inside `<name ...>` or `</name>`, which started on line `line`. `inner` counts block tags open inside it.\n * - `raw`: inside `<script>` or `<style>`, or kept as written inside `<pre>`, `<textarea>` and the like.\n * - `kept`: inside the body of block tag `name`, output as written: `verbatim`, or a `set` or `apply` whose tag shares\n * its line, where Kiln doesn't remove the body's indentation. `depth` counts the tags of that name open.\n */\ntype Mode =\n\t| { kind: \"data\" }\n\t| {\n\t\t\tkind: \"tag\";\n\t\t\tname: string;\n\t\t\tclosing: boolean;\n\t\t\tquote: string | null;\n\t\t\tline: number;\n\t\t\tatLineStart: boolean;\n\t\t\tinner: number;\n\t }\n\t| { kind: \"comment\"; anchor: number; level: number }\n\t| { kind: \"raw\"; name: string; keep: boolean; anchor: number; level: number }\n\t| { kind: \"kept\"; name: string; depth: number; level: number };\n\nconst VOID_ELEMENTS = new Set([\n\t\"area\",\n\t\"base\",\n\t\"br\",\n\t\"col\",\n\t\"embed\",\n\t\"hr\",\n\t\"img\",\n\t\"input\",\n\t\"link\",\n\t\"meta\",\n\t\"source\",\n\t\"track\",\n\t\"wbr\",\n]);\n\n/** Elements written in `<script>` or `<style>`'s own language, whose lines move together. */\nconst RAW_ELEMENTS = new Set([\"script\", \"style\"]);\n/** Elements whose whitespace shows on the page. Nothing closes `<plaintext>`. */\nconst KEPT_ELEMENTS = new Set([\n\t\"pre\",\n\t\"textarea\",\n\t\"xmp\",\n\t\"listing\",\n\t\"plaintext\",\n]);\n\n/** Whether `</name` starts at `index`, as a whole tag name. */\nconst closesElement = (text: string, index: number, name: string): boolean => {\n\tif (name === \"plaintext\") return false;\n\tconst end = index + 2 + name.length;\n\treturn (\n\t\ttext.slice(index, end).toLowerCase() === `</${name}` &&\n\t\t(end === text.length || /[\\s/>]/.test(text[end] as string))\n\t);\n};\n\n/**\n * Whether a line starting with `trimmed` begins with the tag that ends the outermost `kept` body, and the formatter\n * may indent it. It may when Kiln removes the whitespace before the tag: a `-` trim marker, or a tag alone on its line.\n */\nconst endsKept = (\n\ttrimmed: string,\n\tmode: Extract<Mode, { kind: \"kept\" }>,\n): boolean => {\n\tconst match = /^\\{%(-?)\\s*end([A-Za-z]+)\\s*-?%\\}([^\\n]*)/.exec(trimmed);\n\treturn (\n\t\tmatch !== null &&\n\t\tmatch[2] === mode.name &&\n\t\tmode.depth === 1 &&\n\t\t(match[1] === \"-\" || /^[ \\t\\r]*$/.test(match[3] as string))\n\t);\n};\n\n/** Elements that the next of these siblings closes, such as a `<li>` without `</li>`. */\nconst CLOSED_BY: Record<string, readonly string[]> = {\n\tli: [\"li\"],\n\tdt: [\"dt\", \"dd\"],\n\tdd: [\"dt\", \"dd\"],\n\tp: [\"p\"],\n\toption: [\"option\"],\n\ttr: [\"tr\"],\n\ttd: [\"td\", \"th\"],\n\tth: [\"td\", \"th\"],\n\tthead: [\"tbody\", \"tfoot\"],\n\ttbody: [\"tbody\", \"tfoot\"],\n};\n\n/** Block tags that hold a body, and so indent what follows. */\nconst BLOCK_TAGS = new Set([\n\t\"if\",\n\t\"for\",\n\t\"set\",\n\t\"block\",\n\t\"component\",\n\t\"fill\",\n\t\"slot\",\n\t\"macro\",\n\t\"with\",\n\t\"cache\",\n\t\"island\",\n\t\"add\",\n\t\"apply\",\n\t\"autoescape\",\n\t\"verbatim\",\n]);\n\n/** What a tag does to indentation: opens a body, starts another branch of one, closes one, or nothing. */\nconst roleOf = (\n\tpart: DelimitedPart,\n): { kind: \"open\" | \"close\"; name: string } | { kind: \"branch\" } | null => {\n\tconst name = part.tokens[1];\n\tif (name?.type !== \"name\") return null;\n\tif (BLOCK_TAGS.has(name.value)) {\n\t\tif (\n\t\t\tname.value === \"set\" &&\n\t\t\tpart.tokens.some((token) => token.type === \"punct\" && token.value === \"=\")\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\t// `{% block title page.title %}` is the short form, with no body.\n\t\tif (name.value === \"block\" && part.tokens.length > 4) return null;\n\t\treturn { kind: \"open\", name: name.value };\n\t}\n\tif (name.value === \"else\" || name.value === \"elseif\")\n\t\treturn { kind: \"branch\" };\n\tif (name.value.startsWith(\"end\")) {\n\t\treturn { kind: \"close\", name: name.value.slice(3) };\n\t}\n\treturn null;\n};\n\nconst BLOCK_TAG = /[ \\t]*<\\/?([A-Za-z][A-Za-z0-9-]*)/y;\n\n/** Whether the line at `start` begins with a tag of an element shown on a line of its own, such as `<p>` or `</td>`, before which HTML shows no space. */\nconst startsWithBlock = (text: string, start: number): boolean => {\n\tBLOCK_TAG.lastIndex = start;\n\tconst name = BLOCK_TAG.exec(text)?.[1];\n\treturn name !== undefined && BLOCK.has(name.toLowerCase());\n};\n\nconst isLetter = (char: string | undefined) =>\n\tchar !== undefined && /[A-Za-z]/.test(char);\n\nconst isTest = (name: string) => Object.hasOwn(builtinTests, name);\n\n/** The start offset of every line. */\nconst lineStarts = (text: string): number[] => {\n\tconst starts = [0];\n\tfor (let index = text.indexOf(\"\\n\"); index !== -1;) {\n\t\tstarts.push(index + 1);\n\t\tindex = text.indexOf(\"\\n\", index + 1);\n\t}\n\treturn starts;\n};\n\n/**\n * What the output before a point may end with, as flags: the start of a line, the middle of one, or either. `UNSEEN`\n * means content the template can't see the end of, such as an include's, which may end mid-line.\n */\nconst LINE_START = 1;\nconst MID_LINE = 2;\nconst UNSEEN = 4;\n\n/** Block tags whose body renders somewhere else, such as where a macro is called, so it starts at an unknown point. */\nconst ELSEWHERE = new Set([\"macro\", \"set\", \"add\", \"component\", \"fill\"]);\n/**\n * Tags that insert content from elsewhere where they stand. A `block` may be a child template's, and a child's block\n * body renders after whatever its parent has before the block.\n */\nconst INSERTS = new Set([\"include\", \"outlet\", \"block\"]);\n/** Block tags whose output, after their end tag, may come from elsewhere: a component's, a slot's fill, a child's block. */\nconst INSERTED_BODIES = new Set([\"component\", \"slot\", \"block\"]);\n\n/**\n * The start of each line whose indentation may render in the middle of a line, so changing it changes the spacing\n * between words. Kiln removes a line holding only tags with its line break, so the next line follows whatever came\n * before them, which a trim marker can leave mid-line, as can the end of a loop's body for its next iteration.\n *\n * `unseen` holds the lines that may render mid-line only after content the template can't see the end of: what an\n * include or component inserts, or for the first line of a `set`, `macro` or `block` body, whatever comes before it\n * where it is used. Most of that content ends with a line break, so `formatEdits` keeps these lines only when\n * formatting would change them. See `movedLines`. A line starting with a block tag, such as `<p>`, is left out, since\n * HTML shows no space before it.\n */\nconst midLineStarts = (\n\ttext: string,\n\tparts: readonly Part[],\n\tstandalone: ReadonlyMap<number, number>,\n): { starts: number[]; unseen: number[] } => {\n\ttype Frame = {\n\t\tname: string;\n\t\tstart: number;\n\t\tbefore: number;\n\t\t/** For `if`, how the branches before the current one end. For `for` with `else`, how the loop's body ends. */\n\t\tends: number;\n\t\thasElse: boolean;\n\t};\n\t// How each loop's body ends, by the loop tag's start. A loop's body follows its own end, so passes repeat until\n\t// these settle. Flags only ever get added, so they do.\n\tconst loopEnds = new Map<number, number>();\n\tfor (;;) {\n\t\tconst starts: number[] = [];\n\t\tconst unseen: number[] = [];\n\t\tconst frames: Frame[] = [];\n\t\tlet settled = true;\n\t\tlet state = LINE_START;\n\t\tconst endLoop = (frame: Frame, end: number) => {\n\t\t\tif (loopEnds.get(frame.start) !== end) settled = false;\n\t\t\tloopEnds.set(frame.start, end);\n\t\t};\n\t\tfor (const [index, part] of parts.entries()) {\n\t\t\tif (part.kind === \"text\") {\n\t\t\t\tconst at = part.from;\n\t\t\t\tconst previous = parts[index - 1];\n\t\t\t\tconst next = parts[index + 1];\n\t\t\t\t// Cut at a line start by a removed line, not by a trim marker, which would trim new indentation too.\n\t\t\t\tconst cut =\n\t\t\t\t\tat > part.start &&\n\t\t\t\t\ttext[at - 1] === \"\\n\" &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tprevious !== undefined &&\n\t\t\t\t\t\tprevious.kind !== \"text\" &&\n\t\t\t\t\t\tprevious.trimAfter\n\t\t\t\t\t);\n\t\t\t\tconst shows =\n\t\t\t\t\tat < part.to ||\n\t\t\t\t\t(at === part.end &&\n\t\t\t\t\t\tnext !== undefined &&\n\t\t\t\t\t\tnext.kind !== \"text\" &&\n\t\t\t\t\t\t!next.trimBefore &&\n\t\t\t\t\t\t!standalone.has(next.start));\n\t\t\t\tif (cut && shows && state & MID_LINE) starts.push(at);\n\t\t\t\telse if (cut && shows && state & UNSEEN && !startsWithBlock(text, at)) {\n\t\t\t\t\tunseen.push(at);\n\t\t\t\t}\n\t\t\t\t// Spaces and tabs at the end leave the output where it was: at a line start, they are its indentation.\n\t\t\t\tlet end = part.to;\n\t\t\t\twhile (end > part.from && \" \\t\\r\".includes(text[end - 1] as string)) {\n\t\t\t\t\tend--;\n\t\t\t\t}\n\t\t\t\tif (end > part.from)\n\t\t\t\t\tstate = text[end - 1] === \"\\n\" ? LINE_START : MID_LINE;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (part.kind === \"output\") state = LINE_START | MID_LINE;\n\t\t\tif (part.kind !== \"tag\") continue;\n\t\t\tconst role = roleOf(part);\n\t\t\tconst name = part.tokens[1]?.value;\n\t\t\tif (name !== undefined && INSERTS.has(name)) state |= UNSEEN;\n\t\t\tif (role?.kind === \"open\") {\n\t\t\t\tframes.push({\n\t\t\t\t\tname: role.name,\n\t\t\t\t\tstart: part.start,\n\t\t\t\t\tbefore: state,\n\t\t\t\t\tends: 0,\n\t\t\t\t\thasElse: false,\n\t\t\t\t});\n\t\t\t\tif (ELSEWHERE.has(role.name)) state = LINE_START | UNSEEN;\n\t\t\t\telse if (role.name === \"for\") state |= loopEnds.get(part.start) ?? 0;\n\t\t\t} else if (role?.kind === \"branch\") {\n\t\t\t\tconst frame = frames.at(-1);\n\t\t\t\tif (!frame) continue;\n\t\t\t\tif (frame.name === \"for\") endLoop(frame, state);\n\t\t\t\tframe.ends |= state;\n\t\t\t\tframe.hasElse ||= part.tokens[1]?.value === \"else\";\n\t\t\t\tstate = frame.before;\n\t\t\t} else if (role?.kind === \"close\") {\n\t\t\t\tlet frame = frames.pop();\n\t\t\t\twhile (frame && frame.name !== role.name) frame = frames.pop();\n\t\t\t\tif (!frame) continue;\n\t\t\t\tif (frame.name === \"if\") {\n\t\t\t\t\tstate |= frame.ends | (frame.hasElse ? 0 : frame.before);\n\t\t\t\t} else if (frame.name === \"for\") {\n\t\t\t\t\tif (!frame.hasElse) endLoop(frame, state);\n\t\t\t\t\tstate |= frame.hasElse ? frame.ends : frame.before;\n\t\t\t\t} else if (ELSEWHERE.has(frame.name)) state = frame.before;\n\t\t\t\tif (INSERTED_BODIES.has(frame.name)) state |= UNSEEN;\n\t\t\t}\n\t\t}\n\t\tif (settled) return { starts, unseen };\n\t}\n};\n\n/**\n * Ranges of the template, as [start, end] offsets, whose lines the formatter leaves as they are, for each line in\n * `starts` that may render mid-line. That line's rendered indentation depends on the indentation of the lines around\n * it, through the indentation Kiln removes inside tags, so the whole top-level tag around it stays. See `midLineStarts`.\n */\nconst keptRanges = (\n\tbody: readonly Statement[],\n\tstarts: readonly number[],\n): [number, number][] => {\n\tconst ranges: [number, number][] = [];\n\tlet index = 0;\n\tfor (const start of starts) {\n\t\twhile (\n\t\t\tindex < body.length &&\n\t\t\t(body[index] as Statement).span.end <= start\n\t\t) {\n\t\t\tindex++;\n\t\t}\n\t\tconst node = body[index];\n\t\tconst range: [number, number] =\n\t\t\tnode && node.span.start <= start && node.type !== \"Text\"\n\t\t\t\t? [node.span.start, node.span.end]\n\t\t\t\t: [start, start];\n\t\tconst last = ranges.at(-1);\n\t\tif (last && range[0] <= last[1]) last[1] = Math.max(last[1], range[1]);\n\t\telse ranges.push(range);\n\t}\n\treturn ranges;\n};\n\n/**\n * Walks the template once, tracking open block tags and HTML elements, and decides how to treat each line.\n *\n * Returns the lines, which lines may lose trailing whitespace, and the outputs and tags to print.\n */\nconst planLines = (text: string, parts: readonly Part[]) => {\n\tconst starts = lineStarts(text);\n\tconst lines: Line[] = [];\n\tconst trimEnd: boolean[] = [];\n\tconst stack: Frame[] = [];\n\tlet mode: Mode = { kind: \"data\" };\n\tlet atLineStart = true;\n\t// A line that starts where the next part does, recorded when that part begins.\n\tlet pendingLine = -1;\n\n\tconst lineText = (index: number) =>\n\t\ttext.slice(starts[index], starts[index + 1] ?? text.length);\n\t/** Whether only spaces and tabs come between `offset` and the end of its line. */\n\tconst endsLine = (offset: number) => {\n\t\tlet index = offset;\n\t\twhile (index < text.length && \" \\t\\r\".includes(text[index] as string)) {\n\t\t\tindex++;\n\t\t}\n\t\treturn index === text.length || text[index] === \"\\n\";\n\t};\n\tconst current = () => lines.length - 1;\n\n\t/** Lowers the current line's level when a closing tag comes before anything else on it. */\n\tconst outdent = (line: number, level: number, first: boolean) => {\n\t\tconst info = lines[line];\n\t\tif (first && info?.kind === \"indent\") {\n\t\t\tinfo.level = Math.min(info.level, level);\n\t\t}\n\t};\n\n\tconst levelOf = (line: number): number => {\n\t\tconst info = lines[line];\n\t\treturn info?.kind === \"indent\" ? info.level : stack.length;\n\t};\n\n\t/** Records how to treat the line that starts at `start`, from the current state. */\n\tconst beginLine = (start: number) => {\n\t\tconst index = lines.length;\n\t\tconst trimmed = lineText(index).trimStart();\n\t\tatLineStart = true;\n\t\tswitch (mode.kind) {\n\t\t\tcase \"data\":\n\t\t\t\tlines.push({ kind: \"indent\", start, level: stack.length });\n\t\t\t\treturn;\n\t\t\tcase \"tag\": {\n\t\t\t\tif (mode.quote !== null) {\n\t\t\t\t\tlines.push({ kind: \"keep\", start });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst base = levelOf(mode.line);\n\t\t\t\tconst level =\n\t\t\t\t\ttrimmed.startsWith(\">\") || trimmed.startsWith(\"/>\")\n\t\t\t\t\t\t? base\n\t\t\t\t\t\t: base + 1 + mode.inner;\n\t\t\t\tlines.push({ kind: \"indent\", start, level });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"comment\":\n\t\t\t\tlines.push(\n\t\t\t\t\ttrimmed.startsWith(\"-->\")\n\t\t\t\t\t\t? { kind: \"indent\", start, level: mode.level }\n\t\t\t\t\t\t: { kind: \"shift\", start, anchor: mode.anchor },\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\tcase \"raw\":\n\t\t\t\tif (mode.keep) lines.push({ kind: \"keep\", start });\n\t\t\t\telse if (closesElement(trimmed, 0, mode.name)) {\n\t\t\t\t\tlines.push({ kind: \"indent\", start, level: mode.level });\n\t\t\t\t} else lines.push({ kind: \"shift\", start, anchor: mode.anchor });\n\t\t\t\treturn;\n\t\t\tcase \"kept\":\n\t\t\t\tlines.push(\n\t\t\t\t\tendsKept(trimmed, mode)\n\t\t\t\t\t\t? { kind: \"indent\", start, level: mode.level }\n\t\t\t\t\t\t: { kind: \"keep\", start },\n\t\t\t\t);\n\t\t}\n\t};\n\n\t/** Whether trailing whitespace on a line ending here can go. Not inside attribute values or kept elements. */\n\tconst canTrimHere = () =>\n\t\t!(mode.kind === \"tag\" && mode.quote !== null) &&\n\t\t!(mode.kind === \"raw\" && mode.keep) &&\n\t\tmode.kind !== \"kept\";\n\n\tconst finishTag = (\n\t\ttag: Extract<Mode, { kind: \"tag\" }>,\n\t\tselfClosing: boolean,\n\t) => {\n\t\tmode = { kind: \"data\" };\n\t\tconst name = tag.name;\n\t\tif (tag.closing) {\n\t\t\t// Close the nearest open element of this name, without crossing a block tag.\n\t\t\tfor (let index = stack.length - 1; index >= 0; index--) {\n\t\t\t\tconst frame = stack[index] as Frame;\n\t\t\t\tif (frame.kind === \"kiln\") break;\n\t\t\t\tif (frame.name === name) {\n\t\t\t\t\tstack.length = index;\n\t\t\t\t\toutdent(tag.line, index, tag.atLineStart);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (name.startsWith(\"!\") || selfClosing || VOID_ELEMENTS.has(name)) return;\n\t\tif (RAW_ELEMENTS.has(name) || KEPT_ELEMENTS.has(name)) {\n\t\t\tmode = {\n\t\t\t\tkind: \"raw\",\n\t\t\t\tname,\n\t\t\t\tkeep: KEPT_ELEMENTS.has(name),\n\t\t\t\tanchor: tag.line,\n\t\t\t\tlevel: stack.length,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tconst top = stack[stack.length - 1];\n\t\tif (top?.kind === \"html\" && CLOSED_BY[top.name]?.includes(name)) {\n\t\t\tstack.pop();\n\t\t\toutdent(tag.line, stack.length, tag.atLineStart);\n\t\t}\n\t\tstack.push({ kind: \"html\", name });\n\t};\n\n\t/** Starts a tag at `index` if one starts there, and returns where scanning continues. */\n\tconst startTag = (index: number, closing: boolean): number => {\n\t\tconst nameStart = index + (closing ? 2 : 1);\n\t\tlet nameEnd = nameStart;\n\t\twhile (\n\t\t\tnameEnd < text.length &&\n\t\t\t/[A-Za-z0-9:!_-]/.test(text[nameEnd] as string)\n\t\t) {\n\t\t\tnameEnd++;\n\t\t}\n\t\tmode = {\n\t\t\tkind: \"tag\",\n\t\t\tname: text.slice(nameStart, nameEnd).toLowerCase(),\n\t\t\tclosing,\n\t\t\tquote: null,\n\t\t\tline: current(),\n\t\t\tatLineStart,\n\t\t\tinner: 0,\n\t\t};\n\t\tatLineStart = false;\n\t\treturn nameEnd;\n\t};\n\n\t/** Moves through a text part one character at a time. */\n\tconst scanText = (start: number, end: number) => {\n\t\tfor (let index = start; index < end; index++) {\n\t\t\tconst char = text[index] as string;\n\t\t\tif (char === \"\\n\") {\n\t\t\t\ttrimEnd[current()] = canTrimHere();\n\t\t\t\tif (index + 1 < end) beginLine(index + 1);\n\t\t\t\telse if (index + 1 === text.length) {\n\t\t\t\t\t// The file ends with a line break: there is no further line.\n\t\t\t\t} else pendingLine = index + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tswitch (mode.kind) {\n\t\t\t\tcase \"data\":\n\t\t\t\t\tif (char === \" \" || char === \"\\t\" || char === \"\\r\") break;\n\t\t\t\t\tif (char === \"<\") {\n\t\t\t\t\t\tif (text.startsWith(\"<!--\", index)) {\n\t\t\t\t\t\t\tmode = {\n\t\t\t\t\t\t\t\tkind: \"comment\",\n\t\t\t\t\t\t\t\tanchor: current(),\n\t\t\t\t\t\t\t\tlevel: levelOf(current()),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tatLineStart = false;\n\t\t\t\t\t\t\tindex += 3;\n\t\t\t\t\t\t} else if (text[index + 1] === \"/\" && isLetter(text[index + 2])) {\n\t\t\t\t\t\t\tindex = startTag(index, true) - 1;\n\t\t\t\t\t\t} else if (isLetter(text[index + 1]) || text[index + 1] === \"!\") {\n\t\t\t\t\t\t\tindex = startTag(index, false) - 1;\n\t\t\t\t\t\t} else atLineStart = false;\n\t\t\t\t\t} else atLineStart = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"tag\":\n\t\t\t\t\tif (mode.quote !== null) {\n\t\t\t\t\t\tif (char === mode.quote) mode.quote = null;\n\t\t\t\t\t} else if (char === '\"' || char === \"'\") mode.quote = char;\n\t\t\t\t\telse if (char === \">\") finishTag(mode, text[index - 1] === \"/\");\n\t\t\t\t\telse if (char !== \" \" && char !== \"\\t\" && char !== \"\\r\") {\n\t\t\t\t\t\tatLineStart = false;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"comment\":\n\t\t\t\t\tif (text.startsWith(\"-->\", index)) {\n\t\t\t\t\t\tmode = { kind: \"data\" };\n\t\t\t\t\t\tindex += 2;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"raw\":\n\t\t\t\t\tif (char === \"<\" && closesElement(text, index, mode.name)) {\n\t\t\t\t\t\tindex = startTag(index, true) - 1;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"kept\":\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t};\n\n\t/** Applies a block tag to the stack, or to the count of block tags open inside an HTML tag. */\n\tconst applyTag = (part: DelimitedPart) => {\n\t\tconst role = roleOf(part);\n\t\tconst first = atLineStart;\n\t\tatLineStart = false;\n\t\tif (!role) return;\n\t\tif (mode.kind === \"tag\") {\n\t\t\tconst base = levelOf(mode.line) + 1;\n\t\t\tif (role.kind === \"open\") mode.inner++;\n\t\t\telse if (role.kind === \"close\") {\n\t\t\t\tmode.inner = Math.max(0, mode.inner - 1);\n\t\t\t\toutdent(current(), base + mode.inner, first);\n\t\t\t} else outdent(current(), base + mode.inner - 1, first);\n\t\t\treturn;\n\t\t}\n\t\tif (mode.kind === \"kept\") {\n\t\t\tif (role.kind === \"open\" && role.name === mode.name) mode.depth++;\n\t\t\telse if (\n\t\t\t\trole.kind === \"close\" &&\n\t\t\t\trole.name === mode.name &&\n\t\t\t\t--mode.depth === 0\n\t\t\t) {\n\t\t\t\tconst index = stack.findLastIndex((frame) => frame.kind === \"kiln\");\n\t\t\t\tif (index !== -1) stack.length = index;\n\t\t\t\tmode = { kind: \"data\" };\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (mode.kind !== \"data\") return;\n\t\tif (role.kind === \"open\") {\n\t\t\tstack.push({ kind: \"kiln\", name: role.name });\n\t\t\tif (\n\t\t\t\trole.name === \"verbatim\" ||\n\t\t\t\t((role.name === \"set\" || role.name === \"apply\") &&\n\t\t\t\t\t!(first && endsLine(part.end)))\n\t\t\t) {\n\t\t\t\tmode = {\n\t\t\t\t\tkind: \"kept\",\n\t\t\t\t\tname: role.name,\n\t\t\t\t\tdepth: 1,\n\t\t\t\t\tlevel: stack.length - 1,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst index =\n\t\t\trole.kind === \"branch\"\n\t\t\t\t? stack.findLastIndex((frame) => frame.kind === \"kiln\")\n\t\t\t\t: stack.findLastIndex(\n\t\t\t\t\t\t(frame) => frame.kind === \"kiln\" && frame.name === role.name,\n\t\t\t\t\t);\n\t\tif (index === -1) return;\n\t\t// Elements opened in this body or branch end with it.\n\t\tstack.length = role.kind === \"branch\" ? index + 1 : index;\n\t\toutdent(current(), index, first);\n\t};\n\n\tbeginLine(0);\n\tconst delimiters: { part: DelimitedPart; line: number }[] = [];\n\n\tfor (const part of parts) {\n\t\tif (pendingLine !== -1) {\n\t\t\tbeginLine(pendingLine);\n\t\t\tpendingLine = -1;\n\t\t}\n\t\tif (part.kind === \"text\") {\n\t\t\tscanText(part.start, part.end);\n\t\t\tcontinue;\n\t\t}\n\t\tconst line = current();\n\t\tif (part.kind === \"comment\") atLineStart = false;\n\t\telse {\n\t\t\tdelimiters.push({ part, line });\n\t\t\tif (part.kind === \"tag\") applyTag(part);\n\t\t\telse atLineStart = false;\n\t\t}\n\t\t// Lines that start inside this delimiter.\n\t\tfor (\n\t\t\tlet index = text.indexOf(\"\\n\", part.start);\n\t\t\tindex !== -1 && index < part.end;\n\t\t\tindex = text.indexOf(\"\\n\", index + 1)\n\t\t) {\n\t\t\ttrimEnd[current()] = part.kind === \"comment\";\n\t\t\tlines.push(\n\t\t\t\tpart.kind === \"comment\"\n\t\t\t\t\t? { kind: \"shift\", start: index + 1, anchor: line }\n\t\t\t\t\t: { kind: \"inside\", start: index + 1 },\n\t\t\t);\n\t\t}\n\t}\n\ttrimEnd[current()] ??= canTrimHere();\n\treturn { lines, trimEnd, delimiters };\n};\n\nconst widthOf = (whitespace: string, tabWidth: number): number => {\n\tlet width = 0;\n\tfor (const char of whitespace) width += char === \"\\t\" ? tabWidth : 1;\n\treturn width;\n};\n\n/**\n * Works out the edits that format a template, without checking them. See `formatEdits`.\n */\nconst planEdits = (\n\ttext: string,\n\tparts: readonly Part[],\n\tkept: readonly [number, number][],\n\toptions: Required<Omit<FormatOptions, \"range\">>,\n): FormatEdit[] => {\n\tconst { useTabs, tabWidth } = options;\n\tconst unit = useTabs ? \"\\t\" : \" \".repeat(tabWidth);\n\tconst indentOfWidth = (width: number) =>\n\t\tuseTabs\n\t\t\t? \"\\t\".repeat(Math.floor(width / tabWidth)) + \" \".repeat(width % tabWidth)\n\t\t\t: \" \".repeat(width);\n\tconst { lines, trimEnd, delimiters } = planLines(text, parts);\n\t// Lines that overlap a kept range stay as they are. Both lists are in source order.\n\tlet range = 0;\n\tfor (const [index, line] of lines.entries()) {\n\t\tconst next = lines[index + 1]?.start ?? text.length + 1;\n\t\twhile (\n\t\t\trange < kept.length &&\n\t\t\t(kept[range] as [number, number])[1] < line.start\n\t\t) {\n\t\t\trange++;\n\t\t}\n\t\tconst overlaps =\n\t\t\trange < kept.length && (kept[range] as [number, number])[0] < next;\n\t\tif (overlaps && (line.kind === \"indent\" || line.kind === \"shift\")) {\n\t\t\tlines[index] = { kind: \"keep\", start: line.start };\n\t\t}\n\t}\n\n\tconst oldIndent = (line: number) => {\n\t\tconst start = lines[line]?.start ?? 0;\n\t\tlet end = start;\n\t\twhile (text[end] === \" \" || text[end] === \"\\t\") end++;\n\t\treturn text.slice(start, end);\n\t};\n\t/** Where a line's content ends: at its line break, or the end of the file. */\n\tconst lineEnd = (line: number) => {\n\t\tconst next = lines[line + 1]?.start;\n\t\tif (next !== undefined) return next - 1;\n\t\treturn text.endsWith(\"\\n\") ? text.length - 1 : text.length;\n\t};\n\tconst isBlank = (line: number) => {\n\t\tconst info = lines[line] as Line;\n\t\treturn (\n\t\t\tinfo.kind !== \"keep\" &&\n\t\t\tinfo.kind !== \"inside\" &&\n\t\t\ttext.slice(info.start, lineEnd(line)).trim() === \"\"\n\t\t);\n\t};\n\n\t// Whitespace before the first content and after the last is output as written wherever the template is placed, so\n\t// it stays as it is, as does a file of only whitespace.\n\tlet firstContent = 0;\n\twhile (firstContent < lines.length && isBlank(firstContent)) firstContent++;\n\tlet lastContent = lines.length - 1;\n\twhile (lastContent >= 0 && isBlank(lastContent)) lastContent--;\n\n\tconst newIndents = new Map<number, string | null>();\n\tconst newIndent = (line: number): string | null => {\n\t\tif (newIndents.has(line)) return newIndents.get(line) ?? null;\n\t\tconst info = lines[line];\n\t\tlet indent: string | null = null;\n\t\tif (info?.kind === \"indent\") {\n\t\t\t// The first content line keeps its indentation. See `firstContent`.\n\t\t\tindent =\n\t\t\t\tline === firstContent ? oldIndent(line) : unit.repeat(info.level);\n\t\t} else if (info?.kind === \"shift\") {\n\t\t\tconst anchor = newIndent(info.anchor);\n\t\t\tconst moved =\n\t\t\t\tanchor === null\n\t\t\t\t\t? 0\n\t\t\t\t\t: widthOf(anchor, tabWidth) -\n\t\t\t\t\t\twidthOf(oldIndent(info.anchor), tabWidth);\n\t\t\tindent = indentOfWidth(\n\t\t\t\tMath.max(0, widthOf(oldIndent(line), tabWidth) + moved),\n\t\t\t);\n\t\t}\n\t\tnewIndents.set(line, indent);\n\t\treturn indent;\n\t};\n\n\tconst edits: FormatEdit[] = [];\n\t// Blank lines go where the line before is blank too, so runs become one.\n\tlet previousBlank = false;\n\n\tfor (const [index, info] of lines.entries()) {\n\t\tif (index > lastContent) break;\n\t\tif (index < firstContent) continue;\n\t\tconst start = info.start;\n\t\tconst end = lineEnd(index);\n\t\tif (isBlank(index)) {\n\t\t\tif (info.kind === \"indent\" && previousBlank) {\n\t\t\t\tedits.push({ start, end: end + 1, text: \"\" });\n\t\t\t} else if (end > start) edits.push({ start, end, text: \"\" });\n\t\t\tpreviousBlank = true;\n\t\t\tcontinue;\n\t\t}\n\t\tpreviousBlank = false;\n\n\t\tconst indent = newIndent(index);\n\t\tif (indent !== null) {\n\t\t\tconst current = oldIndent(index);\n\t\t\tif (current !== indent) {\n\t\t\t\tedits.push({ start, end: start + current.length, text: indent });\n\t\t\t}\n\t\t}\n\t\tif (!trimEnd[index] || info.kind === \"keep\") continue;\n\t\tif (index !== lastContent) {\n\t\t\tlet from = end;\n\t\t\twhile (from > start && /[ \\t\\r]/.test(text[from - 1] as string)) from--;\n\t\t\tif (from < end && !insideDelimiter(delimiters, from)) {\n\t\t\t\tedits.push({ start: from, end, text: \"\" });\n\t\t\t}\n\t\t} else if (text[end - 1] === \"\\r\" && text[end] === \"\\n\") {\n\t\t\t// The last content line keeps its trailing spaces, but its line break still becomes `\\n`.\n\t\t\tedits.push({ start: end - 1, end, text: \"\" });\n\t\t}\n\t}\n\n\t// The new indentation of lines that start inside a delimiter, from how that delimiter printed them, for a delimiter\n\t// that starts on one, as in `}} {{ b`.\n\tconst insideIndents = new Map<number, string>();\n\tfor (const { part, line } of delimiters) {\n\t\tconst indent =\n\t\t\tnewIndent(line) ?? insideIndents.get(line) ?? oldIndent(line);\n\t\tconst source = text.slice(part.start, part.end);\n\t\tconst printed = printDelimiter(text, part, indent, unit);\n\t\tif (printed !== null && printed !== source) {\n\t\t\tedits.push({ start: part.start, end: part.end, text: printed });\n\t\t}\n\t\tconst lastBreak = (printed ?? source).lastIndexOf(\"\\n\");\n\t\tif (lastBreak !== -1) {\n\t\t\tconst endLine = line + (source.match(/\\n/g)?.length ?? 0);\n\t\t\tconst after = (printed ?? source).slice(lastBreak + 1);\n\t\t\tinsideIndents.set(endLine, /^[ \\t]*/.exec(after)?.[0] ?? \"\");\n\t\t}\n\t}\n\n\treturn edits.sort((a, b) => a.start - b.start || a.end - b.end);\n};\n\n/** Whether `offset` is strictly inside one of `delimiters`, which are in source order. */\nconst insideDelimiter = (\n\tdelimiters: readonly { part: DelimitedPart }[],\n\toffset: number,\n) => {\n\t// The last delimiter that starts before `offset`.\n\tlet low = 0;\n\tlet high = delimiters.length;\n\twhile (low < high) {\n\t\tconst middle = (low + high) >>> 1;\n\t\tif ((delimiters[middle] as { part: DelimitedPart }).part.start < offset) {\n\t\t\tlow = middle + 1;\n\t\t} else high = middle;\n\t}\n\tconst before = delimiters[low - 1];\n\treturn before !== undefined && offset < before.part.end;\n};\n\nconst applyEdits = (text: string, edits: readonly FormatEdit[]): string => {\n\tlet out = \"\";\n\tlet position = 0;\n\tfor (const edit of edits) {\n\t\tout += text.slice(position, edit.start) + edit.text;\n\t\tposition = edit.end;\n\t}\n\treturn out + text.slice(position);\n};\n\n/**\n * How the safety check compares the leading whitespace of a line that may render mid-line: `exact`ly, or only whether\n * there is `any`, since HTML shows any run of it as one space. See `midLineStarts`.\n */\ntype MidLine = \"exact\" | \"any\";\n\n/** The lines of a template that may render mid-line, by their start, and how to compare each. */\nconst midLinesOf = (\n\ttext: string,\n\tparts: readonly Part[],\n\tstandalone: ReadonlyMap<number, number>,\n) => {\n\tconst { starts, unseen } = midLineStarts(text, parts, standalone);\n\tconst kinds = new Map<number, MidLine>();\n\tfor (const start of starts) kinds.set(start, \"exact\");\n\tfor (const start of unseen) kinds.set(start, \"any\");\n\treturn { starts, unseen, kinds };\n};\n\n/**\n * Removes whitespace at the start and end of lines, and blank lines, which the formatter may change. With `midLine`,\n * the text starts a line that may render mid-line, so its leading spaces and tabs stay, or for `any`, whether it has any.\n */\nconst normaliseText = (value: string, midLine: MidLine | undefined) => {\n\tconst indent = midLine ? (/^[ \\t]*/.exec(value)?.[0] ?? \"\") : \"\";\n\treturn (\n\t\t(midLine === \"any\" && indent !== \"\" ? \" \" : indent) +\n\t\tvalue\n\t\t\t.slice(indent.length)\n\t\t\t// Only from the start of a run, so a long run is not searched again from each of its characters.\n\t\t\t.replace(/(?<![ \\t\\r\\f\\v])[ \\t\\r\\f\\v]+$/gm, \"\")\n\t\t\t.replace(/^[ \\t\\f\\v]+/gm, \"\")\n\t\t\t.replace(/\\n{2,}/g, \"\\n\")\n\t);\n};\n\n/**\n * A copy of a syntax tree without positions or layout, with text normalised and text left empty by that removed.\n * Text starting at one of `midLine` keeps its leading whitespace. See `midLineStarts`.\n */\nconst normaliseTree = (\n\tvalue: unknown,\n\tmidLine: ReadonlyMap<number, MidLine>,\n): unknown => {\n\tif (Array.isArray(value)) {\n\t\treturn value\n\t\t\t.map((item) => normaliseTree(item, midLine))\n\t\t\t.filter(\n\t\t\t\t(item) =>\n\t\t\t\t\t!(\n\t\t\t\t\t\ttypeof item === \"object\" &&\n\t\t\t\t\t\titem !== null &&\n\t\t\t\t\t\t(item as { type?: unknown }).type === \"Text\" &&\n\t\t\t\t\t\t(item as { value?: unknown }).value === \"\"\n\t\t\t\t\t),\n\t\t\t);\n\t}\n\tif (typeof value !== \"object\" || value === null) return value;\n\tconst node = value as { type?: unknown; span?: Span };\n\tconst copy: Record<string, unknown> = {};\n\tfor (const [key, item] of Object.entries(value)) {\n\t\tif (key === \"span\" || key === \"nameSpan\" || key === \"indent\") continue;\n\t\tcopy[key] =\n\t\t\tkey === \"value\" && node.type === \"Text\"\n\t\t\t\t? normaliseText(item as string, midLine.get(node.span?.start ?? -1))\n\t\t\t\t: normaliseTree(item, midLine);\n\t}\n\treturn copy;\n};\n\n/** A syntax tree as JSON, without the whitespace the formatter may change, so two trees can be compared. */\nconst shape = (\n\tvalue: TemplateNode | Statement,\n\tmidLine: ReadonlyMap<number, MidLine>,\n): string => JSON.stringify(normaliseTree(value, midLine));\n\n/**\n * The lines in `unseen` whose rendered indentation formatting changes, as the safety check compares it: those in a\n * top-level statement that differs once formatted. `formatEdits` keeps these, with the statement, as written.\n */\nconst movedLines = (\n\tbefore: { body: readonly Statement[]; kinds: ReadonlyMap<number, MidLine> },\n\tafter: { body: readonly Statement[]; kinds: ReadonlyMap<number, MidLine> },\n\tunseen: readonly number[],\n): number[] => {\n\t// Formatting only changes whitespace, so the statements match one to one. Keep every line if they somehow don't.\n\tif (before.body.length !== after.body.length) return [...unseen];\n\tconst moved: number[] = [];\n\tlet index = 0;\n\tfor (const [position, node] of before.body.entries()) {\n\t\tconst inside: number[] = [];\n\t\tfor (; index < unseen.length; index++) {\n\t\t\tconst start = unseen[index] as number;\n\t\t\tif (start >= node.span.end) break;\n\t\t\tif (start >= node.span.start) inside.push(start);\n\t\t}\n\t\tif (\n\t\t\tinside.length > 0 &&\n\t\t\tshape(node, before.kinds) !==\n\t\t\t\tshape(after.body[position] as Statement, after.kinds)\n\t\t) {\n\t\t\tmoved.push(...inside);\n\t\t}\n\t}\n\treturn moved;\n};\n\n/**\n * Works out the edits that format a template, in source order and never overlapping. Editors apply these so the cursor and undo history stay put. See `format` for what it throws.\n */\nexport const formatEdits = (\n\ttext: string,\n\toptions: FormatOptions = {},\n): FormatEdit[] => {\n\tconst parsed = parse(text, { isTest });\n\tif (parsed.problems.length > 0) {\n\t\tconst source = new Source(\"template.kiln\", text);\n\t\tthrow new KilnSyntaxError(\n\t\t\tparsed.problems.map((problem) =>\n\t\t\t\tcreateDiagnostic(source, problem.code, problem.message, problem.span),\n\t\t\t),\n\t\t\tsource,\n\t\t);\n\t}\n\n\tconst tabWidth = options.tabWidth ?? 4;\n\tif (!Number.isInteger(tabWidth) || tabWidth < 1) {\n\t\tthrow new RangeError(\n\t\t\t`tabWidth must be a whole number of at least 1, but got ${tabWidth}`,\n\t\t);\n\t}\n\tconst { parts, standalone } = scanControlled(text);\n\tconst before = midLinesOf(text, parts, standalone);\n\tconst range = options.range;\n\t/** The edits, keeping lines starting at `starts` as written, with the top-level tags around them. */\n\tconst plan = (starts: readonly number[]) => {\n\t\tconst edits = planEdits(text, parts, keptRanges(parsed.ast.body, starts), {\n\t\t\tuseTabs: options.useTabs ?? true,\n\t\t\ttabWidth,\n\t\t});\n\t\treturn range\n\t\t\t? edits.filter(\n\t\t\t\t\t(edit) => edit.end >= range.start && edit.start <= range.end,\n\t\t\t\t)\n\t\t\t: edits;\n\t};\n\tconst formatWith = (starts: readonly number[]) => {\n\t\tconst edits = plan(starts);\n\t\tconst formatted = applyEdits(text, edits);\n\t\tconst changed = parse(formatted, { isTest });\n\t\tconst scanned = scanControlled(formatted);\n\t\treturn {\n\t\t\tedits,\n\t\t\tchanged,\n\t\t\tkinds: midLinesOf(formatted, scanned.parts, scanned.standalone).kinds,\n\t\t};\n\t};\n\n\tlet result = formatWith(before.starts);\n\t// Lines after unseen content usually render at a line start, so they stay as written only when formatting moves\n\t// them. Keeping a statement leaves alone the lines it shares with the next, which can move another, so this repeats.\n\tlet kept = before.starts;\n\tfor (let unseen = before.unseen; result.changed.problems.length === 0;) {\n\t\tconst moved = movedLines(\n\t\t\t{ body: parsed.ast.body, kinds: before.kinds },\n\t\t\t{ body: result.changed.ast.body, kinds: result.kinds },\n\t\t\tunseen,\n\t\t);\n\t\tif (moved.length === 0) break;\n\t\tkept = [...kept, ...moved].sort((a, b) => a - b);\n\t\tconst done = new Set(moved);\n\t\tunseen = unseen.filter((start) => !done.has(start));\n\t\tresult = formatWith(kept);\n\t}\n\n\tconst { edits, changed, kinds } = result;\n\tif (\n\t\tchanged.problems.length > 0 ||\n\t\tshape(changed.ast, kinds) !== shape(parsed.ast, before.kinds)\n\t) {\n\t\tthrow new KilnFormatError(\n\t\t\t\"Formatting would have changed what this template renders, so nothing was changed. This is a bug in Kiln's formatter.\",\n\t\t);\n\t}\n\treturn edits;\n};\n\n/**\n * Formats a template: indents it to match its structure, and tidies spacing inside outputs and tags. Never changes what it renders.\n *\n * Throws `KilnSyntaxError` when the template has syntax errors, `KilnFormatError` if the safety check fails, and\n * `RangeError` for a `tabWidth` that isn't a whole number of at least 1.\n *\n * ```ts\n * const formatted = format(source, { useTabs: false, tabWidth: 2 });\n * ```\n */\nexport const format = (text: string, options: FormatOptions = {}): string =>\n\tapplyEdits(text, formatEdits(text, options));\n"],"mappings":";;;AAmCA,MAAM,2BAAW,IAAI,IAAI;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,MAAM,YAAY,QAAgB,WAAsC;CACvE,MAAM,SAAkB,CAAC;CACzB,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;EACnD,MAAM,QAAQ,OAAO;EACrB,IAAI,MAAM,MAAM;EAChB,IAAI,MAAM,SAAS,eAAe;GACjC,IAAI,QAAQ;GACZ,OAAO,QAAQ,OAAO,QAAQ,SAAS;IACtC,MAAM,QAAQ,OAAO;IACrB,IAAI,MAAM,SAAS,eAAe;SAC7B,IAAI,MAAM,SAAS,eAAe,EAAE,UAAU,GAAG;GACvD;GACA,MAAO,OAAO,KAAK,IAAI,OAAO,OAAO,SAAS,CAAC,EAAE,CAAW;EAC7D;EACA,OAAO,KAAK;GACX,MAAM,MAAM,SAAS,gBAAgB,WAAW,MAAM;GACtD,MAAM,OAAO,MAAM,MAAM,OAAO,GAAG;GACnC,OAAO,MAAM;GACb;EACD,CAAC;CACF;CACA,OAAO;AACR;;AAGA,MAAM,WAAW,QA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E,MAAM,QAAQ,WACb;GAAE,MAAM,OAAO,IAAI;GAAM,OAAO,OAAO;EAAM,GAC7C;GAAE,MAAM,OAAO,QAAQ,IAAI;GAAM,OAAO,OAAO;EAAM,GACrD,MACD;EACA,IAAI,MAAM,WAAW,GAAG;EACxB,OAAO,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;EAC/C,MAAM,OAAO,IAAI,IAAI,KAAK;EAC1B,SAAS,OAAO,QAAQ,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC;EAClD,SAAS,WAAW,IAAI;CACzB;CAEA,MAAM,EAAE,OAAO,SAAS,UAAU;CAClC,IACC,QAAQ,SAAS,SAAS,KAC1B,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM,OAAO,KAAK,OAAO,KAAK,GAE5D,MAAM,IAAI,gBACT,sHACD;CAED,OAAO;AACR;;;;;;;;;;;AAYA,MAAa,UAAU,MAAc,UAAyB,CAAC,MAC9D,WAAW,MAAM,YAAY,MAAM,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"format-B5w2QhSr.js","names":[],"sources":["../src/formatter/delimiters.ts","../src/formatter/format.ts"],"sourcesContent":["import type { DelimitedPart, Token } from \"../lexer/lexer.js\";\n\n/** A token as the formatter prints it: its source text, unchanged. An interpolated string is one piece. */\ntype Piece = {\n\ttype: Token[\"type\"];\n\ttext: string;\n\tstart: number;\n\tend: number;\n};\n\n/**\n * What a piece does, where that changes its spacing.\n *\n * - `word`: a name, number or string.\n * - `keyword`: a tag's name, or a name such as `and` or `in`. A bracket after it groups rather than calls.\n * - `unary`: a sign that makes a number negative or positive, written against its operand.\n * - `tight`: `.`, `?.`, `..` and a filter's `|`, with no space either side.\n * - `key`: the colon after a key or named argument, or `?` and `?:` marking an optional key in `props`.\n * - `call`: a bracket that calls or indexes the piece before it.\n * - `open`, `close`: other brackets.\n * - `spaced`: operators with a space either side.\n */\ntype Role =\n\t| \"word\"\n\t| \"keyword\"\n\t| \"unary\"\n\t| \"tight\"\n\t| \"key\"\n\t| \"call\"\n\t| \"open\"\n\t| \"close\"\n\t| \"comma\"\n\t| \"spread\"\n\t| \"spaced\";\n\nconst KEYWORDS = new Set([\n\t\"and\",\n\t\"or\",\n\t\"not\",\n\t\"in\",\n\t\"is\",\n\t\"starts\",\n\t\"ends\",\n\t\"with\",\n\t\"as\",\n\t\"import\",\n\t\"ignore\",\n\t\"missing\",\n]);\n\n/** Joins each interpolated string's tokens, from `stringStart` to its matching `stringEnd`, into one piece. */\nconst toPieces = (source: string, tokens: readonly Token[]): Piece[] => {\n\tconst pieces: Piece[] = [];\n\tfor (let index = 0; index < tokens.length; index++) {\n\t\tconst token = tokens[index] as Token;\n\t\tlet end = token.end;\n\t\tif (token.type === \"stringStart\") {\n\t\t\tlet depth = 0;\n\t\t\tfor (; index < tokens.length; index++) {\n\t\t\t\tconst inner = tokens[index] as Token;\n\t\t\t\tif (inner.type === \"stringStart\") depth++;\n\t\t\t\telse if (inner.type === \"stringEnd\" && --depth === 0) break;\n\t\t\t}\n\t\t\tend = (tokens[Math.min(index, tokens.length - 1)] as Token).end;\n\t\t}\n\t\tpieces.push({\n\t\t\ttype: token.type === \"stringStart\" ? \"string\" : token.type,\n\t\t\ttext: source.slice(token.start, end),\n\t\t\tstart: token.start,\n\t\t\tend,\n\t\t});\n\t}\n\treturn pieces;\n};\n\n/** Works out each piece's role. `isTag` means the first piece is a tag's name. */\nconst rolesOf = (pieces: readonly Piece[], isTag: boolean): Role[] => {\n\tconst roles: Role[] = [];\n\t// In `props`, `|` joins types and `?:` marks an optional key, until `=` starts a default value.\n\tconst props = isTag && pieces[0]?.text === \"props\";\n\tlet inDefault = false;\n\t// Open `?`s at each bracket depth, so a conditional's `:` can be told from a key's.\n\tconst conditionals: number[] = [0];\n\n\tfor (const [index, piece] of pieces.entries()) {\n\t\tconst previous = roles[index - 1];\n\t\tconst depth = conditionals.length - 1;\n\t\tconst types = props && !inDefault;\n\t\tlet role: Role;\n\n\t\tif (piece.type !== \"punct\") {\n\t\t\trole =\n\t\t\t\t(isTag && index === 0) ||\n\t\t\t\t(piece.type === \"name\" && KEYWORDS.has(piece.text))\n\t\t\t\t\t? \"keyword\"\n\t\t\t\t\t: \"word\";\n\t\t} else {\n\t\t\tswitch (piece.text) {\n\t\t\t\tcase \"(\":\n\t\t\t\tcase \"[\":\n\t\t\t\t\trole = previous === \"word\" || previous === \"close\" ? \"call\" : \"open\";\n\t\t\t\t\tconditionals.push(0);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"{\":\n\t\t\t\t\trole = \"open\";\n\t\t\t\t\tconditionals.push(0);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \")\":\n\t\t\t\tcase \"]\":\n\t\t\t\tcase \"}\":\n\t\t\t\t\trole = \"close\";\n\t\t\t\t\tif (conditionals.length > 1) conditionals.pop();\n\t\t\t\t\tbreak;\n\t\t\t\tcase \",\":\n\t\t\t\t\trole = \"comma\";\n\t\t\t\t\tif (props && depth === 0) inDefault = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"...\":\n\t\t\t\t\trole = \"spread\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \".\":\n\t\t\t\tcase \"?.\":\n\t\t\t\tcase \"..\":\n\t\t\t\t\trole = \"tight\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"|\":\n\t\t\t\t\trole = types ? \"spaced\" : \"tight\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"-\":\n\t\t\t\tcase \"+\":\n\t\t\t\t\trole =\n\t\t\t\t\t\tprevious === undefined ||\n\t\t\t\t\t\t(previous !== \"word\" && previous !== \"close\")\n\t\t\t\t\t\t\t? \"unary\"\n\t\t\t\t\t\t\t: \"spaced\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"?\":\n\t\t\t\tcase \"?:\":\n\t\t\t\t\trole = types ? \"key\" : \"spaced\";\n\t\t\t\t\tif (piece.text === \"?\" && !types) {\n\t\t\t\t\t\tconditionals[depth] = (conditionals[depth] ?? 0) + 1;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \":\":\n\t\t\t\t\tif ((conditionals[depth] ?? 0) > 0) {\n\t\t\t\t\t\tconditionals[depth] = (conditionals[depth] ?? 0) - 1;\n\t\t\t\t\t\trole = \"spaced\";\n\t\t\t\t\t} else role = \"key\";\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\trole = \"spaced\";\n\t\t\t\t\tif (props && depth === 0 && piece.text === \"=\") inDefault = true;\n\t\t\t}\n\t\t}\n\t\troles.push(role);\n\t}\n\treturn roles;\n};\n\n/** The gap between two pieces: a space or nothing. */\nconst gapBetween = (\n\tprevious: Piece,\n\tpreviousRole: Role,\n\tpiece: Piece,\n\trole: Role,\n): string => {\n\tif (role === \"comma\" || role === \"tight\" || role === \"key\" || role === \"call\")\n\t\treturn \"\";\n\tif (role === \"close\") {\n\t\treturn piece.text === \"}\" && previous.text !== \"{\" ? \" \" : \"\";\n\t}\n\tif (previousRole === \"tight\" || previousRole === \"unary\") return \"\";\n\tif (previousRole === \"spread\") return \"\";\n\tif (previousRole === \"open\" || previousRole === \"call\") {\n\t\treturn previous.text === \"{\" ? \" \" : \"\";\n\t}\n\treturn \" \";\n};\n\n/**\n * Whether `pieces[index]`, a number after a `.`, would join the number before the `.` if printed against it, as `1 . 5`\n * would read as `1.5`. A number right after `.` or `?.` is read as a whole number, so `items.0 . 1` can't join.\n */\nconst joinsNumber = (pieces: readonly Piece[], index: number): boolean => {\n\tconst number = pieces[index - 2];\n\tconst before = pieces[index - 3]?.text;\n\treturn (\n\t\tpieces[index]?.type === \"number\" &&\n\t\tpieces[index - 1]?.text === \".\" &&\n\t\tnumber?.type === \"number\" &&\n\t\t!number.text.includes(\".\") &&\n\t\tbefore !== \".\" &&\n\t\tbefore !== \"?.\"\n\t);\n};\n\n/**\n * Prints one output or tag with normalised spacing. Line breaks between tokens stay; each line after one is indented from `indent`, one step further or to match the brackets it sits inside, using `unit` per step.\n *\n * Returns null for a delimiter that never closed, which the formatter leaves as it is.\n */\nexport const printDelimiter = (\n\tsource: string,\n\tpart: DelimitedPart,\n\tindent: string,\n\tunit: string,\n): string | null => {\n\tconst tokens = part.tokens;\n\tconst open = tokens[0];\n\tconst close = tokens[tokens.length - 1];\n\tif (!open || !close || close.value === \"\" || tokens.length < 3) return null;\n\n\tconst pieces = toPieces(source, tokens.slice(1, -1));\n\tconst roles = rolesOf(pieces, part.kind === \"tag\");\n\tlet out = open.value;\n\tlet previousEnd = part.start + open.value.length;\n\t// The line each open bracket started on. Brackets opened on the same line add one step between them.\n\tconst openedOn: number[] = [];\n\tlet line = 0;\n\t/** Steps of indentation for a new line, once `closers` brackets at its start have closed. */\n\tconst steps = (closers: number) =>\n\t\tnew Set(openedOn.slice(0, openedOn.length - closers)).size;\n\n\tfor (const [index, piece] of pieces.entries()) {\n\t\tconst role = roles[index] as Role;\n\t\tconst gap = source.slice(previousEnd, piece.start);\n\t\tif (gap.includes(\"\\n\")) {\n\t\t\tline++;\n\t\t\t// Closing brackets at the start of a line line up with the line that opened them. Only those on this line count.\n\t\t\tlet closers = 0;\n\t\t\twhile (\n\t\t\t\troles[index + closers] === \"close\" &&\n\t\t\t\t(closers === 0 ||\n\t\t\t\t\t!source\n\t\t\t\t\t\t.slice(\n\t\t\t\t\t\t\t(pieces[index + closers - 1] as Piece).end,\n\t\t\t\t\t\t\t(pieces[index + closers] as Piece).start,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.includes(\"\\n\"))\n\t\t\t) {\n\t\t\t\tclosers++;\n\t\t\t}\n\t\t\tout += `\\n${indent}${unit.repeat(closers > 0 ? steps(closers) : Math.max(steps(0), 1))}`;\n\t\t} else if (index === 0) out += \" \";\n\t\telse if (joinsNumber(pieces, index)) out += \" \";\n\t\telse {\n\t\t\tout += gapBetween(\n\t\t\t\tpieces[index - 1] as Piece,\n\t\t\t\troles[index - 1] as Role,\n\t\t\t\tpiece,\n\t\t\t\trole,\n\t\t\t);\n\t\t}\n\t\tout += piece.text;\n\t\tif (role === \"open\" || role === \"call\") openedOn.push(line);\n\t\telse if (role === \"close\") openedOn.pop();\n\t\tpreviousEnd = piece.end;\n\t}\n\n\tconst closeStart = part.end - close.value.length;\n\tout += source.slice(previousEnd, closeStart).includes(\"\\n\")\n\t\t? `\\n${indent}`\n\t\t: \" \";\n\treturn out + close.value;\n};\n","import { builtinTests } from \"../builtins/functions.js\";\nimport { KilnSyntaxError } from \"../errors.js\";\nimport { createDiagnostic } from \"../errors.js\";\nimport { BLOCK } from \"../html/data.js\";\nimport {\n\ttype DelimitedPart,\n\ttype Part,\n\tscanControlled,\n} from \"../lexer/lexer.js\";\nimport type { Statement, TemplateNode } from \"../parser/ast.js\";\nimport { parse } from \"../parser/parser.js\";\nimport { type Span, Source } from \"../source.js\";\nimport { printDelimiter } from \"./delimiters.js\";\n\nexport type FormatOptions = {\n\t/** Indent with tabs. Default `true`. */\n\tuseTabs?: boolean;\n\t/** Spaces per step without tabs, and the width of a tab when moving lines. A whole number of at least 1. Default `4`. */\n\ttabWidth?: number;\n\t/** Only format lines that overlap this range of offsets. */\n\trange?: { start: number; end: number };\n};\n\n/** Replace `start` to `end` of the original source with `text`. */\nexport type FormatEdit = { start: number; end: number; text: string };\n\n/** Thrown when formatting would have changed what a template renders. That is a bug in the formatter. */\nexport class KilnFormatError extends Error {\n\toverride name = \"KilnFormatError\";\n}\n\n/**\n * How the formatter treats one line.\n *\n * - `indent`: set its indentation to `level` steps.\n * - `shift`: move it by as much as line `anchor` moved, keeping its own indentation relative to it. For scripts, styles and comments.\n * - `keep`: leave it alone, for `<pre>`, `<textarea>`, `verbatim`, text inside attribute values, and the body of a `set` or `apply` whose tag shares its line.\n * - `inside`: it starts inside an output or tag, which `printDelimiter` indents.\n */\ntype Line =\n\t| { kind: \"indent\"; start: number; level: number }\n\t| { kind: \"shift\"; start: number; anchor: number }\n\t| { kind: \"keep\" | \"inside\"; start: number };\n\ntype Frame = { kind: \"kiln\" | \"html\"; name: string };\n\n/**\n * Where the scanner is in the HTML.\n *\n * - `tag`: inside `<name ...>` or `</name>`, which started on line `line`. `inner` counts block tags open inside it.\n * - `raw`: inside `<script>` or `<style>`, or kept as written inside `<pre>`, `<textarea>` and the like.\n * - `kept`: inside the body of block tag `name`, output as written: `verbatim`, or a `set` or `apply` whose tag shares\n * its line, where Kiln doesn't remove the body's indentation. `depth` counts the tags of that name open.\n */\ntype Mode =\n\t| { kind: \"data\" }\n\t| {\n\t\t\tkind: \"tag\";\n\t\t\tname: string;\n\t\t\tclosing: boolean;\n\t\t\tquote: string | null;\n\t\t\tline: number;\n\t\t\tatLineStart: boolean;\n\t\t\tinner: number;\n\t }\n\t| { kind: \"comment\"; anchor: number; level: number }\n\t| { kind: \"raw\"; name: string; keep: boolean; anchor: number; level: number }\n\t| { kind: \"kept\"; name: string; depth: number; level: number };\n\nconst VOID_ELEMENTS = new Set([\n\t\"area\",\n\t\"base\",\n\t\"br\",\n\t\"col\",\n\t\"embed\",\n\t\"hr\",\n\t\"img\",\n\t\"input\",\n\t\"link\",\n\t\"meta\",\n\t\"source\",\n\t\"track\",\n\t\"wbr\",\n]);\n\n/** Elements written in `<script>` or `<style>`'s own language, whose lines move together. */\nconst RAW_ELEMENTS = new Set([\"script\", \"style\"]);\n/** Elements whose whitespace shows on the page. Nothing closes `<plaintext>`. */\nconst KEPT_ELEMENTS = new Set([\n\t\"pre\",\n\t\"textarea\",\n\t\"xmp\",\n\t\"listing\",\n\t\"plaintext\",\n]);\n\n/** Whether `</name` starts at `index`, as a whole tag name. */\nconst closesElement = (text: string, index: number, name: string): boolean => {\n\tif (name === \"plaintext\") return false;\n\tconst end = index + 2 + name.length;\n\treturn (\n\t\ttext.slice(index, end).toLowerCase() === `</${name}` &&\n\t\t(end === text.length || /[\\s/>]/.test(text[end] as string))\n\t);\n};\n\n/**\n * Whether a line starting with `trimmed` begins with the tag that ends the outermost `kept` body, and the formatter\n * may indent it. It may when Kiln removes the whitespace before the tag: a `-` trim marker, or a tag alone on its line.\n */\nconst endsKept = (\n\ttrimmed: string,\n\tmode: Extract<Mode, { kind: \"kept\" }>,\n): boolean => {\n\tconst match = /^\\{%(-?)\\s*end([A-Za-z]+)\\s*-?%\\}([^\\n]*)/.exec(trimmed);\n\treturn (\n\t\tmatch !== null &&\n\t\tmatch[2] === mode.name &&\n\t\tmode.depth === 1 &&\n\t\t(match[1] === \"-\" || /^[ \\t\\r]*$/.test(match[3] as string))\n\t);\n};\n\n/** Elements that the next of these siblings closes, such as a `<li>` without `</li>`. */\nconst CLOSED_BY: Record<string, readonly string[]> = {\n\tli: [\"li\"],\n\tdt: [\"dt\", \"dd\"],\n\tdd: [\"dt\", \"dd\"],\n\tp: [\"p\"],\n\toption: [\"option\"],\n\ttr: [\"tr\"],\n\ttd: [\"td\", \"th\"],\n\tth: [\"td\", \"th\"],\n\tthead: [\"tbody\", \"tfoot\"],\n\ttbody: [\"tbody\", \"tfoot\"],\n};\n\n/** Block tags that hold a body, and so indent what follows. */\nconst BLOCK_TAGS = new Set([\n\t\"if\",\n\t\"for\",\n\t\"set\",\n\t\"block\",\n\t\"component\",\n\t\"fill\",\n\t\"slot\",\n\t\"macro\",\n\t\"with\",\n\t\"cache\",\n\t\"island\",\n\t\"add\",\n\t\"apply\",\n\t\"autoescape\",\n\t\"verbatim\",\n]);\n\n/** What a tag does to indentation: opens a body, starts another branch of one, closes one, or nothing. */\nconst roleOf = (\n\tpart: DelimitedPart,\n): { kind: \"open\" | \"close\"; name: string } | { kind: \"branch\" } | null => {\n\tconst name = part.tokens[1];\n\tif (name?.type !== \"name\") return null;\n\tif (BLOCK_TAGS.has(name.value)) {\n\t\tif (\n\t\t\tname.value === \"set\" &&\n\t\t\tpart.tokens.some((token) => token.type === \"punct\" && token.value === \"=\")\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\t// `{% block title page.title %}` is the short form, with no body.\n\t\tif (name.value === \"block\" && part.tokens.length > 4) return null;\n\t\treturn { kind: \"open\", name: name.value };\n\t}\n\tif (name.value === \"else\" || name.value === \"elseif\")\n\t\treturn { kind: \"branch\" };\n\tif (name.value.startsWith(\"end\")) {\n\t\treturn { kind: \"close\", name: name.value.slice(3) };\n\t}\n\treturn null;\n};\n\nconst BLOCK_TAG = /[ \\t]*<\\/?([A-Za-z][A-Za-z0-9-]*)/y;\n\n/** Whether the line at `start` begins with a tag of an element shown on a line of its own, such as `<p>` or `</td>`, before which HTML shows no space. */\nconst startsWithBlock = (text: string, start: number): boolean => {\n\tBLOCK_TAG.lastIndex = start;\n\tconst name = BLOCK_TAG.exec(text)?.[1];\n\treturn name !== undefined && BLOCK.has(name.toLowerCase());\n};\n\nconst isLetter = (char: string | undefined) =>\n\tchar !== undefined && /[A-Za-z]/.test(char);\n\nconst isTest = (name: string) => Object.hasOwn(builtinTests, name);\n\n/** The start offset of every line. */\nconst lineStarts = (text: string): number[] => {\n\tconst starts = [0];\n\tfor (let index = text.indexOf(\"\\n\"); index !== -1;) {\n\t\tstarts.push(index + 1);\n\t\tindex = text.indexOf(\"\\n\", index + 1);\n\t}\n\treturn starts;\n};\n\n/**\n * What the output before a point may end with, as flags: the start of a line, the middle of one, or either. `UNSEEN`\n * means content the template can't see the end of, such as an include's, which may end mid-line.\n */\nconst LINE_START = 1;\nconst MID_LINE = 2;\nconst UNSEEN = 4;\n\n/** Block tags whose body renders somewhere else, such as where a macro is called, so it starts at an unknown point. */\nconst ELSEWHERE = new Set([\"macro\", \"set\", \"add\", \"component\", \"fill\"]);\n/**\n * Tags that insert content from elsewhere where they stand. A `block` may be a child template's, and a child's block\n * body renders after whatever its parent has before the block.\n */\nconst INSERTS = new Set([\"include\", \"outlet\", \"block\"]);\n/** Block tags whose output, after their end tag, may come from elsewhere: a component's, a slot's fill, a child's block. */\nconst INSERTED_BODIES = new Set([\"component\", \"slot\", \"block\"]);\n\n/**\n * The start of each line whose indentation may render in the middle of a line, so changing it changes the spacing\n * between words. Kiln removes a line holding only tags with its line break, so the next line follows whatever came\n * before them, which a trim marker can leave mid-line, as can the end of a loop's body for its next iteration.\n *\n * `unseen` holds the lines that may render mid-line only after content the template can't see the end of: what an\n * include or component inserts, or for the first line of a `set`, `macro` or `block` body, whatever comes before it\n * where it is used. Most of that content ends with a line break, so `formatEdits` keeps these lines only when\n * formatting would change them. See `movedLines`. A line starting with a block tag, such as `<p>`, is left out, since\n * HTML shows no space before it.\n */\nconst midLineStarts = (\n\ttext: string,\n\tparts: readonly Part[],\n\tstandalone: ReadonlyMap<number, number>,\n): { starts: number[]; unseen: number[] } => {\n\ttype Frame = {\n\t\tname: string;\n\t\tstart: number;\n\t\tbefore: number;\n\t\t/** For `if`, how the branches before the current one end. For `for` with `else`, how the loop's body ends. */\n\t\tends: number;\n\t\thasElse: boolean;\n\t};\n\t// How each loop's body ends, by the loop tag's start. A loop's body follows its own end, so passes repeat until\n\t// these settle. Flags only ever get added, so they do.\n\tconst loopEnds = new Map<number, number>();\n\tfor (;;) {\n\t\tconst starts: number[] = [];\n\t\tconst unseen: number[] = [];\n\t\tconst frames: Frame[] = [];\n\t\tlet settled = true;\n\t\tlet state = LINE_START;\n\t\tconst endLoop = (frame: Frame, end: number) => {\n\t\t\tif (loopEnds.get(frame.start) !== end) settled = false;\n\t\t\tloopEnds.set(frame.start, end);\n\t\t};\n\t\tfor (const [index, part] of parts.entries()) {\n\t\t\tif (part.kind === \"text\") {\n\t\t\t\tconst at = part.from;\n\t\t\t\tconst previous = parts[index - 1];\n\t\t\t\tconst next = parts[index + 1];\n\t\t\t\t// Cut at a line start by a removed line, not by a trim marker, which would trim new indentation too.\n\t\t\t\tconst cut =\n\t\t\t\t\tat > part.start &&\n\t\t\t\t\ttext[at - 1] === \"\\n\" &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tprevious !== undefined &&\n\t\t\t\t\t\tprevious.kind !== \"text\" &&\n\t\t\t\t\t\tprevious.trimAfter\n\t\t\t\t\t);\n\t\t\t\tconst shows =\n\t\t\t\t\tat < part.to ||\n\t\t\t\t\t(at === part.end &&\n\t\t\t\t\t\tnext !== undefined &&\n\t\t\t\t\t\tnext.kind !== \"text\" &&\n\t\t\t\t\t\t!next.trimBefore &&\n\t\t\t\t\t\t!standalone.has(next.start));\n\t\t\t\tif (cut && shows && state & MID_LINE) starts.push(at);\n\t\t\t\telse if (cut && shows && state & UNSEEN && !startsWithBlock(text, at)) {\n\t\t\t\t\tunseen.push(at);\n\t\t\t\t}\n\t\t\t\t// Spaces and tabs at the end leave the output where it was: at a line start, they are its indentation.\n\t\t\t\tlet end = part.to;\n\t\t\t\twhile (end > part.from && \" \\t\\r\".includes(text[end - 1] as string)) {\n\t\t\t\t\tend--;\n\t\t\t\t}\n\t\t\t\tif (end > part.from)\n\t\t\t\t\tstate = text[end - 1] === \"\\n\" ? LINE_START : MID_LINE;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (part.kind === \"output\") state = LINE_START | MID_LINE;\n\t\t\tif (part.kind !== \"tag\") continue;\n\t\t\tconst role = roleOf(part);\n\t\t\tconst name = part.tokens[1]?.value;\n\t\t\tif (name !== undefined && INSERTS.has(name)) state |= UNSEEN;\n\t\t\tif (role?.kind === \"open\") {\n\t\t\t\tframes.push({\n\t\t\t\t\tname: role.name,\n\t\t\t\t\tstart: part.start,\n\t\t\t\t\tbefore: state,\n\t\t\t\t\tends: 0,\n\t\t\t\t\thasElse: false,\n\t\t\t\t});\n\t\t\t\tif (ELSEWHERE.has(role.name)) state = LINE_START | UNSEEN;\n\t\t\t\telse if (role.name === \"for\") state |= loopEnds.get(part.start) ?? 0;\n\t\t\t} else if (role?.kind === \"branch\") {\n\t\t\t\tconst frame = frames.at(-1);\n\t\t\t\tif (!frame) continue;\n\t\t\t\tif (frame.name === \"for\") endLoop(frame, state);\n\t\t\t\tframe.ends |= state;\n\t\t\t\tframe.hasElse ||= part.tokens[1]?.value === \"else\";\n\t\t\t\tstate = frame.before;\n\t\t\t} else if (role?.kind === \"close\") {\n\t\t\t\tlet frame = frames.pop();\n\t\t\t\twhile (frame && frame.name !== role.name) frame = frames.pop();\n\t\t\t\tif (!frame) continue;\n\t\t\t\tif (frame.name === \"if\") {\n\t\t\t\t\tstate |= frame.ends | (frame.hasElse ? 0 : frame.before);\n\t\t\t\t} else if (frame.name === \"for\") {\n\t\t\t\t\tif (!frame.hasElse) endLoop(frame, state);\n\t\t\t\t\tstate |= frame.hasElse ? frame.ends : frame.before;\n\t\t\t\t} else if (ELSEWHERE.has(frame.name)) state = frame.before;\n\t\t\t\tif (INSERTED_BODIES.has(frame.name)) state |= UNSEEN;\n\t\t\t}\n\t\t}\n\t\tif (settled) return { starts, unseen };\n\t}\n};\n\n/**\n * Ranges of the template, as [start, end] offsets, whose lines the formatter leaves as they are, for each line in\n * `starts` that may render mid-line. That line's rendered indentation depends on the indentation of the lines around\n * it, through the indentation Kiln removes inside tags, so the whole top-level tag around it stays. See `midLineStarts`.\n */\nconst keptRanges = (\n\tbody: readonly Statement[],\n\tstarts: readonly number[],\n): [number, number][] => {\n\tconst ranges: [number, number][] = [];\n\tlet index = 0;\n\tfor (const start of starts) {\n\t\twhile (\n\t\t\tindex < body.length &&\n\t\t\t(body[index] as Statement).span.end <= start\n\t\t) {\n\t\t\tindex++;\n\t\t}\n\t\tconst node = body[index];\n\t\tconst range: [number, number] =\n\t\t\tnode && node.span.start <= start && node.type !== \"Text\"\n\t\t\t\t? [node.span.start, node.span.end]\n\t\t\t\t: [start, start];\n\t\tconst last = ranges.at(-1);\n\t\tif (last && range[0] <= last[1]) last[1] = Math.max(last[1], range[1]);\n\t\telse ranges.push(range);\n\t}\n\treturn ranges;\n};\n\n/**\n * Walks the template once, tracking open block tags and HTML elements, and decides how to treat each line.\n *\n * Returns the lines, which lines may lose trailing whitespace, and the outputs and tags to print.\n */\nconst planLines = (text: string, parts: readonly Part[]) => {\n\tconst starts = lineStarts(text);\n\tconst lines: Line[] = [];\n\tconst trimEnd: boolean[] = [];\n\tconst stack: Frame[] = [];\n\tlet mode: Mode = { kind: \"data\" };\n\tlet atLineStart = true;\n\t// A line that starts where the next part does, recorded when that part begins.\n\tlet pendingLine = -1;\n\n\tconst lineText = (index: number) =>\n\t\ttext.slice(starts[index], starts[index + 1] ?? text.length);\n\t/** Whether only spaces and tabs come between `offset` and the end of its line. */\n\tconst endsLine = (offset: number) => {\n\t\tlet index = offset;\n\t\twhile (index < text.length && \" \\t\\r\".includes(text[index] as string)) {\n\t\t\tindex++;\n\t\t}\n\t\treturn index === text.length || text[index] === \"\\n\";\n\t};\n\tconst current = () => lines.length - 1;\n\n\t/** Lowers the current line's level when a closing tag comes before anything else on it. */\n\tconst outdent = (line: number, level: number, first: boolean) => {\n\t\tconst info = lines[line];\n\t\tif (first && info?.kind === \"indent\") {\n\t\t\tinfo.level = Math.min(info.level, level);\n\t\t}\n\t};\n\n\tconst levelOf = (line: number): number => {\n\t\tconst info = lines[line];\n\t\treturn info?.kind === \"indent\" ? info.level : stack.length;\n\t};\n\n\t/** Records how to treat the line that starts at `start`, from the current state. */\n\tconst beginLine = (start: number) => {\n\t\tconst index = lines.length;\n\t\tconst trimmed = lineText(index).trimStart();\n\t\tatLineStart = true;\n\t\tswitch (mode.kind) {\n\t\t\tcase \"data\":\n\t\t\t\tlines.push({ kind: \"indent\", start, level: stack.length });\n\t\t\t\treturn;\n\t\t\tcase \"tag\": {\n\t\t\t\tif (mode.quote !== null) {\n\t\t\t\t\tlines.push({ kind: \"keep\", start });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst base = levelOf(mode.line);\n\t\t\t\tconst level =\n\t\t\t\t\ttrimmed.startsWith(\">\") || trimmed.startsWith(\"/>\")\n\t\t\t\t\t\t? base\n\t\t\t\t\t\t: base + 1 + mode.inner;\n\t\t\t\tlines.push({ kind: \"indent\", start, level });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"comment\":\n\t\t\t\tlines.push(\n\t\t\t\t\ttrimmed.startsWith(\"-->\")\n\t\t\t\t\t\t? { kind: \"indent\", start, level: mode.level }\n\t\t\t\t\t\t: { kind: \"shift\", start, anchor: mode.anchor },\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\tcase \"raw\":\n\t\t\t\tif (mode.keep) lines.push({ kind: \"keep\", start });\n\t\t\t\telse if (closesElement(trimmed, 0, mode.name)) {\n\t\t\t\t\tlines.push({ kind: \"indent\", start, level: mode.level });\n\t\t\t\t} else lines.push({ kind: \"shift\", start, anchor: mode.anchor });\n\t\t\t\treturn;\n\t\t\tcase \"kept\":\n\t\t\t\tlines.push(\n\t\t\t\t\tendsKept(trimmed, mode)\n\t\t\t\t\t\t? { kind: \"indent\", start, level: mode.level }\n\t\t\t\t\t\t: { kind: \"keep\", start },\n\t\t\t\t);\n\t\t}\n\t};\n\n\t/** Whether trailing whitespace on a line ending here can go. Not inside attribute values or kept elements. */\n\tconst canTrimHere = () =>\n\t\t!(mode.kind === \"tag\" && mode.quote !== null) &&\n\t\t!(mode.kind === \"raw\" && mode.keep) &&\n\t\tmode.kind !== \"kept\";\n\n\tconst finishTag = (\n\t\ttag: Extract<Mode, { kind: \"tag\" }>,\n\t\tselfClosing: boolean,\n\t) => {\n\t\tmode = { kind: \"data\" };\n\t\tconst name = tag.name;\n\t\tif (tag.closing) {\n\t\t\t// Close the nearest open element of this name, without crossing a block tag.\n\t\t\tfor (let index = stack.length - 1; index >= 0; index--) {\n\t\t\t\tconst frame = stack[index] as Frame;\n\t\t\t\tif (frame.kind === \"kiln\") break;\n\t\t\t\tif (frame.name === name) {\n\t\t\t\t\tstack.length = index;\n\t\t\t\t\toutdent(tag.line, index, tag.atLineStart);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (name.startsWith(\"!\") || selfClosing || VOID_ELEMENTS.has(name)) return;\n\t\tif (RAW_ELEMENTS.has(name) || KEPT_ELEMENTS.has(name)) {\n\t\t\tmode = {\n\t\t\t\tkind: \"raw\",\n\t\t\t\tname,\n\t\t\t\tkeep: KEPT_ELEMENTS.has(name),\n\t\t\t\tanchor: tag.line,\n\t\t\t\tlevel: stack.length,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tconst top = stack[stack.length - 1];\n\t\tif (top?.kind === \"html\" && CLOSED_BY[top.name]?.includes(name)) {\n\t\t\tstack.pop();\n\t\t\toutdent(tag.line, stack.length, tag.atLineStart);\n\t\t}\n\t\tstack.push({ kind: \"html\", name });\n\t};\n\n\t/** Starts a tag at `index` if one starts there, and returns where scanning continues. */\n\tconst startTag = (index: number, closing: boolean): number => {\n\t\tconst nameStart = index + (closing ? 2 : 1);\n\t\tlet nameEnd = nameStart;\n\t\twhile (\n\t\t\tnameEnd < text.length &&\n\t\t\t/[A-Za-z0-9:!_-]/.test(text[nameEnd] as string)\n\t\t) {\n\t\t\tnameEnd++;\n\t\t}\n\t\tmode = {\n\t\t\tkind: \"tag\",\n\t\t\tname: text.slice(nameStart, nameEnd).toLowerCase(),\n\t\t\tclosing,\n\t\t\tquote: null,\n\t\t\tline: current(),\n\t\t\tatLineStart,\n\t\t\tinner: 0,\n\t\t};\n\t\tatLineStart = false;\n\t\treturn nameEnd;\n\t};\n\n\t/** Moves through a text part one character at a time. */\n\tconst scanText = (start: number, end: number) => {\n\t\tfor (let index = start; index < end; index++) {\n\t\t\tconst char = text[index] as string;\n\t\t\tif (char === \"\\n\") {\n\t\t\t\ttrimEnd[current()] = canTrimHere();\n\t\t\t\tif (index + 1 < end) beginLine(index + 1);\n\t\t\t\telse if (index + 1 === text.length) {\n\t\t\t\t\t// The file ends with a line break: there is no further line.\n\t\t\t\t} else pendingLine = index + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tswitch (mode.kind) {\n\t\t\t\tcase \"data\":\n\t\t\t\t\tif (char === \" \" || char === \"\\t\" || char === \"\\r\") break;\n\t\t\t\t\tif (char === \"<\") {\n\t\t\t\t\t\tif (text.startsWith(\"<!--\", index)) {\n\t\t\t\t\t\t\tmode = {\n\t\t\t\t\t\t\t\tkind: \"comment\",\n\t\t\t\t\t\t\t\tanchor: current(),\n\t\t\t\t\t\t\t\tlevel: levelOf(current()),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tatLineStart = false;\n\t\t\t\t\t\t\tindex += 3;\n\t\t\t\t\t\t} else if (text[index + 1] === \"/\" && isLetter(text[index + 2])) {\n\t\t\t\t\t\t\tindex = startTag(index, true) - 1;\n\t\t\t\t\t\t} else if (isLetter(text[index + 1]) || text[index + 1] === \"!\") {\n\t\t\t\t\t\t\tindex = startTag(index, false) - 1;\n\t\t\t\t\t\t} else atLineStart = false;\n\t\t\t\t\t} else atLineStart = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"tag\":\n\t\t\t\t\tif (mode.quote !== null) {\n\t\t\t\t\t\tif (char === mode.quote) mode.quote = null;\n\t\t\t\t\t} else if (char === '\"' || char === \"'\") mode.quote = char;\n\t\t\t\t\telse if (char === \">\") finishTag(mode, text[index - 1] === \"/\");\n\t\t\t\t\telse if (char !== \" \" && char !== \"\\t\" && char !== \"\\r\") {\n\t\t\t\t\t\tatLineStart = false;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"comment\":\n\t\t\t\t\tif (text.startsWith(\"-->\", index)) {\n\t\t\t\t\t\tmode = { kind: \"data\" };\n\t\t\t\t\t\tindex += 2;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"raw\":\n\t\t\t\t\tif (char === \"<\" && closesElement(text, index, mode.name)) {\n\t\t\t\t\t\tindex = startTag(index, true) - 1;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"kept\":\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t};\n\n\t/** Applies a block tag to the stack, or to the count of block tags open inside an HTML tag. */\n\tconst applyTag = (part: DelimitedPart) => {\n\t\tconst role = roleOf(part);\n\t\tconst first = atLineStart;\n\t\tatLineStart = false;\n\t\tif (!role) return;\n\t\tif (mode.kind === \"tag\") {\n\t\t\tconst base = levelOf(mode.line) + 1;\n\t\t\tif (role.kind === \"open\") mode.inner++;\n\t\t\telse if (role.kind === \"close\") {\n\t\t\t\tmode.inner = Math.max(0, mode.inner - 1);\n\t\t\t\toutdent(current(), base + mode.inner, first);\n\t\t\t} else outdent(current(), base + mode.inner - 1, first);\n\t\t\treturn;\n\t\t}\n\t\tif (mode.kind === \"kept\") {\n\t\t\tif (role.kind === \"open\" && role.name === mode.name) mode.depth++;\n\t\t\telse if (\n\t\t\t\trole.kind === \"close\" &&\n\t\t\t\trole.name === mode.name &&\n\t\t\t\t--mode.depth === 0\n\t\t\t) {\n\t\t\t\tconst index = stack.findLastIndex((frame) => frame.kind === \"kiln\");\n\t\t\t\tif (index !== -1) stack.length = index;\n\t\t\t\tmode = { kind: \"data\" };\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (mode.kind !== \"data\") return;\n\t\tif (role.kind === \"open\") {\n\t\t\tstack.push({ kind: \"kiln\", name: role.name });\n\t\t\tif (\n\t\t\t\trole.name === \"verbatim\" ||\n\t\t\t\t((role.name === \"set\" || role.name === \"apply\") &&\n\t\t\t\t\t!(first && endsLine(part.end)))\n\t\t\t) {\n\t\t\t\tmode = {\n\t\t\t\t\tkind: \"kept\",\n\t\t\t\t\tname: role.name,\n\t\t\t\t\tdepth: 1,\n\t\t\t\t\tlevel: stack.length - 1,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst index =\n\t\t\trole.kind === \"branch\"\n\t\t\t\t? stack.findLastIndex((frame) => frame.kind === \"kiln\")\n\t\t\t\t: stack.findLastIndex(\n\t\t\t\t\t\t(frame) => frame.kind === \"kiln\" && frame.name === role.name,\n\t\t\t\t\t);\n\t\tif (index === -1) return;\n\t\t// Elements opened in this body or branch end with it.\n\t\tstack.length = role.kind === \"branch\" ? index + 1 : index;\n\t\toutdent(current(), index, first);\n\t};\n\n\tbeginLine(0);\n\tconst delimiters: { part: DelimitedPart; line: number }[] = [];\n\n\tfor (const part of parts) {\n\t\tif (pendingLine !== -1) {\n\t\t\tbeginLine(pendingLine);\n\t\t\tpendingLine = -1;\n\t\t}\n\t\tif (part.kind === \"text\") {\n\t\t\tscanText(part.start, part.end);\n\t\t\tcontinue;\n\t\t}\n\t\tconst line = current();\n\t\tif (part.kind === \"comment\") atLineStart = false;\n\t\telse {\n\t\t\tdelimiters.push({ part, line });\n\t\t\tif (part.kind === \"tag\") applyTag(part);\n\t\t\telse atLineStart = false;\n\t\t}\n\t\t// Lines that start inside this delimiter.\n\t\tfor (\n\t\t\tlet index = text.indexOf(\"\\n\", part.start);\n\t\t\tindex !== -1 && index < part.end;\n\t\t\tindex = text.indexOf(\"\\n\", index + 1)\n\t\t) {\n\t\t\ttrimEnd[current()] = part.kind === \"comment\";\n\t\t\tlines.push(\n\t\t\t\tpart.kind === \"comment\"\n\t\t\t\t\t? { kind: \"shift\", start: index + 1, anchor: line }\n\t\t\t\t\t: { kind: \"inside\", start: index + 1 },\n\t\t\t);\n\t\t}\n\t}\n\ttrimEnd[current()] ??= canTrimHere();\n\treturn { lines, trimEnd, delimiters };\n};\n\nconst widthOf = (whitespace: string, tabWidth: number): number => {\n\tlet width = 0;\n\tfor (const char of whitespace) width += char === \"\\t\" ? tabWidth : 1;\n\treturn width;\n};\n\n/**\n * Works out the edits that format a template, without checking them. See `formatEdits`.\n */\nconst planEdits = (\n\ttext: string,\n\tparts: readonly Part[],\n\tkept: readonly [number, number][],\n\toptions: Required<Omit<FormatOptions, \"range\">>,\n): FormatEdit[] => {\n\tconst { useTabs, tabWidth } = options;\n\tconst unit = useTabs ? \"\\t\" : \" \".repeat(tabWidth);\n\tconst indentOfWidth = (width: number) =>\n\t\tuseTabs\n\t\t\t? \"\\t\".repeat(Math.floor(width / tabWidth)) + \" \".repeat(width % tabWidth)\n\t\t\t: \" \".repeat(width);\n\tconst { lines, trimEnd, delimiters } = planLines(text, parts);\n\t// Lines that overlap a kept range stay as they are. Both lists are in source order.\n\tlet range = 0;\n\tfor (const [index, line] of lines.entries()) {\n\t\tconst next = lines[index + 1]?.start ?? text.length + 1;\n\t\twhile (\n\t\t\trange < kept.length &&\n\t\t\t(kept[range] as [number, number])[1] < line.start\n\t\t) {\n\t\t\trange++;\n\t\t}\n\t\tconst overlaps =\n\t\t\trange < kept.length && (kept[range] as [number, number])[0] < next;\n\t\tif (overlaps && (line.kind === \"indent\" || line.kind === \"shift\")) {\n\t\t\tlines[index] = { kind: \"keep\", start: line.start };\n\t\t}\n\t}\n\n\tconst oldIndent = (line: number) => {\n\t\tconst start = lines[line]?.start ?? 0;\n\t\tlet end = start;\n\t\twhile (text[end] === \" \" || text[end] === \"\\t\") end++;\n\t\treturn text.slice(start, end);\n\t};\n\t/** Where a line's content ends: at its line break, or the end of the file. */\n\tconst lineEnd = (line: number) => {\n\t\tconst next = lines[line + 1]?.start;\n\t\tif (next !== undefined) return next - 1;\n\t\treturn text.endsWith(\"\\n\") ? text.length - 1 : text.length;\n\t};\n\tconst isBlank = (line: number) => {\n\t\tconst info = lines[line] as Line;\n\t\treturn (\n\t\t\tinfo.kind !== \"keep\" &&\n\t\t\tinfo.kind !== \"inside\" &&\n\t\t\ttext.slice(info.start, lineEnd(line)).trim() === \"\"\n\t\t);\n\t};\n\n\t// Whitespace before the first content and after the last is output as written wherever the template is placed, so\n\t// it stays as it is, as does a file of only whitespace.\n\tlet firstContent = 0;\n\twhile (firstContent < lines.length && isBlank(firstContent)) firstContent++;\n\tlet lastContent = lines.length - 1;\n\twhile (lastContent >= 0 && isBlank(lastContent)) lastContent--;\n\n\tconst newIndents = new Map<number, string | null>();\n\tconst newIndent = (line: number): string | null => {\n\t\tif (newIndents.has(line)) return newIndents.get(line) ?? null;\n\t\tconst info = lines[line];\n\t\tlet indent: string | null = null;\n\t\tif (info?.kind === \"indent\") {\n\t\t\t// The first content line keeps its indentation. See `firstContent`.\n\t\t\tindent =\n\t\t\t\tline === firstContent ? oldIndent(line) : unit.repeat(info.level);\n\t\t} else if (info?.kind === \"shift\") {\n\t\t\tconst anchor = newIndent(info.anchor);\n\t\t\tconst moved =\n\t\t\t\tanchor === null\n\t\t\t\t\t? 0\n\t\t\t\t\t: widthOf(anchor, tabWidth) -\n\t\t\t\t\t\twidthOf(oldIndent(info.anchor), tabWidth);\n\t\t\tindent = indentOfWidth(\n\t\t\t\tMath.max(0, widthOf(oldIndent(line), tabWidth) + moved),\n\t\t\t);\n\t\t}\n\t\tnewIndents.set(line, indent);\n\t\treturn indent;\n\t};\n\n\tconst edits: FormatEdit[] = [];\n\t// Blank lines go where the line before is blank too, so runs become one.\n\tlet previousBlank = false;\n\n\tfor (const [index, info] of lines.entries()) {\n\t\tif (index > lastContent) break;\n\t\tif (index < firstContent) continue;\n\t\tconst start = info.start;\n\t\tconst end = lineEnd(index);\n\t\tif (isBlank(index)) {\n\t\t\tif (info.kind === \"indent\" && previousBlank) {\n\t\t\t\tedits.push({ start, end: end + 1, text: \"\" });\n\t\t\t} else if (end > start) edits.push({ start, end, text: \"\" });\n\t\t\tpreviousBlank = true;\n\t\t\tcontinue;\n\t\t}\n\t\tpreviousBlank = false;\n\n\t\tconst indent = newIndent(index);\n\t\tif (indent !== null) {\n\t\t\tconst current = oldIndent(index);\n\t\t\tif (current !== indent) {\n\t\t\t\tedits.push({ start, end: start + current.length, text: indent });\n\t\t\t}\n\t\t}\n\t\tif (!trimEnd[index] || info.kind === \"keep\") continue;\n\t\tif (index !== lastContent) {\n\t\t\tlet from = end;\n\t\t\twhile (from > start && /[ \\t\\r]/.test(text[from - 1] as string)) from--;\n\t\t\tif (from < end && !insideDelimiter(delimiters, from)) {\n\t\t\t\tedits.push({ start: from, end, text: \"\" });\n\t\t\t}\n\t\t} else if (text[end - 1] === \"\\r\" && text[end] === \"\\n\") {\n\t\t\t// The last content line keeps its trailing spaces, but its line break still becomes `\\n`.\n\t\t\tedits.push({ start: end - 1, end, text: \"\" });\n\t\t}\n\t}\n\n\t// The new indentation of lines that start inside a delimiter, from how that delimiter printed them, for a delimiter\n\t// that starts on one, as in `}} {{ b`.\n\tconst insideIndents = new Map<number, string>();\n\tfor (const { part, line } of delimiters) {\n\t\tconst indent =\n\t\t\tnewIndent(line) ?? insideIndents.get(line) ?? oldIndent(line);\n\t\tconst source = text.slice(part.start, part.end);\n\t\tconst printed = printDelimiter(text, part, indent, unit);\n\t\tif (printed !== null && printed !== source) {\n\t\t\tedits.push({ start: part.start, end: part.end, text: printed });\n\t\t}\n\t\tconst lastBreak = (printed ?? source).lastIndexOf(\"\\n\");\n\t\tif (lastBreak !== -1) {\n\t\t\tconst endLine = line + (source.match(/\\n/g)?.length ?? 0);\n\t\t\tconst after = (printed ?? source).slice(lastBreak + 1);\n\t\t\tinsideIndents.set(endLine, /^[ \\t]*/.exec(after)?.[0] ?? \"\");\n\t\t}\n\t}\n\n\treturn edits.sort((a, b) => a.start - b.start || a.end - b.end);\n};\n\n/** Whether `offset` is strictly inside one of `delimiters`, which are in source order. */\nconst insideDelimiter = (\n\tdelimiters: readonly { part: DelimitedPart }[],\n\toffset: number,\n) => {\n\t// The last delimiter that starts before `offset`.\n\tlet low = 0;\n\tlet high = delimiters.length;\n\twhile (low < high) {\n\t\tconst middle = (low + high) >>> 1;\n\t\tif ((delimiters[middle] as { part: DelimitedPart }).part.start < offset) {\n\t\t\tlow = middle + 1;\n\t\t} else high = middle;\n\t}\n\tconst before = delimiters[low - 1];\n\treturn before !== undefined && offset < before.part.end;\n};\n\nconst applyEdits = (text: string, edits: readonly FormatEdit[]): string => {\n\tlet out = \"\";\n\tlet position = 0;\n\tfor (const edit of edits) {\n\t\tout += text.slice(position, edit.start) + edit.text;\n\t\tposition = edit.end;\n\t}\n\treturn out + text.slice(position);\n};\n\n/**\n * How the safety check compares the leading whitespace of a line that may render mid-line: `exact`ly, or only whether\n * there is `any`, since HTML shows any run of it as one space. See `midLineStarts`.\n */\ntype MidLine = \"exact\" | \"any\";\n\n/** The lines of a template that may render mid-line, by their start, and how to compare each. */\nconst midLinesOf = (\n\ttext: string,\n\tparts: readonly Part[],\n\tstandalone: ReadonlyMap<number, number>,\n) => {\n\tconst { starts, unseen } = midLineStarts(text, parts, standalone);\n\tconst kinds = new Map<number, MidLine>();\n\tfor (const start of starts) kinds.set(start, \"exact\");\n\tfor (const start of unseen) kinds.set(start, \"any\");\n\treturn { starts, unseen, kinds };\n};\n\n/**\n * Removes whitespace at the start and end of lines, and blank lines, which the formatter may change. With `midLine`,\n * the text starts a line that may render mid-line, so its leading spaces and tabs stay, or for `any`, whether it has any.\n */\nconst normaliseText = (value: string, midLine: MidLine | undefined) => {\n\tconst indent = midLine ? (/^[ \\t]*/.exec(value)?.[0] ?? \"\") : \"\";\n\treturn (\n\t\t(midLine === \"any\" && indent !== \"\" ? \" \" : indent) +\n\t\tvalue\n\t\t\t.slice(indent.length)\n\t\t\t// Only from the start of a run, so a long run is not searched again from each of its characters.\n\t\t\t.replace(/(?<![ \\t\\r\\f\\v])[ \\t\\r\\f\\v]+$/gm, \"\")\n\t\t\t.replace(/^[ \\t\\f\\v]+/gm, \"\")\n\t\t\t.replace(/\\n{2,}/g, \"\\n\")\n\t);\n};\n\n/**\n * A copy of a syntax tree without positions or layout, with text normalised and text left empty by that removed.\n * Text starting at one of `midLine` keeps its leading whitespace. See `midLineStarts`.\n */\nconst normaliseTree = (\n\tvalue: unknown,\n\tmidLine: ReadonlyMap<number, MidLine>,\n): unknown => {\n\tif (Array.isArray(value)) {\n\t\treturn value\n\t\t\t.map((item) => normaliseTree(item, midLine))\n\t\t\t.filter(\n\t\t\t\t(item) =>\n\t\t\t\t\t!(\n\t\t\t\t\t\ttypeof item === \"object\" &&\n\t\t\t\t\t\titem !== null &&\n\t\t\t\t\t\t(item as { type?: unknown }).type === \"Text\" &&\n\t\t\t\t\t\t(item as { value?: unknown }).value === \"\"\n\t\t\t\t\t),\n\t\t\t);\n\t}\n\tif (typeof value !== \"object\" || value === null) return value;\n\tconst node = value as { type?: unknown; span?: Span };\n\tconst copy: Record<string, unknown> = {};\n\tfor (const [key, item] of Object.entries(value)) {\n\t\tif (key === \"span\" || key === \"nameSpan\" || key === \"indent\") continue;\n\t\tcopy[key] =\n\t\t\tkey === \"value\" && node.type === \"Text\"\n\t\t\t\t? normaliseText(item as string, midLine.get(node.span?.start ?? -1))\n\t\t\t\t: normaliseTree(item, midLine);\n\t}\n\treturn copy;\n};\n\n/** A syntax tree as JSON, without the whitespace the formatter may change, so two trees can be compared. */\nconst shape = (\n\tvalue: TemplateNode | Statement,\n\tmidLine: ReadonlyMap<number, MidLine>,\n): string => JSON.stringify(normaliseTree(value, midLine));\n\n/**\n * The lines in `unseen` whose rendered indentation formatting changes, as the safety check compares it: those in a\n * top-level statement that differs once formatted. `formatEdits` keeps these, with the statement, as written.\n */\nconst movedLines = (\n\tbefore: { body: readonly Statement[]; kinds: ReadonlyMap<number, MidLine> },\n\tafter: { body: readonly Statement[]; kinds: ReadonlyMap<number, MidLine> },\n\tunseen: readonly number[],\n): number[] => {\n\t// Formatting only changes whitespace, so the statements match one to one. Keep every line if they somehow don't.\n\tif (before.body.length !== after.body.length) return [...unseen];\n\tconst moved: number[] = [];\n\tlet index = 0;\n\tfor (const [position, node] of before.body.entries()) {\n\t\tconst inside: number[] = [];\n\t\tfor (; index < unseen.length; index++) {\n\t\t\tconst start = unseen[index] as number;\n\t\t\tif (start >= node.span.end) break;\n\t\t\tif (start >= node.span.start) inside.push(start);\n\t\t}\n\t\tif (\n\t\t\tinside.length > 0 &&\n\t\t\tshape(node, before.kinds) !==\n\t\t\t\tshape(after.body[position] as Statement, after.kinds)\n\t\t) {\n\t\t\tmoved.push(...inside);\n\t\t}\n\t}\n\treturn moved;\n};\n\n/**\n * Works out the edits that format a template, in source order and never overlapping. Editors apply these so the cursor and undo history stay put. See `format` for what it throws.\n */\nexport const formatEdits = (\n\ttext: string,\n\toptions: FormatOptions = {},\n): FormatEdit[] => {\n\tconst parsed = parse(text, { isTest });\n\tif (parsed.problems.length > 0) {\n\t\tconst source = new Source(\"template.kiln\", text);\n\t\tthrow new KilnSyntaxError(\n\t\t\tparsed.problems.map((problem) =>\n\t\t\t\tcreateDiagnostic(source, problem.code, problem.message, problem.span),\n\t\t\t),\n\t\t\tsource,\n\t\t);\n\t}\n\n\tconst tabWidth = options.tabWidth ?? 4;\n\tif (!Number.isInteger(tabWidth) || tabWidth < 1) {\n\t\tthrow new RangeError(\n\t\t\t`tabWidth must be a whole number of at least 1, but got ${tabWidth}`,\n\t\t);\n\t}\n\tconst { parts, standalone } = scanControlled(text);\n\tconst before = midLinesOf(text, parts, standalone);\n\tconst range = options.range;\n\t/** The edits, keeping lines starting at `starts` as written, with the top-level tags around them. */\n\tconst plan = (starts: readonly number[]) => {\n\t\tconst edits = planEdits(text, parts, keptRanges(parsed.ast.body, starts), {\n\t\t\tuseTabs: options.useTabs ?? true,\n\t\t\ttabWidth,\n\t\t});\n\t\treturn range\n\t\t\t? edits.filter(\n\t\t\t\t\t(edit) => edit.end >= range.start && edit.start <= range.end,\n\t\t\t\t)\n\t\t\t: edits;\n\t};\n\tconst formatWith = (starts: readonly number[]) => {\n\t\tconst edits = plan(starts);\n\t\tconst formatted = applyEdits(text, edits);\n\t\tconst changed = parse(formatted, { isTest });\n\t\tconst scanned = scanControlled(formatted);\n\t\treturn {\n\t\t\tedits,\n\t\t\tchanged,\n\t\t\tkinds: midLinesOf(formatted, scanned.parts, scanned.standalone).kinds,\n\t\t};\n\t};\n\n\tlet result = formatWith(before.starts);\n\t// Lines after unseen content usually render at a line start, so they stay as written only when formatting moves\n\t// them. Keeping a statement leaves alone the lines it shares with the next, which can move another, so this repeats.\n\tlet kept = before.starts;\n\tfor (let unseen = before.unseen; result.changed.problems.length === 0;) {\n\t\tconst moved = movedLines(\n\t\t\t{ body: parsed.ast.body, kinds: before.kinds },\n\t\t\t{ body: result.changed.ast.body, kinds: result.kinds },\n\t\t\tunseen,\n\t\t);\n\t\tif (moved.length === 0) break;\n\t\tkept = [...kept, ...moved].sort((a, b) => a - b);\n\t\tconst done = new Set(moved);\n\t\tunseen = unseen.filter((start) => !done.has(start));\n\t\tresult = formatWith(kept);\n\t}\n\n\tconst { edits, changed, kinds } = result;\n\tif (\n\t\tchanged.problems.length > 0 ||\n\t\tshape(changed.ast, kinds) !== shape(parsed.ast, before.kinds)\n\t) {\n\t\tthrow new KilnFormatError(\n\t\t\t\"Formatting would have changed what this template renders, so nothing was changed. This is a bug in Kiln's formatter.\",\n\t\t);\n\t}\n\treturn edits;\n};\n\n/**\n * Formats a template: indents it to match its structure, and tidies spacing inside outputs and tags. Never changes what it renders.\n *\n * Throws `KilnSyntaxError` when the template has syntax errors, `KilnFormatError` if the safety check fails, and\n * `RangeError` for a `tabWidth` that isn't a whole number of at least 1.\n *\n * ```ts\n * const formatted = format(source, { useTabs: false, tabWidth: 2 });\n * ```\n */\nexport const format = (text: string, options: FormatOptions = {}): string =>\n\tapplyEdits(text, formatEdits(text, options));\n"],"mappings":";;;AAmCA,MAAM,2BAAW,IAAI,IAAI;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,MAAM,YAAY,QAAgB,WAAsC;CACvE,MAAM,SAAkB,CAAC;CACzB,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;EACnD,MAAM,QAAQ,OAAO;EACrB,IAAI,MAAM,MAAM;EAChB,IAAI,MAAM,SAAS,eAAe;GACjC,IAAI,QAAQ;GACZ,OAAO,QAAQ,OAAO,QAAQ,SAAS;IACtC,MAAM,QAAQ,OAAO;IACrB,IAAI,MAAM,SAAS,eAAe;SAC7B,IAAI,MAAM,SAAS,eAAe,EAAE,UAAU,GAAG;GACvD;GACA,MAAO,OAAO,KAAK,IAAI,OAAO,OAAO,SAAS,CAAC,EAAE,CAAW;EAC7D;EACA,OAAO,KAAK;GACX,MAAM,MAAM,SAAS,gBAAgB,WAAW,MAAM;GACtD,MAAM,OAAO,MAAM,MAA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IAAI,OAAO,OAAO;CAClB,KAAK,IAAI,SAAS,OAAO,QAAQ,OAAO,QAAQ,SAAS,WAAW,IAAI;EACvE,MAAM,QAAQ,WACb;GAAE,MAAM,OAAO,IAAI;GAAM,OAAO,OAAO;EAAM,GAC7C;GAAE,MAAM,OAAO,QAAQ,IAAI;GAAM,OAAO,OAAO;EAAM,GACrD,MACD;EACA,IAAI,MAAM,WAAW,GAAG;EACxB,OAAO,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;EAC/C,MAAM,OAAO,IAAI,IAAI,KAAK;EAC1B,SAAS,OAAO,QAAQ,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC;EAClD,SAAS,WAAW,IAAI;CACzB;CAEA,MAAM,EAAE,OAAO,SAAS,UAAU;CAClC,IACC,QAAQ,SAAS,SAAS,KAC1B,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM,OAAO,KAAK,OAAO,KAAK,GAE5D,MAAM,IAAI,gBACT,sHACD;CAED,OAAO;AACR;;;;;;;;;;;AAYA,MAAa,UAAU,MAAc,UAAyB,CAAC,MAC9D,WAAW,MAAM,YAAY,MAAM,OAAO,CAAC"}
|
package/dist/format.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as KilnFormatError, n as format, r as formatEdits } from "./format-
|
|
1
|
+
export { t as KilnFormatError, n as format, r as formatEdits } from "./format-B5w2QhSr.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as PropType, l as ShapeKey, m as Position, p as TypeName, r as EscapeStrategy } from "./ast-DzzSn9tS.js";
|
|
2
|
-
import { $ as Diagnostic, A as HostRender, B as TemplateReference, C as memoryLoader, D as HtmlChecks, E as HtmlCheckLevel, F as AnalysedProp, G as IslandEntry, H as KilnCache, I as Analysis, J as JsonValue, K as IslandManifest, L as CallArgument, M as Markup, N as isSafe, O as PrecompiledTemplate, P as safe, Q as streamIslands, R as FunctionCall, S as memoryCache, T as HtmlCheck, U as RenderInfo, V as AbortSignalLike, W as DeferredIslands, X as deferIslands, Y as StreamedIslands, Z as islandScript, _ as TemplateContext, a as KilnGlobals, b as builtins, c as KilnTemplates, d as Limits, et as KilnRenderError, f as LoadedTemplate, g as TemplateBlock, h as RenderOptions, i as KilnFunctions, j as hostComponent, k as HostComponent, l as KilnTests, m as RenderAware, n as KilnCallable, nt as TemplateLocation, o as KilnOptions, p as Loader, q as IslandMode, r as KilnFilters, s as KilnSchema, t as Kiln, tt as KilnSyntaxError, u as KilnTypes, v as TemplateName, w as withRender, x as createKiln, y as TypeChecks, z as TemplateExport } from "./environment-
|
|
2
|
+
import { $ as Diagnostic, A as HostRender, B as TemplateReference, C as memoryLoader, D as HtmlChecks, E as HtmlCheckLevel, F as AnalysedProp, G as IslandEntry, H as KilnCache, I as Analysis, J as JsonValue, K as IslandManifest, L as CallArgument, M as Markup, N as isSafe, O as PrecompiledTemplate, P as safe, Q as streamIslands, R as FunctionCall, S as memoryCache, T as HtmlCheck, U as RenderInfo, V as AbortSignalLike, W as DeferredIslands, X as deferIslands, Y as StreamedIslands, Z as islandScript, _ as TemplateContext, a as KilnGlobals, b as builtins, c as KilnTemplates, d as Limits, et as KilnRenderError, f as LoadedTemplate, g as TemplateBlock, h as RenderOptions, i as KilnFunctions, j as hostComponent, k as HostComponent, l as KilnTests, m as RenderAware, n as KilnCallable, nt as TemplateLocation, o as KilnOptions, p as Loader, q as IslandMode, r as KilnFilters, s as KilnSchema, t as Kiln, tt as KilnSyntaxError, u as KilnTypes, v as TemplateName, w as withRender, x as createKiln, y as TypeChecks, z as TemplateExport } from "./environment-DcH713WK.js";
|
|
3
3
|
//#region src/runtime/exposure.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Lists the members of a class that templates may read or call.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as unhold, $t as variableNames, A as checkLength, An as VOID, At as isRoot, B as isPromise, Bt as takeOutput, C as toTime, Cn as ONLY_CHILDREN, Ct as unwrap, D as addSlotFlags, Dn as ROLES, Dt as lookup, E as readableNames, En as REQUIRED_PARENTS, Et as expose, F as embedScope, Fn as KilnSyntaxError, Ft as runSequence, G as markCaller, Gt as endCapture, H as loadTemplate, Ht as Run, I as fail, In as createDiagnostic, It as additionsIn, J as renderTemplate, Jt as childScope, K as moreSteps, Kt as fillScope, L as hold, Ln as issue, Lt as checkLate, M as consumeAt, Mn as resolveTemplateName, Mt as passesAhead, N as embed, Nn as KilnIssue, Nt as passesFrom, O as after, On as SPECIAL, Ot as atFront, P as embedKeyed, Pn as KilnRenderError, Pt as runAhead, Q as stepError, Qt as sectionScope, R as holdData, Rt as closeOutlets, S as toPlainData, Sn as OBSOLETE_ATTRIBUTES, St as typeName, T as getMethod, Tn as RAW_TEXT, Tt as BLOCKED_NAMES, U as locate, Ut as blockScope, V as lendSteps, Vt as RenderState, W as locating, Wt as emptyOut, X as silence, Xt as ownerOf, Y as returnSteps, Yt as lookup$1, Z as step, Zt as sectionCopy, _ as mapContents, _n as IMPLICIT_ROLES, _t as templateFunctions, a as operatorFunction, an as escapeUrl, at as compare, b as scanHtml, bn as METADATA, bt as toStringArgument, c as checkDepth, cn as ARIA_ATTRIBUTES, ct as equals, d as functionArgument, dn as BOOLEAN_ATTRIBUTES, dt as isHashLike, en as suggest, et as withCaller, f as insertedPiece, fn as BUTTON_SCOPE, ft as isPlainObject, g as listOf$1, gn as HEADINGS, gt as setOwn, h as keyName, hn as FOREIGN, ht as matchesType, i as contains, in as escapeHtml, it as MISSING, j as consume, jn as TEMPLATE_EXTENSION, jt as mayRunAhead, k as all, kn as TRANSPARENT, kt as contentSets, l as entriesOf, ln as ATTRIBUTE_VALUES, lt as hashKeys, m as isHtmlStrategy, mn as FLOW, mt as mapKeys, n as builtinFunctions, nn as isSafe, nt as FORMATTERS, o as rangeOperator, on as escapeWith, ot as describeType, p as integerArgument, pn as FIRST_CHILD, pt as literalOptions, q as passData, qt as startCapture, r as builtinTests, rn as safe, rt as MAX_DATA_DEPTH, s as Kept, sn as ABSTRACT_ROLES, st as describeValue, t as Source, tn as Markup, tt as write, u as fromPieces, un as BLOCK, ut as isEmpty, v as markupText, vn as INPUT_ROLES, vt as toNumber, w as getAttr, wn as PHRASING_ONLY, wt as valueLabel, x as toPieces, xn as OBSOLETE, xt as truthy, y as readProperty, yn as MAIN_PARENTS, yt as toStr, z as importsFor, zt as recordAddition } from "./source-
|
|
1
|
+
import { $ as unhold, $t as variableNames, A as checkLength, An as VOID, At as isRoot, B as isPromise, Bt as takeOutput, C as toTime, Cn as ONLY_CHILDREN, Ct as unwrap, D as addSlotFlags, Dn as ROLES, Dt as lookup, E as readableNames, En as REQUIRED_PARENTS, Et as expose, F as embedScope, Fn as KilnSyntaxError, Ft as runSequence, G as markCaller, Gt as endCapture, H as loadTemplate, Ht as Run, I as fail, In as createDiagnostic, It as additionsIn, J as renderTemplate, Jt as childScope, K as moreSteps, Kt as fillScope, L as hold, Ln as issue, Lt as checkLate, M as consumeAt, Mn as resolveTemplateName, Mt as passesAhead, N as embed, Nn as KilnIssue, Nt as passesFrom, O as after, On as SPECIAL, Ot as atFront, P as embedKeyed, Pn as KilnRenderError, Pt as runAhead, Q as stepError, Qt as sectionScope, R as holdData, Rt as closeOutlets, S as toPlainData, Sn as OBSOLETE_ATTRIBUTES, St as typeName, T as getMethod, Tn as RAW_TEXT, Tt as BLOCKED_NAMES, U as locate, Ut as blockScope, V as lendSteps, Vt as RenderState, W as locating, Wt as emptyOut, X as silence, Xt as ownerOf, Y as returnSteps, Yt as lookup$1, Z as step, Zt as sectionCopy, _ as mapContents, _n as IMPLICIT_ROLES, _t as templateFunctions, a as operatorFunction, an as escapeUrl, at as compare, b as scanHtml, bn as METADATA, bt as toStringArgument, c as checkDepth, cn as ARIA_ATTRIBUTES, ct as equals, d as functionArgument, dn as BOOLEAN_ATTRIBUTES, dt as isHashLike, en as suggest, et as withCaller, f as insertedPiece, fn as BUTTON_SCOPE, ft as isPlainObject, g as listOf$1, gn as HEADINGS, gt as setOwn, h as keyName, hn as FOREIGN, ht as matchesType, i as contains, in as escapeHtml, it as MISSING, j as consume, jn as TEMPLATE_EXTENSION, jt as mayRunAhead, k as all, kn as TRANSPARENT, kt as contentSets, l as entriesOf, ln as ATTRIBUTE_VALUES, lt as hashKeys, m as isHtmlStrategy, mn as FLOW, mt as mapKeys, n as builtinFunctions, nn as isSafe, nt as FORMATTERS, o as rangeOperator, on as escapeWith, ot as describeType, p as integerArgument, pn as FIRST_CHILD, pt as literalOptions, q as passData, qt as startCapture, r as builtinTests, rn as safe, rt as MAX_DATA_DEPTH, s as Kept, sn as ABSTRACT_ROLES, st as describeValue, t as Source, tn as Markup, tt as write, u as fromPieces, un as BLOCK, ut as isEmpty, v as markupText, vn as INPUT_ROLES, vt as toNumber, w as getAttr, wn as PHRASING_ONLY, wt as valueLabel, x as toPieces, xn as OBSOLETE, xt as truthy, y as readProperty, yn as MAIN_PARENTS, yt as toStr, z as importsFor, zt as recordAddition } from "./source-DcWmJzQW.js";
|
|
2
2
|
import { a as DEFAULT_SLOT, i as scanParts, o as ESCAPE_STRATEGIES, t as parse } from "./parser-CRWl5Lka.js";
|
|
3
3
|
//#region src/analyzer.ts
|
|
4
4
|
const MAX_DEPTH$1 = 1e3;
|
|
@@ -1738,12 +1738,13 @@ const unpackSaved = (value) => {
|
|
|
1738
1738
|
* await writeFile("build/islands.json", JSON.stringify(islands.manifest));
|
|
1739
1739
|
* ```
|
|
1740
1740
|
*/
|
|
1741
|
-
const deferIslands = ({ url, script = true }) => {
|
|
1741
|
+
const deferIslands = ({ url, script = true, query = false }) => {
|
|
1742
1742
|
if (typeof url !== "string") throw new TypeError("deferIslands needs a url");
|
|
1743
1743
|
return {
|
|
1744
1744
|
mode: "defer",
|
|
1745
1745
|
url,
|
|
1746
1746
|
script,
|
|
1747
|
+
query,
|
|
1747
1748
|
manifest: {}
|
|
1748
1749
|
};
|
|
1749
1750
|
};
|
|
@@ -1764,12 +1765,13 @@ const streamIslands = ({ script = true } = {}) => ({
|
|
|
1764
1765
|
* inline scripts, with `script: false`.
|
|
1765
1766
|
*
|
|
1766
1767
|
* - A deferred island's element fetches its `src`, and replaces itself with the response when it succeeds and is HTML.
|
|
1768
|
+
* With a `query` attribute, the page's query string follows the `src`'s own.
|
|
1767
1769
|
* - A streamed island's HTML arrives in a `<template>`, followed by `<kiln-island fill="n">`, which moves it in place of
|
|
1768
1770
|
* `<kiln-island stream="n">` once the template is parsed.
|
|
1769
1771
|
*
|
|
1770
1772
|
* Otherwise the fallback stays. Kept short and plain, since it is written into pages.
|
|
1771
1773
|
*/
|
|
1772
|
-
const islandScript = "customElements.get(\"kiln-island\")||customElements.define(\"kiln-island\",class extends HTMLElement{connectedCallback(){if(this.k)return;this.k=1;this.style.display=\"contents\";const p=h=>document.createRange().createContextualFragment(h),f=this.getAttribute(\"fill\"),s=this.getAttribute(\"src\");if(f){const t=this.previousElementSibling,e=document.querySelector(`kiln-island[stream=\"${f}\"]`);if(e&&t&&t.localName==\"template\")e.replaceWith(p(t.innerHTML)),t.remove();this.remove()}else if(s)fetch(s).then(r=>r.ok&&/^text\\/html/.test(r.headers.get(\"content-type\"))?r.text():null).then(h=>{if(h!=null)this.replaceWith(p(h))},()=>{})}});";
|
|
1774
|
+
const islandScript = "customElements.get(\"kiln-island\")||customElements.define(\"kiln-island\",class extends HTMLElement{connectedCallback(){if(this.k)return;this.k=1;this.style.display=\"contents\";const p=h=>document.createRange().createContextualFragment(h),f=this.getAttribute(\"fill\"),s=this.getAttribute(\"src\"),q=this.hasAttribute(\"query\")?location.search.slice(1):\"\";if(f){const t=this.previousElementSibling,e=document.querySelector(`kiln-island[stream=\"${f}\"]`);if(e&&t&&t.localName==\"template\")e.replaceWith(p(t.innerHTML)),t.remove();this.remove()}else if(s)fetch(q?s+(s.includes(\"?\")?\"&\":\"?\")+q:s).then(r=>r.ok&&/^text\\/html/.test(r.headers.get(\"content-type\"))?r.text():null).then(h=>{if(h!=null)this.replaceWith(p(h))},()=>{})}});";
|
|
1773
1775
|
/**
|
|
1774
1776
|
* Copies an island's props as JSON values, or fails naming the first value that isn't one. Hashes may be maps, and
|
|
1775
1777
|
* become plain objects.
|
|
@@ -3187,7 +3189,7 @@ var Compiler = class {
|
|
|
3187
3189
|
const render = (run, out, scope, islands, template, props) => {
|
|
3188
3190
|
if (islands.mode === "defer") {
|
|
3189
3191
|
const id = recordIsland(run, span, islands, template.name, props);
|
|
3190
|
-
return element(run, out, scope, islands, `src="${escapeHtml(islands.url + id)}"`);
|
|
3192
|
+
return element(run, out, scope, islands, `src="${escapeHtml(islands.url + id)}"${islands.query ? " query" : ""}`);
|
|
3191
3193
|
}
|
|
3192
3194
|
const state = run.state;
|
|
3193
3195
|
const streamed = state.streamed ??= [];
|
|
@@ -3289,7 +3291,11 @@ var Compiler = class {
|
|
|
3289
3291
|
const parts = Array.isArray(value) ? value.map((item) => part(run, item)) : [part(run, value)];
|
|
3290
3292
|
const { locale, timeZone, islands } = run.state;
|
|
3291
3293
|
const key = `${JSON.stringify(run.state.env.cacheNamespace)}|${templateName}|${locale}|${timeZone}|${JSON.stringify(parts)}`;
|
|
3292
|
-
return islands?.mode === "defer" ? `${key}|islands|${JSON.stringify([
|
|
3294
|
+
return islands?.mode === "defer" ? `${key}|islands|${JSON.stringify([
|
|
3295
|
+
islands.url,
|
|
3296
|
+
islands.script,
|
|
3297
|
+
islands.query
|
|
3298
|
+
])}` : key;
|
|
3293
3299
|
};
|
|
3294
3300
|
const lifetime = (run, value) => {
|
|
3295
3301
|
if (value === null || value === void 0) return null;
|