@lucidkiln/core 1.4.0 → 1.6.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 +11 -0
- package/dist/cli.js +2 -2
- package/dist/{environment-CFAjojgY.d.ts → environment-By1fPtOz.d.ts} +73 -8
- package/dist/environment-By1fPtOz.d.ts.map +1 -0
- package/dist/{format-A7Ol0apX.js → format-Cgjx6D1j.js} +2 -2
- package/dist/{format-A7Ol0apX.js.map → format-Cgjx6D1j.js.map} +1 -1
- package/dist/format.js +1 -1
- package/dist/index.d.ts +17 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +102 -20
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{source-C2pjTx-Y.js → source-DxHQeBEo.js} +25 -1
- package/dist/source-DxHQeBEo.js.map +1 -0
- package/package.json +1 -1
- package/dist/environment-CFAjojgY.d.ts.map +0 -1
- package/dist/source-C2pjTx-Y.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
- New host components. A loader can return a component written in JavaScript with `hostComponent`, such as one made with React or Svelte. ([8d43019](https://github.com/buildlucid/kiln/commit/8d43019e8a0278449232b518d9e0a0f22547d83e))
|
|
6
|
+
- `withRender` functions and host components can add HTML to an outlet with `render.addTo`. ([8d43019](https://github.com/buildlucid/kiln/commit/8d43019e8a0278449232b518d9e0a0f22547d83e))
|
|
7
|
+
- `generateManifest` takes a `components` list of the files your loader returns as host components. ([8d43019](https://github.com/buildlucid/kiln/commit/8d43019e8a0278449232b518d9e0a0f22547d83e))
|
|
8
|
+
|
|
9
|
+
## 1.5.0
|
|
10
|
+
|
|
11
|
+
- New `globals` render option, which adds globals for one render on top of the environment's. ([8560145](https://github.com/buildlucid/kiln/commit/8560145ff40508c0fff2390677bfb75d0d51e306))
|
|
12
|
+
- Deferred island manifest entries now record the render's `locale` and `timeZone`, and both are part of the island's id, so ids from earlier versions change. ([8560145](https://github.com/buildlucid/kiln/commit/8560145ff40508c0fff2390677bfb75d0d51e306))
|
|
13
|
+
|
|
3
14
|
## 1.4.0
|
|
4
15
|
|
|
5
16
|
- New `builtins` export, which lists Kiln's own function, filter and test names. ([8d99639](https://github.com/buildlucid/kiln/commit/8d99639916ce3dfb920d567ed4de9069ec739cd7))
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { an as KilnSyntaxError } from "./source-
|
|
3
|
-
import { n as format, t as KilnFormatError } from "./format-
|
|
2
|
+
import { an as KilnSyntaxError } from "./source-DxHQeBEo.js";
|
|
3
|
+
import { n as format, t as KilnFormatError } from "./format-Cgjx6D1j.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";
|
|
@@ -53,10 +53,16 @@ declare class KilnRenderError extends Error {
|
|
|
53
53
|
type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
54
54
|
[key: string]: JsonValue;
|
|
55
55
|
};
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* One deferred island: the template to render, the props to render it with, and the locale and time zone of the render
|
|
58
|
+
* that deferred it. Hosts render it with `render(entry.template, entry.props, { locale: entry.locale, timeZone:
|
|
59
|
+
* entry.timeZone })`, plus any other render options it needs, such as `state` or `globals`.
|
|
60
|
+
*/
|
|
57
61
|
type IslandEntry = {
|
|
58
62
|
template: string;
|
|
59
63
|
props: Record<string, JsonValue>;
|
|
64
|
+
locale: string;
|
|
65
|
+
timeZone: string;
|
|
60
66
|
};
|
|
61
67
|
/** Every island deferred in a build, by id. Hosts save it as JSON and look ids up in it. */
|
|
62
68
|
type IslandManifest = Record<string, IslandEntry>;
|
|
@@ -159,6 +165,13 @@ type RenderInfo<State = unknown> = {
|
|
|
159
165
|
* when that data changes. Does nothing outside a cached section.
|
|
160
166
|
*/
|
|
161
167
|
tagCache(...tags: string[]): void;
|
|
168
|
+
/**
|
|
169
|
+
* Adds HTML to an outlet, as `add to` does where the call happens. `once` adds it only the first time the render
|
|
170
|
+
* sees that key, which never clashes with an `add to once` tag.
|
|
171
|
+
*/
|
|
172
|
+
addTo(outlet: string, html: string, options?: {
|
|
173
|
+
once?: string;
|
|
174
|
+
}): void;
|
|
162
175
|
};
|
|
163
176
|
//#endregion
|
|
164
177
|
//#region src/analyzer.d.ts
|
|
@@ -216,6 +229,50 @@ type Analysis = {
|
|
|
216
229
|
exports: TemplateExport[];
|
|
217
230
|
};
|
|
218
231
|
//#endregion
|
|
232
|
+
//#region src/runtime/markup.d.ts
|
|
233
|
+
/**
|
|
234
|
+
* A string that is already safe to output with one escaping strategy.
|
|
235
|
+
*
|
|
236
|
+
* Output skips escaping for markup whose strategy matches, and escapes it otherwise.
|
|
237
|
+
*/
|
|
238
|
+
declare class Markup {
|
|
239
|
+
readonly value: string;
|
|
240
|
+
readonly strategy: EscapeStrategy;
|
|
241
|
+
constructor(value: string, strategy: EscapeStrategy);
|
|
242
|
+
toString(): string;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Marks a string as safe to output with one escaping strategy, `"html"` by default.
|
|
246
|
+
*
|
|
247
|
+
* Return this from a function or filter that produces trusted HTML, such as rendered rich text.
|
|
248
|
+
*/
|
|
249
|
+
declare const safe: (value: string, strategy?: EscapeStrategy) => Markup;
|
|
250
|
+
/** Checks whether a value was marked safe with `safe()` or by a template. */
|
|
251
|
+
declare const isSafe: (value: unknown) => value is Markup;
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/compiler/host.d.ts
|
|
254
|
+
declare const hostMark: unique symbol;
|
|
255
|
+
/**
|
|
256
|
+
* Renders a component written in JavaScript. Gets the props passed with `with`, each slot the caller filled rendered
|
|
257
|
+
* to markup, and the render's request data.
|
|
258
|
+
*/
|
|
259
|
+
type HostRender<State = unknown> = (props: Record<string, unknown>, slots: Record<string, Markup>, render: RenderInfo<State>) => unknown;
|
|
260
|
+
/** A component written in JavaScript, which a loader returns in place of template source. Create it with `hostComponent`. */
|
|
261
|
+
type HostComponent<State = unknown> = {
|
|
262
|
+
readonly [hostMark]: true;
|
|
263
|
+
/** A method, so a loader can return a component that declares any state. */
|
|
264
|
+
render(...args: Parameters<HostRender<State>>): unknown;
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Wraps a function that renders a component, such as one made with a UI library, so a loader can return it for a
|
|
268
|
+
* name. It should return markup made with `safe`, or a promise of it. A plain string is escaped.
|
|
269
|
+
*
|
|
270
|
+
* ```ts
|
|
271
|
+
* load: (name) => name.endsWith(".tsx") ? hostComponent((props, slots) => safe(renderReact(name, props, slots))) : null
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
declare const hostComponent: <State = unknown>(render: HostRender<State>) => HostComponent<State>;
|
|
275
|
+
//#endregion
|
|
219
276
|
//#region src/compiler/precompiled.d.ts
|
|
220
277
|
/**
|
|
221
278
|
* A template compiled to JavaScript at build time, the default export of a module `precompile` wrote. Loaders return
|
|
@@ -240,16 +297,18 @@ type HtmlCheckLevel = "off" | "warning" | "error";
|
|
|
240
297
|
type HtmlChecks = boolean | Partial<Record<HtmlCheck, HtmlCheckLevel>>;
|
|
241
298
|
//#endregion
|
|
242
299
|
//#region src/environment.d.ts
|
|
300
|
+
/** What a loader returns for a template that exists: its source, a precompiled module's default export, or a host component. */
|
|
301
|
+
type LoadedTemplate = string | PrecompiledTemplate | HostComponent;
|
|
243
302
|
/**
|
|
244
303
|
* Where templates come from. Kiln calls `load` once per resolved name that exists, until `invalidate`, and remembers
|
|
245
304
|
* a limited number of missing names.
|
|
246
305
|
*/
|
|
247
306
|
type Loader = {
|
|
248
307
|
/**
|
|
249
|
-
* Returns the source for a resolved name, such as `pages/page.kiln`,
|
|
250
|
-
* `null` if it does not exist. May return a promise or another thenable.
|
|
308
|
+
* Returns the source for a resolved name, such as `pages/page.kiln`, a precompiled module's default export, a
|
|
309
|
+
* `hostComponent`, or `null` if it does not exist. May return a promise or another thenable.
|
|
251
310
|
*/
|
|
252
|
-
load(name: string):
|
|
311
|
+
load(name: string): LoadedTemplate | null | PromiseLike<LoadedTemplate | null>;
|
|
253
312
|
/** Returns every resolved name the loader holds. Rendering never calls it; tools such as `generateTypes` do. */
|
|
254
313
|
list?(): string[] | Promise<string[]>;
|
|
255
314
|
};
|
|
@@ -365,6 +424,12 @@ type KilnOptions<State = undefined, Schema extends KilnSchema = DefaultSchema> =
|
|
|
365
424
|
types: TypeChecks<Schema["types"]>;
|
|
366
425
|
});
|
|
367
426
|
type BaseRenderOptions = {
|
|
427
|
+
/**
|
|
428
|
+
* Globals for this render, layered over the environment's. `check`, generated types and exports only know the
|
|
429
|
+
* environment's globals, so give each one a default there. `cache` keys don't include them, so add any that change a
|
|
430
|
+
* cached section's output to its key.
|
|
431
|
+
*/
|
|
432
|
+
globals?: Record<string, unknown>;
|
|
368
433
|
locale?: string;
|
|
369
434
|
timeZone?: string;
|
|
370
435
|
/** Stops the render when aborted. A real `AbortSignal` works. */
|
|
@@ -437,11 +502,11 @@ declare const builtins: {
|
|
|
437
502
|
declare const createKiln: <State = undefined, Schema extends KilnSchema = DefaultSchema>(options: KilnOptions<State, Schema>) => Kiln<State, Schema>;
|
|
438
503
|
/**
|
|
439
504
|
* A loader for templates held in memory, keyed by name. Keys without an extension get `.kiln`. Each template is its
|
|
440
|
-
* source
|
|
505
|
+
* source, a precompiled module's default export or a host component.
|
|
441
506
|
*
|
|
442
507
|
* Works on every runtime, including Cloudflare Workers.
|
|
443
508
|
*/
|
|
444
|
-
declare const memoryLoader: (templates: Record<string,
|
|
509
|
+
declare const memoryLoader: (templates: Record<string, LoadedTemplate> | Map<string, LoadedTemplate>) => Omit<Loader, "list"> & {
|
|
445
510
|
list(): string[];
|
|
446
511
|
};
|
|
447
512
|
/**
|
|
@@ -470,5 +535,5 @@ declare const memoryCache: ({ max }?: {
|
|
|
470
535
|
}) => void;
|
|
471
536
|
};
|
|
472
537
|
//#endregion
|
|
473
|
-
export {
|
|
474
|
-
//# sourceMappingURL=environment-
|
|
538
|
+
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 };
|
|
539
|
+
//# sourceMappingURL=environment-By1fPtOz.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-By1fPtOz.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;;KAGM;EACX;EACA;EACA;;;;;cAyBY,wBAAwB;EAC3B;WACA,aAAa;EAEtB,YAAY,aAAa,cAAc,QAAQ;;;;;cAqBnC,wBAAwB;;EAC3B;WACA;WACA;WACA;WACA;;WAEA;;WAEA,eAA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3B;EAAU,QAAQ;;EAAY,OAAO;;;KAGpD,gBAAgB,SAAS,yBAEd,WAAW,UAAU,YAAY,SAAS,iCACnC,SAClB,UAAU,cAAc,WACxB,SAAS,cAAc;KAGhB,KACX,mBACA,eAAe,aAAa;;EAG5B,OAAO,aAAa,aAAa,sBAChC,MAAM,SACH,MAAM,gBAAgB,gBAAgB,MAAM,sBAAsB,SACnE;;;;EAIH,YAAY,aAAa,aAAa,sBACrC,MAAM,MACN,OAAO,cAAc,MAAM,yBACxB,MAAM,gBAAgB,gBAAgB,MAAM,sBAAsB,SACnE;;;;;EAKH,aAAa,aAAa,aAAa,sBACtC,MAAM,SACH,MAAM,gBAAgB,gBAAgB,MAAM,sBAAsB,SACnE,QAAQ,eAAe;;EAE1B,MAAM,cAAc,kBAAkB,QAAQ;;EAE9C,QAAQ,cAAc,kBAAkB,QAAQ;;;;;EAKhD,SACC,MAAM,aAAa,sBACnB,uBACG,2BAA2B,SAC1B,UAAU,cAAc,WACxB,SAAS,cAAc,UACzB;;;;;EAKH,WAAW,cAAc,kBAAkB;;EAE3C,WAAW;;;;;;;;;cAUC,aAAc,aAAa,YAAU,IAC7C,SACF,YAAY;;cA2DF;WACH;WACA;WACA;;;;;;;;;;cA2hBG,aACZ,mBACA,eAAe,aAAa,eAAa,SAEhC,YAAY,OAAO,YAC1B,KAAK,OAAO;;;;;;;cAoHF,eAAY,WACb,eAAe,kBAAkB,YAAY,oBACtD,KAAK;EAAoB;;;;;;;;;;cAkBf,gBAAW;EAAsB;;;;;;;;;;;;EA0B1B,UAAA;IAAE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { an as KilnSyntaxError, on as createDiagnostic, r as builtinTests, t as Source } from "./source-
|
|
1
|
+
import { an as KilnSyntaxError, on as createDiagnostic, r as builtinTests, t as Source } from "./source-DxHQeBEo.js";
|
|
2
2
|
import { r as scanParts, t as parse } from "./parser-BZpRlGWi.js";
|
|
3
3
|
//#region src/formatter/delimiters.ts
|
|
4
4
|
const KEYWORDS = /* @__PURE__ */ new Set([
|
|
@@ -694,4 +694,4 @@ const format = (text, options = {}) => applyEdits(text, formatEdits(text, option
|
|
|
694
694
|
//#endregion
|
|
695
695
|
export { format as n, formatEdits as r, KilnFormatError as t };
|
|
696
696
|
|
|
697
|
-
//# sourceMappingURL=format-
|
|
697
|
+
//# sourceMappingURL=format-Cgjx6D1j.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-A7Ol0apX.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 * 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 {\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 { type DelimitedPart, type Part, scanParts } from \"../lexer/lexer.js\";\nimport { parse } from \"../parser/parser.js\";\nimport { 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 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 * 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\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\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\" && 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}\n\t}\n\n\tfor (const { part, line } of delimiters) {\n\t\tconst indent = newIndent(line) ?? oldIndent(line);\n\t\tconst printed = printDelimiter(text, part, indent, unit);\n\t\tif (printed !== null && printed !== text.slice(part.start, part.end)) {\n\t\t\tedits.push({ start: part.start, end: part.end, text: printed });\n\t\t}\n\t}\n\n\treturn edits.sort((a, b) => a.start - b.start || a.end - b.end);\n};\n\nconst insideDelimiter = (\n\tdelimiters: readonly { part: DelimitedPart }[],\n\toffset: number,\n) => delimiters.some(({ part }) => offset > part.start && offset < part.end);\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/** Removes whitespace at the start and end of lines, and blank lines, which the formatter may change. */\nconst normaliseText = (value: string) =>\n\tvalue\n\t\t.replace(/[ \\t\\r\\f\\v]+$/gm, \"\")\n\t\t.replace(/^[ \\t\\f\\v]+/gm, \"\")\n\t\t.replace(/\\n{2,}/g, \"\\n\");\n\n/** A copy of a syntax tree without positions or layout, with text normalised and text left empty by that removed. */\nconst normaliseTree = (value: unknown): unknown => {\n\tif (Array.isArray(value)) {\n\t\treturn value\n\t\t\t.map(normaliseTree)\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 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\" && (value as { type?: unknown }).type === \"Text\"\n\t\t\t\t? normaliseText(item as string)\n\t\t\t\t: normaliseTree(item);\n\t}\n\treturn copy;\n};\n\n/** The syntax tree as JSON, without the whitespace the formatter may change, so two trees can be compared. */\nconst shape = (text: string): string =>\n\tJSON.stringify(normaliseTree(parse(text, { isTest }).ast));\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\tlet edits = planEdits(text, scanParts(text).parts, {\n\t\tuseTabs: options.useTabs ?? true,\n\t\ttabWidth,\n\t});\n\tconst range = options.range;\n\tif (range) {\n\t\tedits = edits.filter(\n\t\t\t(edit) => edit.end >= range.start && edit.start <= range.end,\n\t\t);\n\t}\n\n\tconst formatted = applyEdits(text, edits);\n\tconst changed = parse(formatted, { isTest });\n\tif (changed.problems.length > 0 || shape(formatted) !== shape(text)) {\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;EAC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MAAM,SAAS,KAAK,SAAS,MAAM,GAC1D;CAGD,MAAM,YAAY,WAAW,MAAM,KAAK;CAExC,IADgB,MAAM,WAAW,EAAE,OAAO,CAChC,CAAC,CAAC,SAAS,SAAS,KAAK,MAAM,SAAS,MAAM,MAAM,IAAI,GACjE,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-Cgjx6D1j.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 * 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 {\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 { type DelimitedPart, type Part, scanParts } from \"../lexer/lexer.js\";\nimport { parse } from \"../parser/parser.js\";\nimport { 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 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 * 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\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\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\" && 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}\n\t}\n\n\tfor (const { part, line } of delimiters) {\n\t\tconst indent = newIndent(line) ?? oldIndent(line);\n\t\tconst printed = printDelimiter(text, part, indent, unit);\n\t\tif (printed !== null && printed !== text.slice(part.start, part.end)) {\n\t\t\tedits.push({ start: part.start, end: part.end, text: printed });\n\t\t}\n\t}\n\n\treturn edits.sort((a, b) => a.start - b.start || a.end - b.end);\n};\n\nconst insideDelimiter = (\n\tdelimiters: readonly { part: DelimitedPart }[],\n\toffset: number,\n) => delimiters.some(({ part }) => offset > part.start && offset < part.end);\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/** Removes whitespace at the start and end of lines, and blank lines, which the formatter may change. */\nconst normaliseText = (value: string) =>\n\tvalue\n\t\t.replace(/[ \\t\\r\\f\\v]+$/gm, \"\")\n\t\t.replace(/^[ \\t\\f\\v]+/gm, \"\")\n\t\t.replace(/\\n{2,}/g, \"\\n\");\n\n/** A copy of a syntax tree without positions or layout, with text normalised and text left empty by that removed. */\nconst normaliseTree = (value: unknown): unknown => {\n\tif (Array.isArray(value)) {\n\t\treturn value\n\t\t\t.map(normaliseTree)\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 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\" && (value as { type?: unknown }).type === \"Text\"\n\t\t\t\t? normaliseText(item as string)\n\t\t\t\t: normaliseTree(item);\n\t}\n\treturn copy;\n};\n\n/** The syntax tree as JSON, without the whitespace the formatter may change, so two trees can be compared. */\nconst shape = (text: string): string =>\n\tJSON.stringify(normaliseTree(parse(text, { isTest }).ast));\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\tlet edits = planEdits(text, scanParts(text).parts, {\n\t\tuseTabs: options.useTabs ?? true,\n\t\ttabWidth,\n\t});\n\tconst range = options.range;\n\tif (range) {\n\t\tedits = edits.filter(\n\t\t\t(edit) => edit.end >= range.start && edit.start <= range.end,\n\t\t);\n\t}\n\n\tconst formatted = applyEdits(text, edits);\n\tconst changed = parse(formatted, { isTest });\n\tif (changed.problems.length > 0 || shape(formatted) !== shape(text)) {\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,OAA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tB,IAAI,OACH,QAAQ,MAAM,QACZ,SAAS,KAAK,OAAO,MAAM,SAAS,KAAK,SAAS,MAAM,GAC1D;CAGD,MAAM,YAAY,WAAW,MAAM,KAAK;CAExC,IADgB,MAAM,WAAW,EAAE,OAAO,CAChC,CAAC,CAAC,SAAS,SAAS,KAAK,MAAM,SAAS,MAAM,MAAM,IAAI,GACjE,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-Cgjx6D1j.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +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 { A as
|
|
3
|
-
//#region src/runtime/markup.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* A string that is already safe to output with one escaping strategy.
|
|
6
|
-
*
|
|
7
|
-
* Output skips escaping for markup whose strategy matches, and escapes it otherwise.
|
|
8
|
-
*/
|
|
9
|
-
export declare class Markup {
|
|
10
|
-
readonly value: string;
|
|
11
|
-
readonly strategy: EscapeStrategy;
|
|
12
|
-
constructor(value: string, strategy: EscapeStrategy);
|
|
13
|
-
toString(): string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Marks a string as safe to output with one escaping strategy, `"html"` by default.
|
|
17
|
-
*
|
|
18
|
-
* Return this from a function or filter that produces trusted HTML, such as rendered rich text.
|
|
19
|
-
*/
|
|
20
|
-
export declare const safe: (value: string, strategy?: EscapeStrategy) => Markup;
|
|
21
|
-
/** Checks whether a value was marked safe with `safe()` or by a template. */
|
|
22
|
-
export declare const isSafe: (value: unknown) => value is Markup;
|
|
23
|
-
//#endregion
|
|
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-By1fPtOz.js";
|
|
24
3
|
//#region src/runtime/exposure.d.ts
|
|
25
4
|
/**
|
|
26
5
|
* Lists the members of a class that templates may read or call.
|
|
@@ -62,9 +41,22 @@ type KilnManifest = {
|
|
|
62
41
|
globals: string[];
|
|
63
42
|
types: string[];
|
|
64
43
|
htmlChecks: HtmlChecks;
|
|
44
|
+
/** The files the loader returns as host components. The first entry matching a file applies. */
|
|
45
|
+
components: ManifestComponent[];
|
|
46
|
+
};
|
|
47
|
+
/** Files a loader returns as host components, which editors complete and don't check as templates. */
|
|
48
|
+
type ManifestComponent = {
|
|
49
|
+
/** File extensions, such as `[".tsx"]`. */
|
|
50
|
+
extensions: string[];
|
|
51
|
+
/** Globs relative to `root` the files must match. Any file with the extensions when left out. */
|
|
52
|
+
include?: string[];
|
|
53
|
+
/** Globs relative to `root` the files must not match. */
|
|
54
|
+
exclude?: string[];
|
|
55
|
+
/** The TypeScript type of a component's props, with `$file` standing for the component's module. */
|
|
56
|
+
props?: string;
|
|
65
57
|
};
|
|
66
58
|
/**
|
|
67
|
-
* Writes `kiln.json` for an environment: the names of its functions, filters, tests, globals and prop types, and its HTML check levels, so editors can check templates without running your code. `root` is the template folder, relative to where you write the file.
|
|
59
|
+
* Writes `kiln.json` for an environment: the names of its functions, filters, tests, globals and prop types, and its HTML check levels, so editors can check templates without running your code. `root` is the template folder, relative to where you write the file, and `components` the files your loader returns as host components.
|
|
68
60
|
*
|
|
69
61
|
* ```ts
|
|
70
62
|
* await writeFile("kiln.json", generateManifest(kiln, { root: "src/templates" }));
|
|
@@ -72,6 +64,7 @@ type KilnManifest = {
|
|
|
72
64
|
*/
|
|
73
65
|
export declare const generateManifest: <State, Schema extends KilnSchema>(kiln: Kiln<State, Schema>, options: {
|
|
74
66
|
root: string;
|
|
67
|
+
components?: ManifestComponent[];
|
|
75
68
|
}) => string;
|
|
76
69
|
//#endregion
|
|
77
70
|
//#region src/typegen.d.ts
|
|
@@ -87,5 +80,5 @@ export declare const generateManifest: <State, Schema extends KilnSchema>(kiln:
|
|
|
87
80
|
*/
|
|
88
81
|
export declare const generateTypes: (kiln: Pick<Kiln, "analyze">, names: Iterable<string>) => Promise<string>;
|
|
89
82
|
//#endregion
|
|
90
|
-
export { type AbortSignalLike, type AnalysedProp, type Analysis, type CallArgument, type DeferredIslands, type Diagnostic, type EscapeStrategy, type FunctionCall, type HtmlCheck, type HtmlCheckLevel, type HtmlChecks, type IslandEntry, type IslandManifest, type IslandMode, type JsonValue, type Kiln, type KilnCache, type KilnCallable, type KilnFilters, type KilnFunctions, type KilnGlobals, type KilnManifest, type KilnOptions, KilnRenderError, type KilnSchema, KilnSyntaxError, type KilnTemplates, type KilnTests, type KilnTypes, type Limits, type Loader, type Position, type PrecompiledTemplate, type PropType, type RenderAware, type RenderInfo, type RenderOptions, type ShapeKey, type StreamedIslands, type TemplateBlock, type TemplateContext, type TemplateExport, type TemplateLocation, type TemplateName, type TemplateReference, type TypeChecks, type TypeName, builtins, createKiln, deferIslands, islandScript, memoryCache, memoryLoader, streamIslands, withRender };
|
|
83
|
+
export { type AbortSignalLike, type AnalysedProp, type Analysis, type CallArgument, type DeferredIslands, type Diagnostic, type EscapeStrategy, type FunctionCall, type HostComponent, type HostRender, type HtmlCheck, type HtmlCheckLevel, type HtmlChecks, type IslandEntry, type IslandManifest, type IslandMode, type JsonValue, type Kiln, type KilnCache, type KilnCallable, type KilnFilters, type KilnFunctions, type KilnGlobals, type KilnManifest, type KilnOptions, KilnRenderError, type KilnSchema, KilnSyntaxError, type KilnTemplates, type KilnTests, type KilnTypes, type Limits, type LoadedTemplate, type Loader, type ManifestComponent, Markup, type Position, type PrecompiledTemplate, type PropType, type RenderAware, type RenderInfo, type RenderOptions, type ShapeKey, type StreamedIslands, type TemplateBlock, type TemplateContext, type TemplateExport, type TemplateLocation, type TemplateName, type TemplateReference, type TypeChecks, type TypeName, builtins, createKiln, deferIslands, hostComponent, isSafe, islandScript, memoryCache, memoryLoader, safe, streamIslands, withRender };
|
|
91
84
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/runtime/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/runtime/exposure.ts","../src/html/scanner.ts","../src/manifest.ts","../src/typegen.ts"],"mappings":";;;;;;;;;;;;qBAYa;;;;;;;;;;qBAWA;;;;;;;qBCsCA,eAAY;;;;KCvDb;;EAEX;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY;;EAEZ,YAAY;;;KAID;;EAEX;;EAEA;;EAEA;;EAEA;;;;;;;;;qBAgBY,mBAAoB,OAAO,eAAe,YAAU,MAC1D,KAAK,OAAO,SAAO;EACd;EAAc,aAAa;;;;;;;;;;;;;;qBCwB1B,gBAAa,MACnB,KAAK,kBAAgB,OACpB,qBACL"}
|