@rohal12/spindle 0.64.33 → 0.64.34

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.
@@ -5878,13 +5878,13 @@ function parseCode(src, goal = "expression") {
5878
5878
  return parseWithAst(src, goal).out;
5879
5879
  }
5880
5880
  /** What parseCode finds in `src`, and the syntax tree it is in. */
5881
- function parseWithAst(src, goal) {
5881
+ function parseWithAst(src, goal, effects) {
5882
5882
  const ast = parseAst(src, goal);
5883
5883
  const out = {
5884
5884
  refs: [],
5885
5885
  strings: []
5886
5886
  };
5887
- walk(ast, src, out, false, false);
5887
+ walk(ast, src, out, false, false, "read", effects);
5888
5888
  out.refs.sort((a, b) => a.start - b.start);
5889
5889
  return {
5890
5890
  out,
@@ -5982,47 +5982,83 @@ function propertyName(node, src) {
5982
5982
  const c = src.charAt(node.start);
5983
5983
  if (c === "@" || c === "%") throw new CodeSyntaxError(`"${node.name}" can't be a property name`, src, node.start);
5984
5984
  }
5985
+ /** Keep static member keys decoded; an arbitrary computed key stays unknown. */
5986
+ function mutationTarget(node, src) {
5987
+ const path = [];
5988
+ while (node.type === "MemberExpression") {
5989
+ const property = node.property;
5990
+ path.push(!node.computed && property.type === "Identifier" ? property.name : property.type === "Literal" && ["string", "number"].includes(typeof property.value) ? String(property.value) : null);
5991
+ node = node.object;
5992
+ }
5993
+ return {
5994
+ root: node.type === "Identifier" ? sigilOf(node, src) : null,
5995
+ path: path.reverse()
5996
+ };
5997
+ }
5985
5998
  /**
5986
5999
  * Collect the references and string text under `node`. `binding`: the
5987
6000
  * identifiers here are declared (a `let`, a parameter), where a sigil
5988
6001
  * variable can't be. `shorthand`: the node is a shorthand property's value.
5989
6002
  */
5990
- function walk(root, src, out, binding, shorthand, access = "read") {
6003
+ function walk(root, src, out, binding, shorthand, access = "read", effects) {
5991
6004
  const pending = [[
5992
6005
  root,
5993
6006
  binding,
5994
6007
  shorthand,
5995
- access
6008
+ access,
6009
+ false,
6010
+ false
5996
6011
  ]];
5997
6012
  while (pending.length) {
5998
- const [node, bind, short, role] = pending.pop();
6013
+ const [node, bind, short, role, memberObject, escapes] = pending.pop();
5999
6014
  const children = [];
6000
- visit(node, bind, short, role, children);
6015
+ visit(node, bind, short, role, memberObject, escapes, children);
6001
6016
  for (let i = children.length - 1; i >= 0; i--) pending.push(children[i]);
6002
6017
  }
6003
- function visit(node, binding, shorthand, access, children) {
6018
+ function visit(node, binding, shorthand, access, memberObject, escapes, children) {
6004
6019
  if (Array.isArray(node)) {
6005
6020
  for (const n of node) children.push([
6006
6021
  n,
6007
6022
  binding,
6008
6023
  false,
6009
- access
6024
+ access,
6025
+ false,
6026
+ escapes
6010
6027
  ]);
6011
6028
  return;
6012
6029
  }
6013
6030
  if (!isNode(node)) return;
6014
- const sub = (child, bind = false, short = false, role = "read") => {
6031
+ const sub = (child, bind = false, short = false, role = "read", member = false, escape = escapes) => {
6015
6032
  children.push([
6016
6033
  child,
6017
6034
  bind,
6018
6035
  short,
6019
- role
6036
+ role,
6037
+ member,
6038
+ escape
6020
6039
  ]);
6021
6040
  };
6041
+ const uncertain = (reason) => effects?.uncertain.push({
6042
+ start: node.start,
6043
+ end: node.end,
6044
+ reason
6045
+ });
6046
+ if (effects) {
6047
+ if ([
6048
+ "CallExpression",
6049
+ "NewExpression",
6050
+ "TaggedTemplateExpression"
6051
+ ].includes(node.type)) uncertain("call");
6052
+ if (node.type === "WithStatement") uncertain("dynamic-scope");
6053
+ if (escapes && node.type === "ThisExpression") uncertain("escape");
6054
+ }
6022
6055
  switch (node.type) {
6023
6056
  case "Identifier": {
6024
6057
  const sigil = sigilOf(node, src);
6025
- if (!sigil) return;
6058
+ if (!sigil) {
6059
+ if (effects && escapes && !binding && !memberObject && access === "read") uncertain("escape");
6060
+ return;
6061
+ }
6026
6062
  if (binding) throw new CodeSyntaxError(`"${node.name}" is a ${NAMESPACE_NAME[sigil[0]]} variable and can't be declared`, src, node.start);
6027
6063
  out.refs.push({
6028
6064
  sigil: sigil[0],
@@ -6033,6 +6069,19 @@ function walk(root, src, out, binding, shorthand, access = "read") {
6033
6069
  read: access !== "write",
6034
6070
  write: access !== "read"
6035
6071
  });
6072
+ if (effects) {
6073
+ if (access !== "read") effects.mutations.push({
6074
+ start: node.start,
6075
+ end: node.end,
6076
+ target: {
6077
+ sigil: sigil[0],
6078
+ name: sigil[1],
6079
+ path: []
6080
+ },
6081
+ read: access !== "write"
6082
+ });
6083
+ else if (!memberObject) uncertain("escape");
6084
+ }
6036
6085
  return;
6037
6086
  }
6038
6087
  case "Literal":
@@ -6041,8 +6090,29 @@ function walk(root, src, out, binding, shorthand, access = "read") {
6041
6090
  case "TemplateElement":
6042
6091
  out.strings.push(node.value.raw);
6043
6092
  return;
6093
+ case "ChainExpression":
6094
+ sub(node.expression, binding, shorthand, access, memberObject);
6095
+ return;
6044
6096
  case "MemberExpression":
6045
- sub(node.object);
6097
+ if (effects && escapes && !memberObject && access === "read") uncertain("escape");
6098
+ if (effects && !binding && access !== "read") {
6099
+ const { root, path } = mutationTarget(node, src);
6100
+ const target = root ? {
6101
+ sigil: root[0],
6102
+ name: root[1],
6103
+ path
6104
+ } : null;
6105
+ effects.mutations.push({
6106
+ start: node.start,
6107
+ end: node.end,
6108
+ target,
6109
+ read: access !== "write"
6110
+ });
6111
+ if (!target) uncertain("indirect-write");
6112
+ if (path.includes(null)) uncertain("computed-write");
6113
+ if (path.some((key) => key === "prototype" || key === "__proto__")) uncertain("prototype-write");
6114
+ }
6115
+ sub(node.object, false, false, "read", true);
6046
6116
  if (node.computed) sub(node.property);
6047
6117
  else propertyName(node.property, src);
6048
6118
  return;
@@ -6053,7 +6123,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
6053
6123
  const value = node.value;
6054
6124
  if (value.type === "AssignmentPattern") {
6055
6125
  sub(value.left, binding, true, access);
6056
- sub(value.right);
6126
+ sub(value.right, false, false, "read", false, true);
6057
6127
  } else sub(value, binding, true, access);
6058
6128
  } else sub(node.value, binding, false, access);
6059
6129
  return;
@@ -6061,7 +6131,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
6061
6131
  case "PropertyDefinition":
6062
6132
  if (node.computed) sub(node.key);
6063
6133
  else propertyName(node.key, src);
6064
- sub(node.value);
6134
+ sub(node.value, false, false, "read", false, node.type === "PropertyDefinition" || escapes);
6065
6135
  return;
6066
6136
  case "LabeledStatement":
6067
6137
  sub(node.body);
@@ -6072,7 +6142,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
6072
6142
  case "PrivateIdentifier": return;
6073
6143
  case "VariableDeclarator":
6074
6144
  sub(node.id, true);
6075
- sub(node.init);
6145
+ sub(node.init, false, false, "read", false, true);
6076
6146
  return;
6077
6147
  case "FunctionDeclaration":
6078
6148
  case "FunctionExpression":
@@ -6093,7 +6163,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
6093
6163
  return;
6094
6164
  case "AssignmentExpression":
6095
6165
  sub(node.left, false, false, node.operator === "=" ? "write" : "readwrite");
6096
- sub(node.right);
6166
+ sub(node.right, false, false, "read", false, true);
6167
+ return;
6168
+ case "ReturnStatement":
6169
+ case "ThrowStatement":
6170
+ case "YieldExpression":
6171
+ sub(node.argument, false, false, "read", false, true);
6097
6172
  return;
6098
6173
  case "UnaryExpression":
6099
6174
  sub(node.argument, false, false, node.operator === "delete" ? "write" : "read");
@@ -6104,12 +6179,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
6104
6179
  case "ForInStatement":
6105
6180
  case "ForOfStatement":
6106
6181
  sub(node.left, false, false, "write");
6107
- sub(node.right);
6182
+ sub(node.right, false, false, "read", false, true);
6108
6183
  sub(node.body);
6109
6184
  return;
6110
6185
  case "AssignmentPattern":
6111
6186
  sub(node.left, binding, false, access);
6112
- sub(node.right);
6187
+ sub(node.right, false, false, "read", false, true);
6113
6188
  return;
6114
6189
  case "ObjectPattern":
6115
6190
  case "ArrayPattern":
@@ -19810,9 +19885,9 @@ function withEdits(edits, run) {
19810
19885
  activeEdits = previous;
19811
19886
  }
19812
19887
  }
19813
- /** Attribute only the control's own writes, before subscribers can replace them. */
19814
- function runAsControlEdit(segments, run) {
19815
- withEdits([["variables", ...segments]], run);
19888
+ /** Attribute every binding of an atomic form reset to its own path. */
19889
+ function runAsControlEdits(paths, run) {
19890
+ withEdits(paths.map((segments) => ["variables", ...segments]), run);
19816
19891
  }
19817
19892
  /** Whether mutation code runs inside a {for} iteration. */
19818
19893
  var ItemEditContext = createContext(false);
@@ -22138,6 +22213,39 @@ var settings = {
22138
22213
  function collectText(nodes) {
22139
22214
  return nodes.map((n) => n.type === "text" ? n.value : "").join("");
22140
22215
  }
22216
+ // src/utils/control-bindings.ts
22217
+ var pending;
22218
+ /** Commit related bindings together, preserving references and item edits. */
22219
+ function commit(writes) {
22220
+ if (!writes.length) return;
22221
+ runAsControlEdits(writes.map(({ segments }) => segments), () => {
22222
+ mutateState((work, adopt) => {
22223
+ for (const { segments, value } of writes) setByPath(work.variables, segments, adopt(value), { createMissing: true });
22224
+ });
22225
+ });
22226
+ }
22227
+ /** A control write, or one part of the form reset currently being collected. */
22228
+ function setControlValue(segments, value) {
22229
+ notifyVariableWrite(segments);
22230
+ const write = {
22231
+ segments,
22232
+ value
22233
+ };
22234
+ if (pending) pending.push(write);
22235
+ else commit([write]);
22236
+ }
22237
+ /** Subscribers see the complete reset, never a partially reset form. */
22238
+ function batchControlValues(run) {
22239
+ if (pending) return run();
22240
+ const writes = [];
22241
+ pending = writes;
22242
+ try {
22243
+ run();
22244
+ } finally {
22245
+ pending = void 0;
22246
+ }
22247
+ commit(writes);
22248
+ }
22141
22249
  // src/define-macro.ts
22142
22250
  function macroClass(type, className) {
22143
22251
  const base = `macro-${type}`;
@@ -22231,14 +22339,7 @@ function defineMacro(config, source = "builtin") {
22231
22339
  ctx.varName = segments.join(".");
22232
22340
  ctx.value = getByPath(useStoryFields("variables").variables, segments);
22233
22341
  ctx.getValue = () => getByPath(readState().variables, segments);
22234
- ctx.setValue = displayOnly ? refuse : (value) => {
22235
- notifyVariableWrite(segments);
22236
- runAsControlEdit(segments, () => {
22237
- mutateState((work, adopt) => {
22238
- setByPath(work.variables, segments, adopt(value), { createMissing: true });
22239
- });
22240
- });
22241
- };
22342
+ ctx.setValue = displayOnly ? refuse : (value) => setControlValue(segments, value);
22242
22343
  }
22243
22344
  try {
22244
22345
  return entryRender?.pending ? duringEntryRender(() => config.render(props, ctx)) : duringMacroRender(() => config.render(props, ctx));
@@ -26382,7 +26483,7 @@ function SaveManagerContent({ className, id }) {
26382
26483
  });
26383
26484
  statusTimer.current = window.setTimeout(() => setStatus(null), 3e3);
26384
26485
  };
26385
- useEffect(() => {
26486
+ useLayoutEffect(() => {
26386
26487
  mounted.current = true;
26387
26488
  return () => {
26388
26489
  mounted.current = false;
@@ -26456,7 +26557,12 @@ function SaveManagerContent({ className, id }) {
26456
26557
  if (isStateReplacementSuperseded(replacement)) return;
26457
26558
  loadFromPayload(decodeSavePayload(current.payload), void 0, current.meta.playthroughId, replacement);
26458
26559
  showStatus("Game loaded");
26459
- if (closeDialog) closeTimer.current = window.setTimeout(closeDialog, 500);
26560
+ if (closeDialog && mounted.current) {
26561
+ clearTimeout(closeTimer.current);
26562
+ closeTimer.current = window.setTimeout(() => {
26563
+ if (mounted.current) closeDialog();
26564
+ }, 500);
26565
+ }
26460
26566
  await refresh();
26461
26567
  } catch {
26462
26568
  showStatus("Failed to load save", "error");
@@ -26964,7 +27070,9 @@ function subscribeFormReset(form, read) {
26964
27070
  });
26965
27071
  restoreDefaults();
26966
27072
  const commits = controls.map(({ read, element }) => read(element));
26967
- for (const commit of commits) commit();
27073
+ batchControlValues(() => {
27074
+ for (const commit of commits) commit();
27075
+ });
26968
27076
  }, 0);
26969
27077
  };
26970
27078
  subscription = {
@@ -9686,6 +9686,21 @@ function bracketsBefore(src, pos) {
9686
9686
  };
9687
9687
  }
9688
9688
  /**
9689
+ * Conservative shape effects, using the same grammar and target roles as
9690
+ * parseCode. Includes nested functions and unreachable branches; does not
9691
+ * attempt alias, call, control-flow or execution-order analysis.
9692
+ */
9693
+ function analyzeCodeEffects(src, goal = "expression") {
9694
+ const effects = {
9695
+ mutations: [],
9696
+ uncertain: []
9697
+ };
9698
+ parseWithAst(src, goal, effects);
9699
+ effects.mutations.sort((a, b) => a.start - b.start);
9700
+ effects.uncertain.sort((a, b) => a.start - b.start);
9701
+ return effects;
9702
+ }
9703
+ /**
9689
9704
  * Parse `src` as `goal`, and find its variable references and string text.
9690
9705
  * Throws a `CodeSyntaxError` for code that is not well-formed, and for a
9691
9706
  * sigil variable declared (`let _x`) or used as a property name (`a.@x`).
@@ -9694,13 +9709,13 @@ function parseCode(src, goal = "expression") {
9694
9709
  return parseWithAst(src, goal).out;
9695
9710
  }
9696
9711
  /** What parseCode finds in `src`, and the syntax tree it is in. */
9697
- function parseWithAst(src, goal) {
9712
+ function parseWithAst(src, goal, effects) {
9698
9713
  const ast = parseAst(src, goal);
9699
9714
  const out = {
9700
9715
  refs: [],
9701
9716
  strings: []
9702
9717
  };
9703
- walk(ast, src, out, false, false);
9718
+ walk(ast, src, out, false, false, "read", effects);
9704
9719
  out.refs.sort((a, b) => a.start - b.start);
9705
9720
  return {
9706
9721
  out,
@@ -9798,47 +9813,83 @@ function propertyName(node, src) {
9798
9813
  const c = src.charAt(node.start);
9799
9814
  if (c === "@" || c === "%") throw new CodeSyntaxError(`"${node.name}" can't be a property name`, src, node.start);
9800
9815
  }
9816
+ /** Keep static member keys decoded; an arbitrary computed key stays unknown. */
9817
+ function mutationTarget(node, src) {
9818
+ const path = [];
9819
+ while (node.type === "MemberExpression") {
9820
+ const property = node.property;
9821
+ path.push(!node.computed && property.type === "Identifier" ? property.name : property.type === "Literal" && ["string", "number"].includes(typeof property.value) ? String(property.value) : null);
9822
+ node = node.object;
9823
+ }
9824
+ return {
9825
+ root: node.type === "Identifier" ? sigilOf(node, src) : null,
9826
+ path: path.reverse()
9827
+ };
9828
+ }
9801
9829
  /**
9802
9830
  * Collect the references and string text under `node`. `binding`: the
9803
9831
  * identifiers here are declared (a `let`, a parameter), where a sigil
9804
9832
  * variable can't be. `shorthand`: the node is a shorthand property's value.
9805
9833
  */
9806
- function walk(root, src, out, binding, shorthand, access = "read") {
9834
+ function walk(root, src, out, binding, shorthand, access = "read", effects) {
9807
9835
  const pending = [[
9808
9836
  root,
9809
9837
  binding,
9810
9838
  shorthand,
9811
- access
9839
+ access,
9840
+ false,
9841
+ false
9812
9842
  ]];
9813
9843
  while (pending.length) {
9814
- const [node, bind, short, role] = pending.pop();
9844
+ const [node, bind, short, role, memberObject, escapes] = pending.pop();
9815
9845
  const children = [];
9816
- visit(node, bind, short, role, children);
9846
+ visit(node, bind, short, role, memberObject, escapes, children);
9817
9847
  for (let i = children.length - 1; i >= 0; i--) pending.push(children[i]);
9818
9848
  }
9819
- function visit(node, binding, shorthand, access, children) {
9849
+ function visit(node, binding, shorthand, access, memberObject, escapes, children) {
9820
9850
  if (Array.isArray(node)) {
9821
9851
  for (const n of node) children.push([
9822
9852
  n,
9823
9853
  binding,
9824
9854
  false,
9825
- access
9855
+ access,
9856
+ false,
9857
+ escapes
9826
9858
  ]);
9827
9859
  return;
9828
9860
  }
9829
9861
  if (!isNode(node)) return;
9830
- const sub = (child, bind = false, short = false, role = "read") => {
9862
+ const sub = (child, bind = false, short = false, role = "read", member = false, escape = escapes) => {
9831
9863
  children.push([
9832
9864
  child,
9833
9865
  bind,
9834
9866
  short,
9835
- role
9867
+ role,
9868
+ member,
9869
+ escape
9836
9870
  ]);
9837
9871
  };
9872
+ const uncertain = (reason) => effects?.uncertain.push({
9873
+ start: node.start,
9874
+ end: node.end,
9875
+ reason
9876
+ });
9877
+ if (effects) {
9878
+ if ([
9879
+ "CallExpression",
9880
+ "NewExpression",
9881
+ "TaggedTemplateExpression"
9882
+ ].includes(node.type)) uncertain("call");
9883
+ if (node.type === "WithStatement") uncertain("dynamic-scope");
9884
+ if (escapes && node.type === "ThisExpression") uncertain("escape");
9885
+ }
9838
9886
  switch (node.type) {
9839
9887
  case "Identifier": {
9840
9888
  const sigil = sigilOf(node, src);
9841
- if (!sigil) return;
9889
+ if (!sigil) {
9890
+ if (effects && escapes && !binding && !memberObject && access === "read") uncertain("escape");
9891
+ return;
9892
+ }
9842
9893
  if (binding) throw new CodeSyntaxError(`"${node.name}" is a ${NAMESPACE_NAME[sigil[0]]} variable and can't be declared`, src, node.start);
9843
9894
  out.refs.push({
9844
9895
  sigil: sigil[0],
@@ -9849,6 +9900,19 @@ function walk(root, src, out, binding, shorthand, access = "read") {
9849
9900
  read: access !== "write",
9850
9901
  write: access !== "read"
9851
9902
  });
9903
+ if (effects) {
9904
+ if (access !== "read") effects.mutations.push({
9905
+ start: node.start,
9906
+ end: node.end,
9907
+ target: {
9908
+ sigil: sigil[0],
9909
+ name: sigil[1],
9910
+ path: []
9911
+ },
9912
+ read: access !== "write"
9913
+ });
9914
+ else if (!memberObject) uncertain("escape");
9915
+ }
9852
9916
  return;
9853
9917
  }
9854
9918
  case "Literal":
@@ -9857,8 +9921,29 @@ function walk(root, src, out, binding, shorthand, access = "read") {
9857
9921
  case "TemplateElement":
9858
9922
  out.strings.push(node.value.raw);
9859
9923
  return;
9924
+ case "ChainExpression":
9925
+ sub(node.expression, binding, shorthand, access, memberObject);
9926
+ return;
9860
9927
  case "MemberExpression":
9861
- sub(node.object);
9928
+ if (effects && escapes && !memberObject && access === "read") uncertain("escape");
9929
+ if (effects && !binding && access !== "read") {
9930
+ const { root, path } = mutationTarget(node, src);
9931
+ const target = root ? {
9932
+ sigil: root[0],
9933
+ name: root[1],
9934
+ path
9935
+ } : null;
9936
+ effects.mutations.push({
9937
+ start: node.start,
9938
+ end: node.end,
9939
+ target,
9940
+ read: access !== "write"
9941
+ });
9942
+ if (!target) uncertain("indirect-write");
9943
+ if (path.includes(null)) uncertain("computed-write");
9944
+ if (path.some((key) => key === "prototype" || key === "__proto__")) uncertain("prototype-write");
9945
+ }
9946
+ sub(node.object, false, false, "read", true);
9862
9947
  if (node.computed) sub(node.property);
9863
9948
  else propertyName(node.property, src);
9864
9949
  return;
@@ -9869,7 +9954,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
9869
9954
  const value = node.value;
9870
9955
  if (value.type === "AssignmentPattern") {
9871
9956
  sub(value.left, binding, true, access);
9872
- sub(value.right);
9957
+ sub(value.right, false, false, "read", false, true);
9873
9958
  } else sub(value, binding, true, access);
9874
9959
  } else sub(node.value, binding, false, access);
9875
9960
  return;
@@ -9877,7 +9962,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
9877
9962
  case "PropertyDefinition":
9878
9963
  if (node.computed) sub(node.key);
9879
9964
  else propertyName(node.key, src);
9880
- sub(node.value);
9965
+ sub(node.value, false, false, "read", false, node.type === "PropertyDefinition" || escapes);
9881
9966
  return;
9882
9967
  case "LabeledStatement":
9883
9968
  sub(node.body);
@@ -9888,7 +9973,7 @@ function walk(root, src, out, binding, shorthand, access = "read") {
9888
9973
  case "PrivateIdentifier": return;
9889
9974
  case "VariableDeclarator":
9890
9975
  sub(node.id, true);
9891
- sub(node.init);
9976
+ sub(node.init, false, false, "read", false, true);
9892
9977
  return;
9893
9978
  case "FunctionDeclaration":
9894
9979
  case "FunctionExpression":
@@ -9909,7 +9994,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
9909
9994
  return;
9910
9995
  case "AssignmentExpression":
9911
9996
  sub(node.left, false, false, node.operator === "=" ? "write" : "readwrite");
9912
- sub(node.right);
9997
+ sub(node.right, false, false, "read", false, true);
9998
+ return;
9999
+ case "ReturnStatement":
10000
+ case "ThrowStatement":
10001
+ case "YieldExpression":
10002
+ sub(node.argument, false, false, "read", false, true);
9913
10003
  return;
9914
10004
  case "UnaryExpression":
9915
10005
  sub(node.argument, false, false, node.operator === "delete" ? "write" : "read");
@@ -9920,12 +10010,12 @@ function walk(root, src, out, binding, shorthand, access = "read") {
9920
10010
  case "ForInStatement":
9921
10011
  case "ForOfStatement":
9922
10012
  sub(node.left, false, false, "write");
9923
- sub(node.right);
10013
+ sub(node.right, false, false, "read", false, true);
9924
10014
  sub(node.body);
9925
10015
  return;
9926
10016
  case "AssignmentPattern":
9927
10017
  sub(node.left, binding, false, access);
9928
- sub(node.right);
10018
+ sub(node.right, false, false, "read", false, true);
9929
10019
  return;
9930
10020
  case "ObjectPattern":
9931
10021
  case "ArrayPattern":
@@ -13829,6 +13919,7 @@ var Bindings = class {
13829
13919
  this.byClose = /* @__PURE__ */ new Map();
13830
13920
  this.functions = /* @__PURE__ */ new Map();
13831
13921
  this.functionStarts = /* @__PURE__ */ new Map();
13922
+ this.listKeywords = /* @__PURE__ */ new Map();
13832
13923
  this.facts = /* @__PURE__ */ new Map();
13833
13924
  this.top = {
13834
13925
  start: -1,
@@ -14135,17 +14226,35 @@ var Bindings = class {
14135
14226
  listKeyword(comma) {
14136
14227
  const { code } = this;
14137
14228
  const floor = this.innermost(comma)?.open ?? -1;
14138
- for (let i = comma - 1; i > floor; i--) {
14229
+ const visited = [];
14230
+ let result;
14231
+ for (let i = comma; i > floor; i--) {
14139
14232
  const c = code.charAt(i);
14140
- if (c === ";") return void 0;
14233
+ if (c === ";") break;
14234
+ if (c === ",") {
14235
+ const cached = this.listKeywords.get(i);
14236
+ if (cached?.floor === floor) {
14237
+ result = cached.word;
14238
+ break;
14239
+ }
14240
+ visited.push(i);
14241
+ }
14141
14242
  const group = CLOSERS[c] ? this.byClose.get(i) : void 0;
14142
14243
  if (group) i = group.open;
14143
14244
  else if (isWordChar(c)) {
14144
14245
  const word = this.wordBefore(i + 1);
14145
- if (DECLARATIONS.has(word.text) && code.charAt(word.start - 1) !== ".") return word;
14246
+ if (DECLARATIONS.has(word.text) && code.charAt(word.start - 1) !== ".") {
14247
+ result = word;
14248
+ break;
14249
+ }
14146
14250
  i = word.start;
14147
14251
  }
14148
14252
  }
14253
+ for (const at of visited) this.listKeywords.set(at, {
14254
+ floor,
14255
+ word: result
14256
+ });
14257
+ return result;
14149
14258
  }
14150
14259
  nameEnd(at) {
14151
14260
  let end = at;
@@ -26682,4 +26791,4 @@ function validateVariableReferences(passages, declarations, macros = []) {
26682
26791
  const list = [...passages];
26683
26792
  return checkVariableReferences(list.filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros, false, list));
26684
26793
  }
26685
- export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, completionTarget, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, indexStrictCodeEnds, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCallAt, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
26794
+ export { MarkupError, SIGIL_SCOPES, analyzeCodeEffects, checkParameterTypes, collectStoryPassageReferences, completionContext, completionTarget, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, indexStrictCodeEnds, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCallAt, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
@@ -23,6 +23,7 @@ export {
23
23
  parseDeclarations,
24
24
  formatDiagnostic,
25
25
  parseCode,
26
+ analyzeCodeEffects,
26
27
  macroArgumentSpans,
27
28
  parseBoundVariable,
28
29
  effectiveWidgetDefinitions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.64.33",
3
+ "version": "0.64.34",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  useState,
3
3
  useEffect,
4
+ useLayoutEffect,
4
5
  useCallback,
5
6
  useRef,
6
7
  useContext,
@@ -135,7 +136,7 @@ export function SaveManagerContent({
135
136
  statusTimer.current = window.setTimeout(() => setStatus(null), 3000);
136
137
  };
137
138
 
138
- useEffect(() => {
139
+ useLayoutEffect(() => {
139
140
  mounted.current = true;
140
141
  return () => {
141
142
  mounted.current = false;
@@ -243,8 +244,11 @@ export function SaveManagerContent({
243
244
  replacement,
244
245
  );
245
246
  showStatus('Game loaded');
246
- if (closeDialog) {
247
- closeTimer.current = window.setTimeout(closeDialog, 500);
247
+ if (closeDialog && mounted.current) {
248
+ clearTimeout(closeTimer.current);
249
+ closeTimer.current = window.setTimeout(() => {
250
+ if (mounted.current) closeDialog();
251
+ }, 500);
248
252
  }
249
253
  // A playthrough deleted since the list was read is recorded again
250
254
  await refresh();
@@ -3,6 +3,7 @@ import { useCallback, useLayoutEffect, useRef, useState } from 'preact/hooks';
3
3
  import { defineMacro, type MacroContext } from '../../define-macro';
4
4
  import { useStoryStore } from '../../store';
5
5
  import { subscribeVariableWrites } from '../../utils/variable-writes';
6
+ import { batchControlValues } from '../../utils/control-bindings';
6
7
  import {
7
8
  actionAttributes,
8
9
  useControlAction,
@@ -65,7 +66,9 @@ function subscribeFormReset(
65
66
  });
66
67
  restoreDefaults();
67
68
  const commits = controls.map(({ read, element }) => read(element));
68
- for (const commit of commits) commit();
69
+ batchControlValues(() => {
70
+ for (const commit of commits) commit();
71
+ });
69
72
  }, 0);
70
73
  };
71
74
  subscription = { readers, reset };