@rohal12/spindle 0.62.8 → 0.62.9

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.
@@ -5827,6 +5827,29 @@ function parseMemberIdentifier(src) {
5827
5827
  if (object.type !== "Identifier" || object.start !== 0 || object.end !== 1 || property.type !== "Identifier" || property.start !== 2 || property.end !== src.length + 2) return null;
5828
5828
  return property.name;
5829
5829
  }
5830
+ /** Read the contiguous dot members after a variable, keeping decoded names. */
5831
+ function readMemberPath(src, end) {
5832
+ const path = [];
5833
+ const p = tokenizerAt(src, end, "expression", { afterOperand: true });
5834
+ try {
5835
+ for (;;) {
5836
+ p.nextToken();
5837
+ if (p.type !== types$1.dot || p.start !== end) break;
5838
+ const dotEnd = p.end;
5839
+ p.nextToken();
5840
+ if (p.start !== dotEnd || p.type !== types$1.name && !p.type.keyword) break;
5841
+ if (!/^\w+$/.test(String(p.value))) break;
5842
+ path.push(String(p.value));
5843
+ end = p.end;
5844
+ }
5845
+ } catch (error) {
5846
+ if (!(error instanceof SyntaxError)) throw error;
5847
+ }
5848
+ return {
5849
+ path,
5850
+ end
5851
+ };
5852
+ }
5830
5853
  /**
5831
5854
  * Parse `src` as `goal`, reading `%` as `percentAt` says where it says, and
5832
5855
  * noting where it read a transient in `transientsRead`.
@@ -13310,10 +13333,10 @@ function registerMacroMetadata(name, metadata) {
13310
13333
  companionParents.set(sub, parents);
13311
13334
  }
13312
13335
  }
13313
- /** The parents declaring a branching companion (listbox options are values). */
13336
+ /** The parents declaring a branching companion (input options are values). */
13314
13337
  function branchParents(name, macros) {
13315
- if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => parent !== "listbox");
13316
- return effectiveNamedDefinitions(macros).filter((macro) => macro.name.toLowerCase() !== "listbox" && macro.subMacros.some((sub) => sub.toLowerCase() === name.toLowerCase())).map((macro) => macro.name.toLowerCase());
13338
+ if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => parent !== "listbox" && parent !== "cycle");
13339
+ return effectiveNamedDefinitions(macros).filter((macro) => macro.name.toLowerCase() !== "listbox" && macro.name.toLowerCase() !== "cycle" && macro.subMacros.some((sub) => sub.toLowerCase() === name.toLowerCase())).map((macro) => macro.name.toLowerCase());
13317
13340
  }
13318
13341
  /** The declared parameters of the macro `name`, if it declares any. */
13319
13342
  function getMacroParameters(name) {
@@ -13505,6 +13528,8 @@ function sourcePositions(text) {
13505
13528
  * runtime reads it, or, when it matches one further out, closes that one and
13506
13529
  * what was open inside it stays unclosed.
13507
13530
  */
13531
+ /** Keep AST construction and recursive rendering within a safe call depth. */
13532
+ var MAX_MARKUP_DEPTH = 256;
13508
13533
  /** The last of `items`. */
13509
13534
  var last = (items) => items[items.length - 1];
13510
13535
  /** The macro each branch macro belongs to. */
@@ -13642,6 +13667,10 @@ function pairMarkup(tokens, options = {}) {
13642
13667
  add(node);
13643
13668
  continue;
13644
13669
  }
13670
+ if (stack.length === MAX_MARKUP_DEPTH) report("nesting-limit", token, `Markup nesting exceeds the limit of ${MAX_MARKUP_DEPTH} elements`, token.start, {
13671
+ name: nameOf(token),
13672
+ limit: String(MAX_MARKUP_DEPTH)
13673
+ });
13645
13674
  const body = {
13646
13675
  children: [],
13647
13676
  branches: []
@@ -16513,7 +16542,7 @@ var StructuralContext = createContext(false);
16513
16542
  /**
16514
16543
  * True while rendering inside an element whose content is not markdown: SVG
16515
16544
  * (whose namespace `<p>` wrappers would break) and the preformatted `<pre>`
16516
- * `<textarea>` and `<style>`, whose text (indentation, `#`, `*`, ...) is literal.
16545
+ * `<textarea>`, `<style>` and `<script>`, whose text is literal.
16517
16546
  * Macro and widget bodies read it so their content stays literal too.
16518
16547
  */
16519
16548
  var RawTextContext = createContext(false);
@@ -16560,7 +16589,8 @@ var STRUCTURAL_ELEMENTS = /* @__PURE__ */ new Set([
16560
16589
  var PREFORMATTED_ELEMENTS = /* @__PURE__ */ new Set([
16561
16590
  "pre",
16562
16591
  "textarea",
16563
- "style"
16592
+ "style",
16593
+ "script"
16564
16594
  ]);
16565
16595
  var WidgetChildrenContext = createContext(null);
16566
16596
  function placeholderHtml(nonce, index) {
@@ -17055,7 +17085,7 @@ function HtmlNodeRenderer({ node }) {
17055
17085
  let children = void 0;
17056
17086
  let structural = false;
17057
17087
  if (node.children.length > 0) {
17058
- if (tag === "style") children = node.children.map((n) => n.type === "text" ? n.value : renderSingleNode(n));
17088
+ if (tag === "style" || tag === "script") children = node.children.map((n) => n.type === "text" ? n.value : renderSingleNode(n));
17059
17089
  else if (rawContent || isRawRoot) children = renderInlineNodes(node.children);
17060
17090
  else {
17061
17091
  const leadAt = leadingPartIndex(tag, node.children);
@@ -21084,11 +21114,11 @@ var escapeAttributeReferences = (text) => text.replace(/&/g, "&amp;");
21084
21114
  var escapeTextReferences = (text) => escapeAttributeReferences(text).replace(/</g, "&lt;");
21085
21115
  /**
21086
21116
  * Elements whose text the renderer shows as written, with no character
21087
- * references decoded: the one it treats as raw text (`style`, see
21117
+ * references decoded: those it treats as raw text (`style`, `script`, see
21088
21118
  * HtmlNodeRenderer), for which the browser did not decode any either.
21089
21119
  */
21090
21120
  function isLiteralTextElement(parent) {
21091
- return parent.localName === "style" && parent.namespaceURI === HTML_NAMESPACE;
21121
+ return ["style", "script"].includes(parent.localName) && parent.namespaceURI === HTML_NAMESPACE;
21092
21122
  }
21093
21123
  /**
21094
21124
  * `value` with the text in it escaped by `escape`, but not markup
@@ -21951,9 +21981,7 @@ function warnIfUndeclared(isTransient, key) {
21951
21981
  /** Set a single variable on an Immer draft, resolving dot-paths if present. */
21952
21982
  function setOne(draft, name, value) {
21953
21983
  const { isTransient, key } = parseName(name);
21954
- const namespace = isTransient ? draft.transient : draft.variables;
21955
- if (key.includes(".")) setByPath(namespace, key.split("."), value);
21956
- else namespace[key] = value;
21984
+ setByPath(isTransient ? draft.transient : draft.variables, key.split("."), value);
21957
21985
  }
21958
21986
  /** A method calling the store action `name`, as the store holds it then. */
21959
21987
  function storeAction(name) {
@@ -22852,8 +22880,6 @@ function declarationRegex(sigil) {
22852
22880
  const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
22853
22881
  return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
22854
22882
  }
22855
- /** A `$name` or `%name` reference with its dot path, at a sigil the lexer found. */
22856
- var VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
22857
22883
  var VALID_VAR_TYPES = /* @__PURE__ */ new Set([
22858
22884
  "number",
22859
22885
  "string",
@@ -23092,36 +23118,19 @@ var BUILTIN_STORE_VAR_MACROS = [
23092
23118
  "textbox"
23093
23119
  ];
23094
23120
  var NO_STORE_VAR_MACROS = /* @__PURE__ */ new Set();
23095
- /** A `.field` path written right after a reference, which may be empty. */
23096
- var FIELD_PATH_RE = /(?:\.\w+)*/y;
23097
23121
  /**
23098
23122
  * The reference to variable `name`, which JavaScript reads at `[start, end)`
23099
23123
  * of `code` (the sigil and the name as written, which may be spelled with
23100
23124
  * escapes), with the dot path written after it.
23101
23125
  */
23102
- function referenceAt(code, sigil, name, start, end, at) {
23103
- FIELD_PATH_RE.lastIndex = end;
23104
- const fields = FIELD_PATH_RE.exec(code)[0];
23126
+ function referenceAt(code, { sigil, name, start, end }, at) {
23127
+ const fields = readMemberPath(code, end);
23105
23128
  return {
23106
23129
  sigil,
23107
23130
  name,
23108
- path: fields ? fields.slice(1).split(".") : [],
23131
+ path: fields.path,
23109
23132
  start: at(start),
23110
- end: at(end + fields.length)
23111
- };
23112
- }
23113
- /** A reference written at `index` of `term`, a `variable` parameter as written. */
23114
- function termReferenceAt(term, index, at) {
23115
- VAR_PATH_RE.lastIndex = index;
23116
- const match = VAR_PATH_RE.exec(term);
23117
- if (!match) return void 0;
23118
- const [name, ...path] = match[2].split(".");
23119
- return {
23120
- sigil: match[1],
23121
- name,
23122
- path,
23123
- start: at(index),
23124
- end: at(index + match[0].length)
23133
+ end: at(fields.end)
23125
23134
  };
23126
23135
  }
23127
23136
  /**
@@ -23158,7 +23167,7 @@ function scanCode(code, at, emit, goal = "expression") {
23158
23167
  }
23159
23168
  for (const ref of parsed.refs) {
23160
23169
  if (ref.sigil !== "$" && ref.sigil !== "%") continue;
23161
- emit(referenceAt(code, ref.sigil, ref.name, ref.start, ref.end, at));
23170
+ emit(referenceAt(code, ref, at));
23162
23171
  }
23163
23172
  }
23164
23173
  /** `scanCode` for code acorn can't parse: lexed leniently. */
@@ -23166,7 +23175,12 @@ function scanCodeLeniently(code, at, emit, goal) {
23166
23175
  lexJs(code, {
23167
23176
  variable(sigil, name, index, _nesting, end) {
23168
23177
  if (sigil !== "$" && sigil !== "%") return;
23169
- emit(referenceAt(code, sigil, name, index, end, at));
23178
+ emit(referenceAt(code, {
23179
+ sigil,
23180
+ name,
23181
+ start: index,
23182
+ end
23183
+ }, at));
23170
23184
  },
23171
23185
  literal() {}
23172
23186
  }, goal);
@@ -23195,7 +23209,7 @@ function scanArgs(token, parametersOf, at, emit, options) {
23195
23209
  const params = parametersOf(token.name);
23196
23210
  let byParameters = false;
23197
23211
  if (params) {
23198
- if (options.all && !options.storeVarMacros.has(token.name.toLowerCase())) scanVariableParameters(token, params, at, emit);
23212
+ if (!options.storeVarMacros.has(token.name.toLowerCase())) scanVariableParameters(token, params, at, emit, options.all);
23199
23213
  const pieces = [...argPieces(token.rawArgs, token.argsStart, params, token.name, "")];
23200
23214
  byParameters = !pieces.some((piece) => piece.kind === "argument-error");
23201
23215
  if (byParameters) scanPieces(pieces, at, emit, options);
@@ -23206,10 +23220,10 @@ function scanArgs(token, parametersOf, at, emit, options) {
23206
23220
  }
23207
23221
  /**
23208
23222
  * Report the variables the `variable` parameters of a macro name
23209
- * (`{unset $x}`, `{computed $x = …}`), when they are `$` or `%` variables.
23210
- * Arguments that do not parse hold none.
23223
+ * (`{unset $x}`, `{computed $x = …}`). Computed members read variables even
23224
+ * when the receiver itself is only included in the complete editor list.
23211
23225
  */
23212
- function scanVariableParameters(token, params, at, emit) {
23226
+ function scanVariableParameters(token, params, at, emit, all) {
23213
23227
  const spans = /* @__PURE__ */ new Map();
23214
23228
  try {
23215
23229
  parseMacroArgs(token.rawArgs, params, spans);
@@ -23220,8 +23234,10 @@ function scanVariableParameters(token, params, at, emit) {
23220
23234
  for (const param of params) {
23221
23235
  const span = spans.get(param);
23222
23236
  if (param.type !== "variable" || !span) continue;
23223
- const ref = termReferenceAt(token.rawArgs.slice(span[0], span[1]), 0, (i) => at(token.argsStart + span[0] + i));
23224
- if (ref) emit(ref);
23237
+ const start = token.argsStart + span[0];
23238
+ scanCode(token.rawArgs.slice(span[0], span[1]), (i) => at(start + i), (ref) => {
23239
+ if (all || ref.start !== at(start)) emit(ref);
23240
+ });
23225
23241
  }
23226
23242
  }
23227
23243
  /** Report the references in the selectors of a token, which are interpolated. */
@@ -24229,10 +24245,11 @@ var UNSET = Symbol("unset");
24229
24245
  function assignmentArgs(rawArgs, args) {
24230
24246
  if (!args["="]) throw new Error(`{computed}: expected "target = expression", got "${rawArgs}"`);
24231
24247
  const { target = "", expression: expr = "" } = args;
24232
- if (!target.match(/^[$_@]\w+$/)) throw new Error(`{computed}: target must be $name, _name, or @name, got "${target}"`);
24233
- checkVariableName(target.slice(1), target);
24248
+ const path = parseReferencePath(target);
24249
+ if (!path || path.nested || path.sigil === "%") throw new Error(`{computed}: target must be $name, _name, or @name, got "${target}"`);
24250
+ checkVariableName(path.name, target);
24234
24251
  return {
24235
- target,
24252
+ target: path.sigil + path.name,
24236
24253
  expr
24237
24254
  };
24238
24255
  }
@@ -26014,6 +26031,7 @@ defineMacro({
26014
26031
  defineMacro({
26015
26032
  name: "cycle",
26016
26033
  block: true,
26034
+ subMacros: ["option"],
26017
26035
  interpolate: true,
26018
26036
  storeVar: true,
26019
26037
  parameters: [VARIABLE_PARAMETER],
@@ -503,7 +503,9 @@ export default [
503
503
  {
504
504
  "name": "cycle",
505
505
  "block": true,
506
- "subMacros": [],
506
+ "subMacros": [
507
+ "option"
508
+ ],
507
509
  "storeVar": true,
508
510
  "interpolate": true,
509
511
  "parameters": [
@@ -503,7 +503,9 @@
503
503
  {
504
504
  "name": "cycle",
505
505
  "block": true,
506
- "subMacros": [],
506
+ "subMacros": [
507
+ "option"
508
+ ],
507
509
  "storeVar": true,
508
510
  "interpolate": true,
509
511
  "parameters": [
@@ -3715,10 +3715,10 @@ function parameterError(macro, param, problem, fix) {
3715
3715
  var metadataRegistry = new NameMap();
3716
3716
  /** Indexed at registration, so parsing each tag does not scan every macro. */
3717
3717
  var companionParents = new NameMap();
3718
- /** The parents declaring a branching companion (listbox options are values). */
3718
+ /** The parents declaring a branching companion (input options are values). */
3719
3719
  function branchParents(name, macros) {
3720
- if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => parent !== "listbox");
3721
- return effectiveNamedDefinitions(macros).filter((macro) => macro.name.toLowerCase() !== "listbox" && macro.subMacros.some((sub) => sub.toLowerCase() === name.toLowerCase())).map((macro) => macro.name.toLowerCase());
3720
+ if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => parent !== "listbox" && parent !== "cycle");
3721
+ return effectiveNamedDefinitions(macros).filter((macro) => macro.name.toLowerCase() !== "listbox" && macro.name.toLowerCase() !== "cycle" && macro.subMacros.some((sub) => sub.toLowerCase() === name.toLowerCase())).map((macro) => macro.name.toLowerCase());
3722
3722
  }
3723
3723
  /** The declared parameters of the macro `name`, if it declares any. */
3724
3724
  function getMacroParameters(name) {
@@ -3894,6 +3894,8 @@ function sourcePositions(text) {
3894
3894
  * runtime reads it, or, when it matches one further out, closes that one and
3895
3895
  * what was open inside it stays unclosed.
3896
3896
  */
3897
+ /** Keep AST construction and recursive rendering within a safe call depth. */
3898
+ var MAX_MARKUP_DEPTH = 256;
3897
3899
  /** The last of `items`. */
3898
3900
  var last$1 = (items) => items[items.length - 1];
3899
3901
  /** The macro each branch macro belongs to. */
@@ -4031,6 +4033,10 @@ function pairMarkup(tokens, options = {}) {
4031
4033
  add(node);
4032
4034
  continue;
4033
4035
  }
4036
+ if (stack.length === MAX_MARKUP_DEPTH) report("nesting-limit", token, `Markup nesting exceeds the limit of ${MAX_MARKUP_DEPTH} elements`, token.start, {
4037
+ name: nameOf(token),
4038
+ limit: String(MAX_MARKUP_DEPTH)
4039
+ });
4034
4040
  const body = {
4035
4041
  children: [],
4036
4042
  branches: []
@@ -9616,6 +9622,29 @@ function parseMemberIdentifier(src) {
9616
9622
  if (object.type !== "Identifier" || object.start !== 0 || object.end !== 1 || property.type !== "Identifier" || property.start !== 2 || property.end !== src.length + 2) return null;
9617
9623
  return property.name;
9618
9624
  }
9625
+ /** Read the contiguous dot members after a variable, keeping decoded names. */
9626
+ function readMemberPath(src, end) {
9627
+ const path = [];
9628
+ const p = tokenizerAt(src, end, "expression", { afterOperand: true });
9629
+ try {
9630
+ for (;;) {
9631
+ p.nextToken();
9632
+ if (p.type !== types$1.dot || p.start !== end) break;
9633
+ const dotEnd = p.end;
9634
+ p.nextToken();
9635
+ if (p.start !== dotEnd || p.type !== types$1.name && !p.type.keyword) break;
9636
+ if (!/^\w+$/.test(String(p.value))) break;
9637
+ path.push(String(p.value));
9638
+ end = p.end;
9639
+ }
9640
+ } catch (error) {
9641
+ if (!(error instanceof SyntaxError)) throw error;
9642
+ }
9643
+ return {
9644
+ path,
9645
+ end
9646
+ };
9647
+ }
9619
9648
  /**
9620
9649
  * Parse `src` as `goal`, reading `%` as `percentAt` says where it says, and
9621
9650
  * noting where it read a transient in `transientsRead`.
@@ -12812,8 +12841,6 @@ function declarationRegex(sigil) {
12812
12841
  const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
12813
12842
  return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
12814
12843
  }
12815
- /** A `$name` or `%name` reference with its dot path, at a sigil the lexer found. */
12816
- var VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
12817
12844
  var VALID_VAR_TYPES = /* @__PURE__ */ new Set([
12818
12845
  "number",
12819
12846
  "string",
@@ -13039,36 +13066,19 @@ function checkReference(ref, declared) {
13039
13066
  return null;
13040
13067
  }
13041
13068
  var NO_STORE_VAR_MACROS = /* @__PURE__ */ new Set();
13042
- /** A `.field` path written right after a reference, which may be empty. */
13043
- var FIELD_PATH_RE = /(?:\.\w+)*/y;
13044
13069
  /**
13045
13070
  * The reference to variable `name`, which JavaScript reads at `[start, end)`
13046
13071
  * of `code` (the sigil and the name as written, which may be spelled with
13047
13072
  * escapes), with the dot path written after it.
13048
13073
  */
13049
- function referenceAt(code, sigil, name, start, end, at) {
13050
- FIELD_PATH_RE.lastIndex = end;
13051
- const fields = FIELD_PATH_RE.exec(code)[0];
13074
+ function referenceAt(code, { sigil, name, start, end }, at) {
13075
+ const fields = readMemberPath(code, end);
13052
13076
  return {
13053
13077
  sigil,
13054
13078
  name,
13055
- path: fields ? fields.slice(1).split(".") : [],
13079
+ path: fields.path,
13056
13080
  start: at(start),
13057
- end: at(end + fields.length)
13058
- };
13059
- }
13060
- /** A reference written at `index` of `term`, a `variable` parameter as written. */
13061
- function termReferenceAt(term, index, at) {
13062
- VAR_PATH_RE.lastIndex = index;
13063
- const match = VAR_PATH_RE.exec(term);
13064
- if (!match) return void 0;
13065
- const [name, ...path] = match[2].split(".");
13066
- return {
13067
- sigil: match[1],
13068
- name,
13069
- path,
13070
- start: at(index),
13071
- end: at(index + match[0].length)
13081
+ end: at(fields.end)
13072
13082
  };
13073
13083
  }
13074
13084
  /**
@@ -13105,7 +13115,7 @@ function scanCode(code, at, emit, goal = "expression") {
13105
13115
  }
13106
13116
  for (const ref of parsed.refs) {
13107
13117
  if (ref.sigil !== "$" && ref.sigil !== "%") continue;
13108
- emit(referenceAt(code, ref.sigil, ref.name, ref.start, ref.end, at));
13118
+ emit(referenceAt(code, ref, at));
13109
13119
  }
13110
13120
  }
13111
13121
  /** `scanCode` for code acorn can't parse: lexed leniently. */
@@ -13113,7 +13123,12 @@ function scanCodeLeniently(code, at, emit, goal) {
13113
13123
  lexJs(code, {
13114
13124
  variable(sigil, name, index, _nesting, end) {
13115
13125
  if (sigil !== "$" && sigil !== "%") return;
13116
- emit(referenceAt(code, sigil, name, index, end, at));
13126
+ emit(referenceAt(code, {
13127
+ sigil,
13128
+ name,
13129
+ start: index,
13130
+ end
13131
+ }, at));
13117
13132
  },
13118
13133
  literal() {}
13119
13134
  }, goal);
@@ -13142,7 +13157,7 @@ function scanArgs(token, parametersOf, at, emit, options) {
13142
13157
  const params = parametersOf(token.name);
13143
13158
  let byParameters = false;
13144
13159
  if (params) {
13145
- if (options.all && !options.storeVarMacros.has(token.name.toLowerCase())) scanVariableParameters(token, params, at, emit);
13160
+ if (!options.storeVarMacros.has(token.name.toLowerCase())) scanVariableParameters(token, params, at, emit, options.all);
13146
13161
  const pieces = [...argPieces(token.rawArgs, token.argsStart, params, token.name, "")];
13147
13162
  byParameters = !pieces.some((piece) => piece.kind === "argument-error");
13148
13163
  if (byParameters) scanPieces(pieces, at, emit, options);
@@ -13153,10 +13168,10 @@ function scanArgs(token, parametersOf, at, emit, options) {
13153
13168
  }
13154
13169
  /**
13155
13170
  * Report the variables the `variable` parameters of a macro name
13156
- * (`{unset $x}`, `{computed $x = …}`), when they are `$` or `%` variables.
13157
- * Arguments that do not parse hold none.
13171
+ * (`{unset $x}`, `{computed $x = …}`). Computed members read variables even
13172
+ * when the receiver itself is only included in the complete editor list.
13158
13173
  */
13159
- function scanVariableParameters(token, params, at, emit) {
13174
+ function scanVariableParameters(token, params, at, emit, all) {
13160
13175
  const spans = /* @__PURE__ */ new Map();
13161
13176
  try {
13162
13177
  parseMacroArgs(token.rawArgs, params, spans);
@@ -13167,8 +13182,10 @@ function scanVariableParameters(token, params, at, emit) {
13167
13182
  for (const param of params) {
13168
13183
  const span = spans.get(param);
13169
13184
  if (param.type !== "variable" || !span) continue;
13170
- const ref = termReferenceAt(token.rawArgs.slice(span[0], span[1]), 0, (i) => at(token.argsStart + span[0] + i));
13171
- if (ref) emit(ref);
13185
+ const start = token.argsStart + span[0];
13186
+ scanCode(token.rawArgs.slice(span[0], span[1]), (i) => at(start + i), (ref) => {
13187
+ if (all || ref.start !== at(start)) emit(ref);
13188
+ });
13172
13189
  }
13173
13190
  }
13174
13191
  /** Report the references in the selectors of a token, which are interpolated. */
@@ -25393,7 +25410,7 @@ async function formatLf(text, options) {
25393
25410
  }
25394
25411
  if (region.type === "html") {
25395
25412
  const htmlText = region.lines.join("\n");
25396
- if (WHITESPACE_AS_WRITTEN.test(htmlText) || region.lines.some((line) => literalLines.has(line.trim()))) {
25413
+ if (WHITESPACE_AS_WRITTEN.test(htmlText) || region.lines.some((line) => literalLines.has(line.trim())) || hasMarkdownBoundaries(htmlText, isBlock)) {
25397
25414
  for (let i = 0; i < region.lines.length; i++) preservedLines.add(lines.length + i);
25398
25415
  lines.push(...region.lines);
25399
25416
  continue;
@@ -25426,6 +25443,30 @@ async function formatLf(text, options) {
25426
25443
  }
25427
25444
  /** Literal HTML and opaque SVG, whose text can inherit significant whitespace. */
25428
25445
  var WHITESPACE_AS_WRITTEN = /<(?:pre|textarea|svg)[\s>]|white-space\s*:/i;
25446
+ /** HTML whitespace formatting must not collapse the Markdown in its bodies. */
25447
+ var HTML_MARKDOWN_BOUNDARIES = /* @__PURE__ */ new Set([
25448
+ "hardBreakTrailing",
25449
+ "hardBreakEscape",
25450
+ "atxHeading",
25451
+ "setextHeading",
25452
+ "listOrdered",
25453
+ "listUnordered",
25454
+ "blockQuote",
25455
+ "thematicBreak",
25456
+ "definition",
25457
+ "table",
25458
+ "codeFenced"
25459
+ ]);
25460
+ function hasMarkdownBoundaries(source, isBlock) {
25461
+ const { tokens } = analyzeMarkup(source, { hooks: { isBlock } });
25462
+ let possibleBoundary = false;
25463
+ for (const token of tokens) {
25464
+ if (token.type !== "text") continue;
25465
+ if (/\n[ \t]*\n/.test(token.value)) return true;
25466
+ if (/[\\#*+\d=>[`~|-]|[ \t]\n/.test(token.value)) possibleBoundary = true;
25467
+ }
25468
+ return possibleBoundary && markdownLines(source, isBlock, HTML_MARKDOWN_BOUNDARIES).size > 0;
25469
+ }
25429
25470
  /** Preserve whole literal elements, including openers beside nested tags. */
25430
25471
  function whitespaceSensitiveLines(source, isBlock) {
25431
25472
  const lines = /* @__PURE__ */ new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.62.8",
3
+ "version": "0.62.9",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -1,5 +1,6 @@
1
1
  import { useStoryStore } from '../../store';
2
2
  import { evaluate } from '../../expression';
3
+ import { parseReferencePath } from '../../js-lexer';
3
4
  import { readState } from '../../execute-mutation';
4
5
  import { deepEqualStrict } from '../../structural';
5
6
  import { defineMacro } from '../../define-macro';
@@ -27,14 +28,15 @@ function assignmentArgs(
27
28
  }
28
29
 
29
30
  const { target = '', expression: expr = '' } = args;
30
- if (!target.match(/^[$_@]\w+$/)) {
31
+ const path = parseReferencePath(target);
32
+ if (!path || path.nested || path.sigil === '%') {
31
33
  throw new Error(
32
34
  `{computed}: target must be $name, _name, or @name, got "${target}"`,
33
35
  );
34
36
  }
35
37
 
36
- checkVariableName(target.slice(1), target);
37
- return { target, expr };
38
+ checkVariableName(path.name, target);
39
+ return { target: path.sigil + path.name, expr };
38
40
  }
39
41
 
40
42
  /**
@@ -5,6 +5,7 @@ import { VARIABLE_PARAMETER, useVariableAction } from './input-macro';
5
5
  defineMacro({
6
6
  name: 'cycle',
7
7
  block: true,
8
+ subMacros: ['option'],
8
9
  interpolate: true,
9
10
  storeVar: true,
10
11
  parameters: [VARIABLE_PARAMETER],
@@ -288,7 +288,8 @@ async function formatLf(
288
288
  // Prettier cannot see a `white-space` style. Leave such HTML as written.
289
289
  if (
290
290
  WHITESPACE_AS_WRITTEN.test(htmlText) ||
291
- region.lines.some((line) => literalLines.has(line.trim()))
291
+ region.lines.some((line) => literalLines.has(line.trim())) ||
292
+ hasMarkdownBoundaries(htmlText, isBlock)
292
293
  ) {
293
294
  for (let i = 0; i < region.lines.length; i++)
294
295
  preservedLines.add(lines.length + i);
@@ -378,6 +379,41 @@ async function formatLf(
378
379
  /** Literal HTML and opaque SVG, whose text can inherit significant whitespace. */
379
380
  const WHITESPACE_AS_WRITTEN = /<(?:pre|textarea|svg)[\s>]|white-space\s*:/i;
380
381
 
382
+ /** HTML whitespace formatting must not collapse the Markdown in its bodies. */
383
+ const HTML_MARKDOWN_BOUNDARIES = new Set([
384
+ 'hardBreakTrailing',
385
+ 'hardBreakEscape',
386
+ 'atxHeading',
387
+ 'setextHeading',
388
+ 'listOrdered',
389
+ 'listUnordered',
390
+ 'blockQuote',
391
+ 'thematicBreak',
392
+ 'definition',
393
+ 'table',
394
+ 'codeFenced',
395
+ ]);
396
+
397
+ function hasMarkdownBoundaries(
398
+ source: string,
399
+ isBlock: (name: string) => boolean,
400
+ ): boolean {
401
+ const { tokens } = analyzeMarkup(source, { hooks: { isBlock } });
402
+ let possibleBoundary = false;
403
+ for (const token of tokens) {
404
+ if (token.type !== 'text') continue;
405
+ if (/\n[ \t]*\n/.test(token.value)) return true;
406
+ // Non-text nodes become inline spans in Markdown. Without punctuation
407
+ // for a block construct or a hard break, their surrounding text cannot
408
+ // create a boundary. Avoid parsing thousands of placeholder-only bodies.
409
+ if (/[\\#*+\d=>[`~|-]|[ \t]\n/.test(token.value)) possibleBoundary = true;
410
+ }
411
+ return (
412
+ possibleBoundary &&
413
+ markdownLines(source, isBlock, HTML_MARKDOWN_BOUNDARIES).size > 0
414
+ );
415
+ }
416
+
381
417
  /** Preserve whole literal elements, including openers beside nested tags. */
382
418
  function whitespaceSensitiveLines(
383
419
  source: string,
package/src/js-lexer.ts CHANGED
@@ -607,6 +607,32 @@ export function parseMemberIdentifier(src: string): string | null {
607
607
  return property.name as string;
608
608
  }
609
609
 
610
+ /** Read the contiguous dot members after a variable, keeping decoded names. */
611
+ export function readMemberPath(
612
+ src: string,
613
+ end: number,
614
+ ): { path: string[]; end: number } {
615
+ const path: string[] = [];
616
+ const p = tokenizerAt(src, end, 'expression', { afterOperand: true });
617
+ try {
618
+ for (;;) {
619
+ p.nextToken();
620
+ if (p.type !== tt.dot || p.start !== end) break;
621
+ const dotEnd = p.end;
622
+ p.nextToken();
623
+ if (p.start !== dotEnd || (p.type !== tt.name && !p.type.keyword)) break;
624
+ // Field schemas cover the runtime's word-character path names.
625
+ if (!/^\w+$/.test(String(p.value))) break;
626
+ path.push(String(p.value));
627
+ end = p.end;
628
+ }
629
+ } catch (error) {
630
+ // Reference collection also reads incomplete authoring input.
631
+ if (!(error instanceof SyntaxError)) throw error;
632
+ }
633
+ return { path, end };
634
+ }
635
+
610
636
  /**
611
637
  * Parse `src` as `goal`, reading `%` as `percentAt` says where it says, and
612
638
  * noting where it read a transient in `transientsRead`.
@@ -17,7 +17,14 @@ import type { HtmlToken, MacroToken, Span, Token } from './tokens';
17
17
 
18
18
  /** What is wrong with the pairing, by kind. */
19
19
  export type PairingErrorCode =
20
- 'unclosed-block' | 'mismatched-closer' | 'stray-closer' | 'misplaced-branch';
20
+ | 'unclosed-block'
21
+ | 'mismatched-closer'
22
+ | 'stray-closer'
23
+ | 'misplaced-branch'
24
+ | 'nesting-limit';
25
+
26
+ /** Keep AST construction and recursive rendering within a safe call depth. */
27
+ const MAX_MARKUP_DEPTH = 256;
21
28
 
22
29
  /**
23
30
  * A problem in the pairing of the tokens, at the token from `start` up to
@@ -322,6 +329,18 @@ export function pairMarkup(
322
329
  add(node);
323
330
  continue;
324
331
  }
332
+ if (stack.length === MAX_MARKUP_DEPTH) {
333
+ report(
334
+ 'nesting-limit',
335
+ token,
336
+ `Markup nesting exceeds the limit of ${MAX_MARKUP_DEPTH} elements`,
337
+ token.start,
338
+ {
339
+ name: nameOf(token as MacroToken | HtmlToken),
340
+ limit: String(MAX_MARKUP_DEPTH),
341
+ },
342
+ );
343
+ }
325
344
  const body: PairedBody = { children: [], branches: [] };
326
345
  node.body = body;
327
346
  const key = tagKey(token as MacroToken | HtmlToken);
@@ -62,7 +62,7 @@ export const StructuralContext = createContext(false);
62
62
  /**
63
63
  * True while rendering inside an element whose content is not markdown: SVG
64
64
  * (whose namespace `<p>` wrappers would break) and the preformatted `<pre>`
65
- * `<textarea>` and `<style>`, whose text (indentation, `#`, `*`, ...) is literal.
65
+ * `<textarea>`, `<style>` and `<script>`, whose text is literal.
66
66
  * Macro and widget bodies read it so their content stays literal too.
67
67
  */
68
68
  export const RawTextContext = createContext(false);
@@ -113,7 +113,7 @@ const STRUCTURAL_ELEMENTS = new Set([
113
113
  ]);
114
114
 
115
115
  /** Elements whose content is literal text, not markdown. */
116
- const PREFORMATTED_ELEMENTS = new Set(['pre', 'textarea', 'style']);
116
+ const PREFORMATTED_ELEMENTS = new Set(['pre', 'textarea', 'style', 'script']);
117
117
  export const WidgetChildrenContext = createContext<WidgetChildren | null>(null);
118
118
 
119
119
  /**
@@ -774,8 +774,8 @@ function HtmlNodeRenderer({ node }: { node: HtmlNode }) {
774
774
  let children: preact.ComponentChildren = undefined;
775
775
  let structural = false;
776
776
  if (node.children.length > 0) {
777
- if (tag === 'style') {
778
- // A raw-text element: its CSS keeps character-reference lookalikes
777
+ if (tag === 'style' || tag === 'script') {
778
+ // Raw-text elements keep script text and character-reference lookalikes
779
779
  // (`?a=1&notch=2`) as written (#453)
780
780
  children = node.children.map((n) =>
781
781
  n.type === 'text' ? n.value : renderSingleNode(n),