@lucidkiln/core 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as withCaller, $t as suggest, A as consume, At as passesAhead, B as indentText, Bt as RenderState, C as getAttr, Ct as BLOCKED_NAMES, D as after, Dt as contentSets, E as addSlotFlags, Et as atFront, F as endPlace, Ft as additionsIn, G as locating, Gt as fillScope, H as isPromise, Ht as blockScope, I as fail, It as checkLate, J as renderTemplate, Jt as lookup$1, K as markCaller, Kt as startCapture, L as hold, Lt as closeOutlets, M as embed, Mt as runAhead, N as embedKeyed, Nt as runSequence, O as all, Ot as isRoot, P as embedScope, Pt as OUTLET_INDENT, Q as unhold, Qt as variableNames, R as holdData, Rt as recordAddition, S as toTime, St as valueLabel, T as readableNames, Tt as lookup, U as loadTemplate, Ut as emptyOut, V as indentedText, Vt as Run, W as locate, Wt as endCapture, X as startPlace, Xt as sectionCopy, Y as silence, Yt as ownerOf, Z as step, Zt as sectionScope, _ as markupText, _t as toStr, a as operatorFunction, an as escapeWith, at as describeValue, b as toPieces, bt as typeName, c as checkDepth, cn as KilnIssue, ct as isEmpty, d as functionArgument, dn as createDiagnostic, dt as literalOptions, en as Markup, et as write, f as insertedPiece, fn as issue, ft as mapKeys, g as mapContents, gt as toNumber, h as listOf$1, ht as templateFunctions, i as contains, in as escapeUrl, it as describeType, j as consumeAt, jt as passesFrom, k as checkLength, kt as mayRunAhead, l as entriesOf, ln as KilnRenderError, lt as isHashLike, m as isHtmlStrategy, mt as setOwn, n as builtinFunctions, nn as safe, nt as MISSING, o as rangeOperator, on as TEMPLATE_EXTENSION, ot as equals, p as integerArgument, pt as matchesType, q as passData, qt as childScope, r as builtinTests, rn as escapeHtml, rt as compare, s as Kept, sn as resolveTemplateName, st as hashKeys, t as Source, tn as isSafe, tt as FORMATTERS, u as fromPieces, un as KilnSyntaxError, ut as isPlainObject, v as readProperty, vt as toStringArgument, w as getMethod, wt as expose, x as toPlainData, xt as unwrap, y as scanHtml, yt as truthy, z as importsFor, zt as takeOutput } from "./source-BHcxowQp.js";
2
- import { a as ESCAPE_STRATEGIES, i as DEFAULT_SLOT, r as scanParts, t as parse } from "./parser-BU5dThuk.js";
1
+ import { $ as compare, $t as escapeUrl, A as consume, At as additionsIn, B as loadTemplate, Bt as fillScope, C as getAttr, Ct as contentSets, D as after, Dt as passesFrom, E as addSlotFlags, Et as passesAhead, F as fail, Ft as RenderState, G as renderTemplate, Gt as sectionCopy, H as locating, Ht as childScope, I as hold, It as Run, J as unhold, Jt as suggest, K as silence, Kt as sectionScope, L as holdData, Lt as blockScope, M as embed, Mt as closeOutlets, N as embedKeyed, Nt as recordAddition, O as all, Ot as runAhead, P as embedScope, Pt as takeOutput, Q as MISSING, Qt as escapeHtml, R as importsFor, Rt as emptyOut, S as toTime, St as atFront, T as readableNames, Tt as mayRunAhead, U as markCaller, Ut as lookup$1, V as locate, Vt as startCapture, W as passData, Wt as ownerOf, X as write, Xt as isSafe, Y as withCaller, Yt as Markup, Z as FORMATTERS, Zt as safe, _ as markupText, _t as unwrap, a as operatorFunction, an as KilnSyntaxError, at as isHashLike, b as toPieces, bt as expose, c as checkDepth, ct as mapKeys, d as functionArgument, dt as templateFunctions, en as escapeWith, et as describeType, f as insertedPiece, ft as toNumber, g as mapContents, gt as typeName, h as listOf$1, ht as truthy, i as contains, in as KilnRenderError, it as isEmpty, j as consumeAt, jt as checkLate, k as checkLength, kt as runSequence, l as entriesOf, lt as matchesType, m as isHtmlStrategy, mt as toStringArgument, n as builtinFunctions, nn as resolveTemplateName, nt as equals, o as rangeOperator, on as createDiagnostic, ot as isPlainObject, p as integerArgument, pt as toStr, q as step, qt as variableNames, r as builtinTests, rn as KilnIssue, rt as hashKeys, s as Kept, sn as issue, st as literalOptions, t as Source, tn as TEMPLATE_EXTENSION, tt as describeValue, u as fromPieces, ut as setOwn, v as readProperty, vt as valueLabel, w as getMethod, wt as isRoot, x as toPlainData, xt as lookup, y as scanHtml, yt as BLOCKED_NAMES, z as isPromise, zt as endCapture } from "./source-BbikGqIb.js";
2
+ import { a as ESCAPE_STRATEGIES, i as DEFAULT_SLOT, r as scanParts, t as parse } from "./parser-isboTef0.js";
3
3
  //#region src/analyzer.ts
4
4
  const MAX_DEPTH$1 = 1e3;
5
5
  /** The statement lists nested inside a statement. */
@@ -30,6 +30,7 @@ const analyzeTemplate = (template, globals, reads) => {
30
30
  const source = template.source;
31
31
  const variables = /* @__PURE__ */ new Set();
32
32
  const functions = /* @__PURE__ */ new Set();
33
+ const calls = [];
33
34
  const filters = /* @__PURE__ */ new Set();
34
35
  const tests = /* @__PURE__ */ new Set();
35
36
  const templates = [];
@@ -73,6 +74,18 @@ const analyzeTemplate = (template, globals, reads) => {
73
74
  scopes.pop();
74
75
  if (isolated) scopes.pop();
75
76
  };
77
+ const callArgument = (arg) => {
78
+ const name = arg.type === "Named" ? arg.name : null;
79
+ return arg.type !== "Spread" && arg.value.type === "Literal" ? {
80
+ name,
81
+ literal: true,
82
+ value: arg.value.value
83
+ } : {
84
+ name,
85
+ literal: false,
86
+ value: null
87
+ };
88
+ };
76
89
  const visitArguments = (args) => {
77
90
  for (const arg of args) expression(arg.value);
78
91
  };
@@ -145,7 +158,15 @@ const analyzeTemplate = (template, globals, reads) => {
145
158
  const callee = node.callee;
146
159
  if (callee.type === "Name") {
147
160
  const name = callee.name;
148
- if (name !== "parent" && name !== "block" && !macroNames.has(name) && !importedNames.has(name)) functions.add(name);
161
+ if (name !== "parent" && name !== "block" && !macroNames.has(name) && !importedNames.has(name)) {
162
+ functions.add(name);
163
+ calls.push({
164
+ name,
165
+ args: node.args.map(callArgument),
166
+ start: source.position(node.span.start),
167
+ end: source.position(node.span.end)
168
+ });
169
+ }
149
170
  } else if (!(callee.type === "Member" && callee.object.type === "Name" && importAliases.has(callee.object.name))) expression(callee);
150
171
  visitArguments(node.args);
151
172
  return;
@@ -302,6 +323,7 @@ const analyzeTemplate = (template, globals, reads) => {
302
323
  rest,
303
324
  sets: template.ast.body.flatMap((node) => node.type === "Set" || node.type === "SetBlock" ? [node.name] : []),
304
325
  functions: [...functions],
326
+ calls,
305
327
  filters: [...filters],
306
328
  tests: [...tests],
307
329
  templates,
@@ -2097,18 +2119,14 @@ const printParts = (list) => {
2097
2119
  const parts = [];
2098
2120
  for (const part of list) {
2099
2121
  const last = parts.at(-1);
2100
- if (part.text !== null && last && last.text !== null) {
2101
- const offset = last.text.length;
2102
- const lines = part.lines ? [...last.lines ?? [], ...part.lines.map((start) => start + offset)] : last.lines;
2103
- parts[parts.length - 1] = {
2104
- text: last.text + part.text,
2105
- lines,
2106
- span: {
2107
- start: last.span.start,
2108
- end: part.span.end
2109
- }
2110
- };
2111
- } else parts.push(part);
2122
+ if (part.text !== null && last && last.text !== null) parts[parts.length - 1] = {
2123
+ text: last.text + part.text,
2124
+ span: {
2125
+ start: last.span.start,
2126
+ end: part.span.end
2127
+ }
2128
+ };
2129
+ else parts.push(part);
2112
2130
  }
2113
2131
  const first = parts[0];
2114
2132
  const span = {
@@ -2117,18 +2135,12 @@ const printParts = (list) => {
2117
2135
  };
2118
2136
  if (parts.length === 1 && first.text !== null) {
2119
2137
  const text = first.text;
2120
- if (!first.lines) return (run, _scope, out) => {
2121
- write(run, out, text, span);
2122
- };
2123
- const entry = indentedText(text, first.lines);
2124
2138
  return (run, _scope, out) => {
2125
- const indent = out.indent;
2126
- write(run, out, indent === "" ? text : indentText(entry, indent, out.inline), span);
2139
+ write(run, out, text, span);
2127
2140
  };
2128
2141
  }
2129
2142
  const count = parts.length;
2130
2143
  const texts = [];
2131
- const indented = [];
2132
2144
  const reads = [];
2133
2145
  const evs = [];
2134
2146
  const emits = [];
@@ -2146,7 +2158,6 @@ const printParts = (list) => {
2146
2158
  const root = compiled?.variable ?? path?.root.variable ?? null;
2147
2159
  const choice = compiled?.choice ? emitChoice(compiled.choice, emit) : null;
2148
2160
  texts.push(part.text);
2149
- indented.push(part.text !== null && part.lines ? indentedText(part.text, part.lines) : null);
2150
2161
  reads.push(root !== null ? "path" : choice ? "choice" : "other");
2151
2162
  evs.push(compiled?.ev ?? null);
2152
2163
  emits.push(emit);
@@ -2158,13 +2169,11 @@ const printParts = (list) => {
2158
2169
  spans.push(part.span);
2159
2170
  }
2160
2171
  return (run, scope, out) => {
2161
- const indent = out.indent;
2162
2172
  let text = "";
2163
2173
  for (let i = 0; i < count; i++) {
2164
2174
  const part = texts[i];
2165
2175
  if (part !== null) {
2166
- const entry = indented[i];
2167
- text += indent === "" || !entry ? part : entry.indent === indent && !out.inline ? entry.indented : indentText(entry, indent, text === "" && out.inline);
2176
+ text += part;
2168
2177
  continue;
2169
2178
  }
2170
2179
  const at = spans[i];
@@ -2648,7 +2657,6 @@ var Compiler = class {
2648
2657
  if (parts.length === 0) partsStart = i;
2649
2658
  parts.push({
2650
2659
  text: statement.value,
2651
- lines: statement.lines,
2652
2660
  span: statement.span
2653
2661
  });
2654
2662
  continue;
@@ -2780,15 +2788,13 @@ var Compiler = class {
2780
2788
  const env = this.#env;
2781
2789
  /**
2782
2790
  * Runs passes `index` to `end`. When a pass waits, the passes after it run as `passesFrom` runs them: ahead of
2783
- * it when they may. `ahead` is whether they may, found the first time a pass waits, and `indent` is the
2784
- * output's indentation when the loop started.
2791
+ * it when they may. `ahead` is whether they may, found the first time a pass waits.
2785
2792
  */
2786
- const iterate = (run, scope, out, values, keys, index, end, reused, indent, ahead) => {
2793
+ const iterate = (run, scope, out, values, keys, index, end, reused, ahead) => {
2787
2794
  const length = values.length;
2788
2795
  for (let i = index; i < end; i++) {
2789
2796
  step(run, span);
2790
2797
  const inner = reused ?? childScope(scope);
2791
- const inline = out.inline;
2792
2798
  inner[valueName] = values[i] ?? null;
2793
2799
  if (keyName !== null) inner[keyName] = keys ? keys[i] ?? null : i;
2794
2800
  if (usesLoop) inner.loop = {
@@ -2811,14 +2817,14 @@ var Compiler = class {
2811
2817
  };
2812
2818
  }
2813
2819
  const may = ahead ??= passesAhead(run, scope, effects.sets, effects.elsewhere);
2814
- return passesFrom(run, out, result, inline, i + 1, end, indent, (aheadRun, aheadOut, at) => iterate(aheadRun, scope, aheadOut, values, keys, at, at + 1, shared ? childScope(scope) : null, indent, may), span, may);
2820
+ return passesFrom(run, out, result, i + 1, end, (aheadRun, aheadOut, at) => iterate(aheadRun, scope, aheadOut, values, keys, at, at + 1, shared ? childScope(scope) : null, may), span, may);
2815
2821
  }
2816
2822
  };
2817
2823
  const start = (run, scope, out, value) => {
2818
2824
  const { values, keys } = loopItems(run, span, value, keyName !== null);
2819
2825
  if (values.length === 0) return alternate?.(run, scope, out);
2820
2826
  const reused = shared ? childScope(scope) : null;
2821
- return iterate(run, scope, out, values, keys, 0, values.length, reused, out.indent, null);
2827
+ return iterate(run, scope, out, values, keys, 0, values.length, reused, null);
2822
2828
  };
2823
2829
  const ev = iterable.ev;
2824
2830
  if (!iterable.async) return (run, scope, out) => {
@@ -2945,31 +2951,20 @@ var Compiler = class {
2945
2951
  }
2946
2952
  #blockStatement(node) {
2947
2953
  this.#defineBlock(node);
2948
- const { name, span, indent } = node;
2954
+ const { name, span } = node;
2949
2955
  return (run, scope, out) => {
2950
2956
  const entry = run.blocks.get(name)?.[0];
2951
2957
  if (!entry) return;
2952
2958
  const render = () => entry.def.body(entry.run.within(run.capture, run.blockDepth), blockScope(entry.def, scope), out);
2953
- const own = entry.run.template === run.template;
2954
- if (indent === "") return own ? render() : withCaller(run, span, render);
2955
- const saved = out.indent;
2956
- const inline = out.inline;
2957
- startPlace(out, indent);
2958
- return endPlace(out, saved, inline, own ? render() : withCaller(run, span, render));
2959
+ return entry.run.template === run.template ? render() : withCaller(run, span, render);
2959
2960
  };
2960
2961
  }
2961
2962
  #include(node) {
2962
- const { ignoreMissing, span, indent } = node;
2963
- return this.#embedding(node.template, node.with, span, (run, out, name, variables) => {
2964
- if (indent === "") return embed(run, out, span, name, variables, null, ignoreMissing);
2965
- const saved = out.indent;
2966
- const inline = out.inline;
2967
- startPlace(out, indent);
2968
- return endPlace(out, saved, inline, embed(run, out, span, name, variables, null, ignoreMissing));
2969
- });
2963
+ const { ignoreMissing, span } = node;
2964
+ return this.#embedding(node.template, node.with, span, (run, out, name, variables) => embed(run, out, span, name, variables, null, ignoreMissing));
2970
2965
  }
2971
2966
  #component(node) {
2972
- const { span, indent } = node;
2967
+ const { span } = node;
2973
2968
  const fills = node.fills.map((fill) => ({
2974
2969
  name: fill.name,
2975
2970
  body: this.#body(fill.body),
@@ -2991,11 +2986,7 @@ var Compiler = class {
2991
2986
  scope: callerScope,
2992
2987
  sets: fill.sets
2993
2988
  });
2994
- if (indent === "") return embed(run, out, span, name, variables, slots, false);
2995
- const saved = out.indent;
2996
- const inline = out.inline;
2997
- startPlace(out, indent);
2998
- return endPlace(out, saved, inline, embed(run, out, span, name, variables, slots, false));
2989
+ return embed(run, out, span, name, variables, slots, false);
2999
2990
  });
3000
2991
  }
3001
2992
  /**
@@ -3013,11 +3004,10 @@ var Compiler = class {
3013
3004
  opening = ISLAND_SCRIPT + opening;
3014
3005
  if (isRoot(state, out)) state.islandScript = true;
3015
3006
  }
3016
- const lead = (at) => (out.inline ? "" : out.indent) + at;
3017
- write(run, out, indent === void 0 ? opening : `${lead(indent)}${opening}${closing?.indent === null ? "" : "\n"}`, span);
3007
+ write(run, out, indent === void 0 ? opening : `${indent}${opening}${closing?.indent === null ? "" : "\n"}`, span);
3018
3008
  return after(fallback(run, childScope(scope), out), () => {
3019
3009
  if (!closing) return write(run, out, ISLAND_CLOSING, span);
3020
- const start = closing.indent === null ? "" : lead(closing.indent);
3010
+ const start = closing.indent ?? "";
3021
3011
  const end = closing.newline ? "\n" : "";
3022
3012
  return write(run, out, `${start}${ISLAND_CLOSING}${end}`, span);
3023
3013
  });
@@ -3040,11 +3030,7 @@ var Compiler = class {
3040
3030
  const state = run.state;
3041
3031
  const islands = state.islands;
3042
3032
  if (islands !== null && (islands.mode === "defer" || state.stream !== null && isRoot(state, out) && !run.capture?.section)) return after(loadTemplate(run, name, span), (template) => template ? render(run, out, scope, islands, template, props) : void 0);
3043
- if (indent === "") return embed(run, out, span, name, props, null, false);
3044
- const saved = out.indent;
3045
- const inline = out.inline;
3046
- startPlace(out, indent);
3047
- return endPlace(out, saved, inline, embed(run, out, span, name, props, null, false));
3033
+ return embed(run, out, span, name, props, null, false);
3048
3034
  };
3049
3035
  return this.#embedding(node.template, node.with, span, (run, out, name, variables, scope) => run.state.islands === null ? place(run, out, name, variables, scope) : atFront(run, () => place(run, out, name, variables, scope)));
3050
3036
  }
@@ -3071,8 +3057,8 @@ var Compiler = class {
3071
3057
  }
3072
3058
  #slot(node) {
3073
3059
  const fallback = this.#body(node.body);
3074
- const { name, span, indent } = node;
3075
- const render = (run, scope, out) => {
3060
+ const { name, span } = node;
3061
+ return (run, scope, out) => {
3076
3062
  const fill = run.slots?.get(name);
3077
3063
  if (!fill) return fallback(run, childScope(scope), out);
3078
3064
  try {
@@ -3085,13 +3071,6 @@ var Compiler = class {
3085
3071
  throw markCaller(run, span, error);
3086
3072
  }
3087
3073
  };
3088
- if (indent === "") return render;
3089
- return (run, scope, out) => {
3090
- const saved = out.indent;
3091
- const inline = out.inline;
3092
- startPlace(out, indent);
3093
- return endPlace(out, saved, inline, render(run, scope, out));
3094
- };
3095
3074
  }
3096
3075
  #with(node) {
3097
3076
  const value = this.#expr(node.value);
@@ -3134,11 +3113,10 @@ var Compiler = class {
3134
3113
  if (value instanceof Markup) return value.value;
3135
3114
  throw fail(run, span, "type-error", `"cache" keys are made of strings, numbers, booleans, dates and null, but got a ${typeName(value)}`);
3136
3115
  };
3137
- const fullKey = (run, out, value) => {
3116
+ const fullKey = (run, value) => {
3138
3117
  const parts = Array.isArray(value) ? value.map((item) => part(run, item)) : [part(run, value)];
3139
3118
  const { locale, timeZone, islands } = run.state;
3140
- let key = `${JSON.stringify(run.state.env.cacheNamespace)}|${templateName}|${locale}|${timeZone}|${JSON.stringify(parts)}`;
3141
- if (out.indent !== "") key += `|indent|${JSON.stringify([out.indent, out.inline])}`;
3119
+ const key = `${JSON.stringify(run.state.env.cacheNamespace)}|${templateName}|${locale}|${timeZone}|${JSON.stringify(parts)}`;
3142
3120
  return islands?.mode === "defer" ? `${key}|islands|${JSON.stringify([islands.url, islands.script])}` : key;
3143
3121
  };
3144
3122
  const lifetime = (run, value) => {
@@ -3147,7 +3125,7 @@ var Compiler = class {
3147
3125
  return value;
3148
3126
  };
3149
3127
  const save = (run, scope, out, keyValue, secondsValue) => {
3150
- const name = fullKey(run, out, keyValue);
3128
+ const name = fullKey(run, keyValue);
3151
3129
  const time = lifetime(run, secondsValue);
3152
3130
  const state = run.state;
3153
3131
  const store = state.env.cache;
@@ -3229,7 +3207,7 @@ var Compiler = class {
3229
3207
  * so the outlet must write to that output, not to a capture or a cached section.
3230
3208
  */
3231
3209
  #outlet(node) {
3232
- const { name, span, indent } = node;
3210
+ const { name, span } = node;
3233
3211
  const mark = (run, out) => {
3234
3212
  const state = run.state;
3235
3213
  if (!isRoot(state, out) || run.capture?.section) throw fail(run, span, "misplaced-outlet", `Outlet "${name}" can't be inside "cache", "set", "apply" or a macro`);
@@ -3238,8 +3216,6 @@ var Compiler = class {
3238
3216
  state.outlets.set(name, {
3239
3217
  out,
3240
3218
  offset: out.s.length,
3241
- indent: indent === void 0 ? out.indent : out.indent + indent,
3242
- inline: indent === void 0,
3243
3219
  content: null
3244
3220
  });
3245
3221
  };
@@ -3267,9 +3243,8 @@ var Compiler = class {
3267
3243
  };
3268
3244
  }
3269
3245
  /**
3270
- * `add to`: renders its content and records it for the outlet. The content takes the outlet's indentation when the
3271
- * outlet has been reached. A `once` tag that already added doesn't render again, but is still recorded, so a cached
3272
- * section saves it.
3246
+ * `add to`: renders its content and records it for the outlet. A `once` tag that already added doesn't render again,
3247
+ * but is still recorded, so a cached section saves it.
3273
3248
  */
3274
3249
  #add(node) {
3275
3250
  const body = this.#body(node.body);
@@ -3285,12 +3260,7 @@ var Compiler = class {
3285
3260
  }, front);
3286
3261
  return;
3287
3262
  }
3288
- const capture = {
3289
- s: "",
3290
- indent: OUTLET_INDENT,
3291
- inline: false,
3292
- ahead: null
3293
- };
3263
+ const capture = emptyOut();
3294
3264
  return after(body(run, childScope(scope), capture), () => recordAddition(run, span, {
3295
3265
  outlet,
3296
3266
  html: capture.s,
@@ -4208,7 +4178,7 @@ const isPrecompiled = (value) => typeof value === "object" && value !== null &&
4208
4178
  const mismatch = (name, detail) => new KilnRenderError("precompiled-mismatch", `Precompiled template "${name}" ${detail}. Precompile it again`, name);
4209
4179
  /** Compiles a precompiled template: its source, with the generated statements in place of the ones they cover. */
4210
4180
  const compilePrecompiled = (env, name, template) => {
4211
- if (template.kiln !== 4) throw mismatch(name, "was made by another version of Kiln");
4181
+ if (template.kiln !== 5) throw mismatch(name, "was made by another version of Kiln");
4212
4182
  if (template.autoescape !== env.autoescape) throw mismatch(name, "was compiled with another \"autoescape\" option");
4213
4183
  const runs = /* @__PURE__ */ new Map();
4214
4184
  const create = template.create;
@@ -4288,30 +4258,29 @@ const runtime = {
4288
4258
  unhold,
4289
4259
  /**
4290
4260
  * Continues a generated run after a statement that returned a promise, `pending`: the rest of the run starts at
4291
- * once, ahead of it, when it may, or else once the statement is done. `inline` is `out.inline` from where the
4292
- * function started. See `runAhead`.
4261
+ * once, ahead of it, when it may, or else once the statement is done. See `runAhead`.
4293
4262
  */
4294
- restAhead: (run, out, pending, inline, indent, rest, span) => mayRunAhead(run.state, inline) ? runAhead(run, out, pending, indent, rest, span) : pending.then(() => rest(run, out)),
4263
+ restAhead: (run, out, pending, rest, span) => mayRunAhead(run.state) ? runAhead(run, out, pending, rest, span) : pending.then(() => rest(run, out)),
4295
4264
  contentSets,
4296
4265
  /**
4297
4266
  * Continues a generated loop after a pass that returned a promise, `pending`: passes `from` to `to` run one at a
4298
4267
  * time with `pass`, ahead of it when they may, see `passesAhead`. `sets` are the variables the loop's body sets,
4299
4268
  * and `elsewhere` whether it places content from elsewhere.
4300
4269
  */
4301
- passAhead: (run, scope, out, pending, inline, indent, sets, elsewhere, from, to, pass, span) => passesFrom(run, out, pending, inline, from, to, indent, pass, span, passesAhead(run, scope, sets, elsewhere)),
4270
+ passAhead: (run, scope, out, pending, sets, elsewhere, from, to, pass, span) => passesFrom(run, out, pending, from, to, pass, span, passesAhead(run, scope, sets, elsewhere)),
4302
4271
  /**
4303
4272
  * For a generated loop that pauses inside a pass: starts passes `from` to `to` ahead of it when they may, and returns
4304
4273
  * what the loop calls once the pass is done. Returns null when they may not, and the loop carries on as usual.
4305
4274
  */
4306
- startAhead: (run, scope, out, inline, indent, sets, elsewhere, from, to, pass, span) => {
4307
- if (!mayRunAhead(run.state, inline) || !passesAhead(run, scope, sets, elsewhere)) return null;
4275
+ startAhead: (run, scope, out, sets, elsewhere, from, to, pass, span) => {
4276
+ if (!mayRunAhead(run.state) || !passesAhead(run, scope, sets, elsewhere)) return null;
4308
4277
  let done = NOTHING;
4309
4278
  let failed = NOTHING;
4310
4279
  const pending = new Promise((resolve, reject) => {
4311
4280
  done = resolve;
4312
4281
  failed = reject;
4313
4282
  });
4314
- const joined = passesFrom(run, out, pending, false, from, to, indent, pass, span, true);
4283
+ const joined = passesFrom(run, out, pending, from, to, pass, span, true);
4315
4284
  return {
4316
4285
  join: () => {
4317
4286
  done();
@@ -4323,10 +4292,6 @@ const runtime = {
4323
4292
  }
4324
4293
  };
4325
4294
  },
4326
- startPlace,
4327
- endPlace,
4328
- indentText,
4329
- indentedText,
4330
4295
  embed,
4331
4296
  embedScope,
4332
4297
  embedKeyed,
@@ -4671,10 +4636,6 @@ const HELPERS = [
4671
4636
  "contentSets",
4672
4637
  "passAhead",
4673
4638
  "startAhead",
4674
- "startPlace",
4675
- "endPlace",
4676
- "indentText",
4677
- "indentedText",
4678
4639
  "truthy",
4679
4640
  "isEmpty",
4680
4641
  "equals",
@@ -4861,7 +4822,7 @@ var Generator = class {
4861
4822
  return [
4862
4823
  "// Precompiled by Kiln. Don't edit this file: precompile the template again.",
4863
4824
  "export default {",
4864
- `\tkiln: 4,`,
4825
+ `\tkiln: 5,`,
4865
4826
  `\tautoescape: ${JSON.stringify(this.#env.autoescape)},`,
4866
4827
  `\tsource: ${JSON.stringify(source)},`,
4867
4828
  " create(rt) {",
@@ -4988,7 +4949,7 @@ var Generator = class {
4988
4949
  const next = `${base}_${index + 1}(run, scope, out)`;
4989
4950
  const body = lines.map((line) => line.replace(WAIT_LINE, (_, tabs, result, ahead) => {
4990
4951
  const then = `${result}.then(() => ${next})`;
4991
- const rest = `restAhead(run, out, ${result}, inl, ind, (run, out) => ${next}, ${span})`;
4952
+ const rest = `restAhead(run, out, ${result}, (run, out) => ${next}, ${span})`;
4992
4953
  return `${tabs}if (${result} !== undefined) return ${ahead === AHEAD ? rest : ahead === GUARDED ? `contentSets(run) ? ${then} : ${rest}` : then};`;
4993
4954
  }));
4994
4955
  const last = index === segments.length - 1;
@@ -5039,8 +5000,6 @@ var Generator = class {
5039
5000
  "let steps = state.steps;",
5040
5001
  "const signal = state.signal;",
5041
5002
  `signal !== undefined && signal.aborted && aborted(run, ${span});`,
5042
- "const ind = out.indent;",
5043
- "const inl = out.inline;",
5044
5003
  "let s = \"\";",
5045
5004
  `let ${[
5046
5005
  "q",
@@ -5188,7 +5147,7 @@ var Generator = class {
5188
5147
  }
5189
5148
  #statement(statement, context) {
5190
5149
  switch (statement.type) {
5191
- case "Text": return [this.#text(statement)];
5150
+ case "Text": return [`s += ${JSON.stringify(statement.value)};`];
5192
5151
  case "Output": return this.#output(statement.expression, statement.span, context);
5193
5152
  case "If": return this.#if(statement, context);
5194
5153
  case "For": return this.#for(statement, context);
@@ -5205,26 +5164,6 @@ var Generator = class {
5205
5164
  default: return unsupported();
5206
5165
  }
5207
5166
  }
5208
- /** Text, with its lines indented to where it is inserted. See `indentText`. */
5209
- #text(statement) {
5210
- const text = JSON.stringify(statement.value);
5211
- if (!statement.lines) return `s += ${text};`;
5212
- const lines = JSON.stringify(statement.lines);
5213
- const entry = this.#constant(`text:${statement.span.start}:${statement.span.end}`, "T", `indentedText(${text}, ${lines})`);
5214
- return `s += ind === "" ? ${text} : ${entry}.indent === ind && !out.inline ? ${entry}.indented : indentText(${entry}, ind, s === "" && out.inline);`;
5215
- }
5216
- /**
5217
- * Inserts content at the indentation of the tag that inserts it, with `startPlace` and `endPlace`. Tags at the start
5218
- * of a line need nothing. Saved values go in temporaries rather than a closure, so the function's locals stay fast.
5219
- */
5220
- #place(at, call) {
5221
- if (at === "") return call;
5222
- const [saved, inline] = [this.#temp(), this.#temp()];
5223
- return `(${saved} = out.indent, ${inline} = out.inline, startPlace(out, ${this.#at(at)}), endPlace(out, ${saved}, ${inline}, ${call}))`;
5224
- }
5225
- #at(at) {
5226
- return at === void 0 ? "undefined" : JSON.stringify(at);
5227
- }
5228
5167
  /** Statements inside another, such as a loop's body. */
5229
5168
  #body(list, context) {
5230
5169
  const inner = {
@@ -5513,7 +5452,7 @@ var Generator = class {
5513
5452
  const call = (part, value) => `${name}_${part}(${partParams}${value === void 0 ? "" : `, ${value}`})`;
5514
5453
  const one = `(run, out, j) => ${name}(run, scope, out, ${loop.values}, ${loop.length}, j, j + 1${keys})`;
5515
5454
  const { sets, elsewhere } = this.#setsOf(statement);
5516
- const handOff = (from, tabs, rest) => from === 0 ? `${tabs}return ${loop.index} + 1 < stop ? passAhead(run, scope, out, ${rest}, inl, ind, ${sets}, ${elsewhere}, ${loop.index} + 1, stop, ${one}, ${loop.span}) : ${rest};` : `${tabs}return ${rest};`;
5455
+ const handOff = (from, tabs, rest) => from === 0 ? `${tabs}return ${loop.index} + 1 < stop ? passAhead(run, scope, out, ${rest}, ${sets}, ${elsewhere}, ${loop.index} + 1, stop, ${one}, ${loop.span}) : ${rest};` : `${tabs}return ${rest};`;
5517
5456
  const continued = (from) => segments.slice(from).flatMap((lines, offset) => this.#forgetLines(lines).flatMap((line) => {
5518
5457
  const next = from + offset + 1;
5519
5458
  const value = VALUE_LINE.exec(line);
@@ -5602,7 +5541,7 @@ var Generator = class {
5602
5541
  const ahead = `a${loop.id}`;
5603
5542
  const { index, span } = loop;
5604
5543
  const { sets, elsewhere } = this.#setsOf(statement);
5605
- const fork = `if (${ahead} === null && ${index} + 1 < stop) ${ahead} = startAhead(run, ${loop.outer}, out, inl, ind, ${sets}, ${elsewhere}, ${index} + 1, stop, (run, out, j) => drive(${name}(run, out, j, j + 1)), ${span});`;
5544
+ const fork = `if (${ahead} === null && ${index} + 1 < stop) ${ahead} = startAhead(run, ${loop.outer}, out, ${sets}, ${elsewhere}, ${index} + 1, stop, (run, out, j) => drive(${name}(run, out, j, j + 1)), ${span});`;
5606
5545
  const body = this.#forgetLines(this.#setFlags(lines)).flatMap((line) => {
5607
5546
  if (line.trim() === FORK) return [line.replace(FORK, fork)];
5608
5547
  const wait = WAIT_LINE.exec(line);
@@ -5767,7 +5706,7 @@ var Generator = class {
5767
5706
  ...target.lines,
5768
5707
  ...variables.lines,
5769
5708
  ...variables.charge(span),
5770
- ...this.#wait(span, this.#place(statement.indent, variables.embed(span, target.name, "null", statement.ignoreMissing)), context.top)
5709
+ ...this.#wait(span, variables.embed(span, target.name, "null", statement.ignoreMissing), context.top)
5771
5710
  ];
5772
5711
  }
5773
5712
  /**
@@ -5855,7 +5794,7 @@ var Generator = class {
5855
5794
  `${slots} = new Map();`,
5856
5795
  ...fills.map((fill) => `${slots}.set(${JSON.stringify(fill.name)}, { body: ${this.#nested(fill.body, statement.span, context)}, run, scope: ${context.scope}, sets: ${mayWrite(fill.body)} });`),
5857
5796
  ...variables.charge(span),
5858
- ...this.#wait(span, this.#place(statement.indent, variables.embed(span, target.name, slots, false)), context.top),
5797
+ ...this.#wait(span, variables.embed(span, target.name, slots, false), context.top),
5859
5798
  ...fills.some((fill) => setsVariables(fill.body)) ? this.#forgetAll() : fills.some((fill) => containsNode(fill.body, (record) => record.type === "Block")) ? this.#afterBlocks() : []
5860
5799
  ];
5861
5800
  }
@@ -5863,7 +5802,6 @@ var Generator = class {
5863
5802
  #slot(statement, context) {
5864
5803
  const span = this.#span(statement.span);
5865
5804
  const fill = this.#temp();
5866
- const at = statement.indent;
5867
5805
  const sets = [...setsIn(statement.body)];
5868
5806
  const scope = sets.length > 0 ? this.#temp() : context.scope;
5869
5807
  let fallback = this.#body(statement.body, {
@@ -5875,23 +5813,10 @@ var Generator = class {
5875
5813
  ...fallback,
5876
5814
  ...sets.flatMap((name) => this.#forget(name))
5877
5815
  ];
5878
- if (at !== "" && !statement.body.every(isBlank)) {
5879
- const [saved, inline] = [this.#temp(), this.#temp()];
5880
- fallback = [
5881
- `${saved} = out.indent;`,
5882
- `${inline} = out.inline;`,
5883
- `startPlace(out, ${this.#at(at)});`,
5884
- "{",
5885
- ...indent(["const ind = out.indent;", ...fallback]),
5886
- "}",
5887
- `out.indent = ${saved};`,
5888
- `if (out.inline) out.inline = ${inline};`
5889
- ];
5890
- }
5891
5816
  return [
5892
5817
  `${fill} = run.slots === null ? undefined : run.slots.get(${JSON.stringify(statement.name)});`,
5893
5818
  `if (${fill} !== undefined) {`,
5894
- ...indent(this.#wait(span, this.#place(at, `fillSlot(run, ${span}, ${fill}, out)`), context.top)),
5819
+ ...indent(this.#wait(span, `fillSlot(run, ${span}, ${fill}, out)`, context.top)),
5895
5820
  "} else {",
5896
5821
  ...indent(fallback),
5897
5822
  "}"
@@ -5905,7 +5830,7 @@ var Generator = class {
5905
5830
  if (context.inLoop) return unsupported();
5906
5831
  this.#pending.push([statement.body, context.strategy]);
5907
5832
  const span = this.#span(statement.span);
5908
- return [...this.#wait(span, this.#place(statement.indent, `placeBlock(run, ${span}, ${JSON.stringify(statement.name)}, ${context.scope}, out)`), context.top), ...this.#afterBlocks()];
5833
+ return [...this.#wait(span, `placeBlock(run, ${span}, ${JSON.stringify(statement.name)}, ${context.scope}, out)`, context.top), ...this.#afterBlocks()];
5909
5834
  }
5910
5835
  /** Forgets every variable lookup after a block is placed when the block, perhaps a child template's version, may set any variable. */
5911
5836
  #afterBlocks() {