@torpor/view 1.3.2 → 1.3.3

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.
@@ -324,6 +324,21 @@ interface Effect {
324
324
  * The number of children of this effect.
325
325
  */
326
326
  extent: number;
327
+ /**
328
+ * Monotonic creation order, assigned by `$run`. The effect queue is run in
329
+ * this order, so an effect always re-runs before effects that were created
330
+ * while it was running (its "children" — e.g. a control statement's branch
331
+ * effects). That is what lets a branch be disposed before its own bindings
332
+ * re-run when the branch's condition turns false.
333
+ */
334
+ seq: number;
335
+ /**
336
+ * True once the effect's owning region has been released (`clearRegion`).
337
+ * A destroyed effect is skipped if it's still queued: e.g. an `@if`
338
+ * branch's bindings must not run again in the same flush in which the
339
+ * control statement disposed the branch.
340
+ */
341
+ destroyed?: boolean;
327
342
  /**
328
343
  * True while the effect is linked into the current run queue. Reset as
329
344
  * soon as the effect is processed, so a signal write later in the same
@@ -395,4 +410,4 @@ interface Effect {
395
410
  }
396
411
  //#endregion
397
412
  export { ProxySignal as i, Region as n, Computed as r, Effect as t };
398
- //# sourceMappingURL=Effect-Bf8fz_zC.d.cts.map
413
+ //# sourceMappingURL=Effect-Bp-BIDDm.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Effect-99HYQdzZ.d.mts","names":[],"sources":["../src/types/AsyncSettle.ts","../src/types/constants.ts","../src/types/ProxySignal.ts","../src/types/Subscription.ts","../src/types/Computed.ts","../src/types/ErrorBoundary.ts","../src/types/Region.ts","../src/types/Effect.ts"],"mappings":";;;;;;;;;;;;;;;KAaK;EAAgB;EAAU;;EAAiB;EAAW;;;;;;;cCV9C;;;;cAKA;;;;cAKA;;;;;;;UCNY;;;;EAIxB,aAAa;;;;EAKb,aAAa;;;;EAKb,oBAAoB;;;;EAKpB;;;;;;;;UClBwB;;;;EAIxB,QAAQ,cAAc;;;;EAKtB,QAAQ,WAAW;;;;;EAMnB,YAAY;;;;;EAMZ,YAAY;;;;;;;EAQZ,gBAAgB;;;;;;EAOhB;;;;;EAMA;;;;EAKA;;;;;;;;;UC9CwB,SAAS;;;;EAIjC,aAAa;;;;;;;;EASb;;;;EAKA,OAAO;;;;EAKP,WAAW;;;;EAKX,aAAa;;;;EAKb,aAAa;;;;;;;EAQb;;;;EAKA;;;;EAKA;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,QAAQ;;;;;;;;;;;;;;;EAgBR;;;;EAKA,UAAU;;;;EAKV;;;;;;;;;;UCrHwB;;;;;;EAMxB;;;;;EAMA;;;;;EAMA,QAAQ;;;;;;;;;EAUR,cAAc,cAAc;;;;UCnCJ;EACxB,WAAW;EACX,SAAS;EAET,gBAAgB;EAChB,YAAY;EACZ;;;;;EAMA,YAAY,IAAI;;;;EAKhB;;;;EAKA,SAAS;;;;;;;EAQT,gBAAgB;;;;;;;EAQhB;;;;;;EAOA;;;;;;;UCtCwB;;;;EAIxB,aAAa;;;;;EAMb,WAAW;;;;EAKX,SAAS;;;;EAKT,aAAa;EAKb,YAAY;;;;EAKZ;;;;;;EAOA;;;;EAKA;;;;;;;EAQA;;;;;;;;;;EAWA,iBAAiB,IAAI;;;;EAKrB;;;;;;EAOA,SAAS;;;;;;EAOT,gBAAgB,cAAc;;;;;;;;;EAU9B;;;;;;;;;;;;;;;;EAiBA"}
1
+ {"version":3,"file":"Effect-Bp-BIDDm.d.cts","names":[],"sources":["../src/types/AsyncSettle.ts","../src/types/constants.ts","../src/types/ProxySignal.ts","../src/types/Subscription.ts","../src/types/Computed.ts","../src/types/ErrorBoundary.ts","../src/types/Region.ts","../src/types/Effect.ts"],"mappings":";;;;;;;;;;;;;;;KAaK;EAAgB;EAAU;;EAAiB;EAAW;;;;;;;cCV9C;;;;cAKA;;;;cAKA;;;;;;;UCNY;;;;EAIxB,aAAa;;;;EAKb,aAAa;;;;EAKb,oBAAoB;;;;EAKpB;;;;;;;;UClBwB;;;;EAIxB,QAAQ,cAAc;;;;EAKtB,QAAQ,WAAW;;;;;EAMnB,YAAY;;;;;EAMZ,YAAY;;;;;;;EAQZ,gBAAgB;;;;;;EAOhB;;;;;EAMA;;;;EAKA;;;;;;;;;UC9CwB,SAAS;;;;EAIjC,aAAa;;;;;;;;EASb;;;;EAKA,OAAO;;;;EAKP,WAAW;;;;EAKX,aAAa;;;;EAKb,aAAa;;;;;;;EAQb;;;;EAKA;;;;EAKA;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,QAAQ;;;;;;;;;;;;;;;EAgBR;;;;EAKA,UAAU;;;;EAKV;;;;;;;;;;UCrHwB;;;;;;EAMxB;;;;;EAMA;;;;;EAMA,QAAQ;;;;;;;;;EAUR,cAAc,cAAc;;;;UCnCJ;EACxB,WAAW;EACX,SAAS;EAET,gBAAgB;EAChB,YAAY;EACZ;;;;;EAMA,YAAY,IAAI;;;;EAKhB;;;;EAKA,SAAS;;;;;;;EAQT,gBAAgB;;;;;;;EAQhB;;;;;;EAOA;;;;;;;UCtCwB;;;;EAIxB,aAAa;;;;;EAMb,WAAW;;;;EAKX,SAAS;;;;EAKT,aAAa;EAKb,YAAY;;;;EAKZ;;;;;;;;EASA;;;;;;;EAQA;;;;;;EAOA;;;;EAKA;;;;;;;EAQA;;;;;;;;;;EAWA,iBAAiB,IAAI;;;;EAKrB;;;;;;EAOA,SAAS;;;;;;EAOT,gBAAgB,cAAc;;;;;;;;;EAU9B;;;;;;;;;;;;;;;;EAiBA"}
@@ -324,6 +324,21 @@ interface Effect {
324
324
  * The number of children of this effect.
325
325
  */
326
326
  extent: number;
327
+ /**
328
+ * Monotonic creation order, assigned by `$run`. The effect queue is run in
329
+ * this order, so an effect always re-runs before effects that were created
330
+ * while it was running (its "children" — e.g. a control statement's branch
331
+ * effects). That is what lets a branch be disposed before its own bindings
332
+ * re-run when the branch's condition turns false.
333
+ */
334
+ seq: number;
335
+ /**
336
+ * True once the effect's owning region has been released (`clearRegion`).
337
+ * A destroyed effect is skipped if it's still queued: e.g. an `@if`
338
+ * branch's bindings must not run again in the same flush in which the
339
+ * control statement disposed the branch.
340
+ */
341
+ destroyed?: boolean;
327
342
  /**
328
343
  * True while the effect is linked into the current run queue. Reset as
329
344
  * soon as the effect is processed, so a signal write later in the same
@@ -395,4 +410,4 @@ interface Effect {
395
410
  }
396
411
  //#endregion
397
412
  export { ProxySignal as i, Region as n, Computed as r, Effect as t };
398
- //# sourceMappingURL=Effect-99HYQdzZ.d.mts.map
413
+ //# sourceMappingURL=Effect-VsIY2vPx.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Effect-Bf8fz_zC.d.cts","names":[],"sources":["../src/types/AsyncSettle.ts","../src/types/constants.ts","../src/types/ProxySignal.ts","../src/types/Subscription.ts","../src/types/Computed.ts","../src/types/ErrorBoundary.ts","../src/types/Region.ts","../src/types/Effect.ts"],"mappings":";;;;;;;;;;;;;;;KAaK;EAAgB;EAAU;;EAAiB;EAAW;;;;;;;cCV9C;;;;cAKA;;;;cAKA;;;;;;;UCNY;;;;EAIxB,aAAa;;;;EAKb,aAAa;;;;EAKb,oBAAoB;;;;EAKpB;;;;;;;;UClBwB;;;;EAIxB,QAAQ,cAAc;;;;EAKtB,QAAQ,WAAW;;;;;EAMnB,YAAY;;;;;EAMZ,YAAY;;;;;;;EAQZ,gBAAgB;;;;;;EAOhB;;;;;EAMA;;;;EAKA;;;;;;;;;UC9CwB,SAAS;;;;EAIjC,aAAa;;;;;;;;EASb;;;;EAKA,OAAO;;;;EAKP,WAAW;;;;EAKX,aAAa;;;;EAKb,aAAa;;;;;;;EAQb;;;;EAKA;;;;EAKA;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,QAAQ;;;;;;;;;;;;;;;EAgBR;;;;EAKA,UAAU;;;;EAKV;;;;;;;;;;UCrHwB;;;;;;EAMxB;;;;;EAMA;;;;;EAMA,QAAQ;;;;;;;;;EAUR,cAAc,cAAc;;;;UCnCJ;EACxB,WAAW;EACX,SAAS;EAET,gBAAgB;EAChB,YAAY;EACZ;;;;;EAMA,YAAY,IAAI;;;;EAKhB;;;;EAKA,SAAS;;;;;;;EAQT,gBAAgB;;;;;;;EAQhB;;;;;;EAOA;;;;;;;UCtCwB;;;;EAIxB,aAAa;;;;;EAMb,WAAW;;;;EAKX,SAAS;;;;EAKT,aAAa;EAKb,YAAY;;;;EAKZ;;;;;;EAOA;;;;EAKA;;;;;;;EAQA;;;;;;;;;;EAWA,iBAAiB,IAAI;;;;EAKrB;;;;;;EAOA,SAAS;;;;;;EAOT,gBAAgB,cAAc;;;;;;;;;EAU9B;;;;;;;;;;;;;;;;EAiBA"}
1
+ {"version":3,"file":"Effect-VsIY2vPx.d.mts","names":[],"sources":["../src/types/AsyncSettle.ts","../src/types/constants.ts","../src/types/ProxySignal.ts","../src/types/Subscription.ts","../src/types/Computed.ts","../src/types/ErrorBoundary.ts","../src/types/Region.ts","../src/types/Effect.ts"],"mappings":";;;;;;;;;;;;;;;KAaK;EAAgB;EAAU;;EAAiB;EAAW;;;;;;;cCV9C;;;;cAKA;;;;cAKA;;;;;;;UCNY;;;;EAIxB,aAAa;;;;EAKb,aAAa;;;;EAKb,oBAAoB;;;;EAKpB;;;;;;;;UClBwB;;;;EAIxB,QAAQ,cAAc;;;;EAKtB,QAAQ,WAAW;;;;;EAMnB,YAAY;;;;;EAMZ,YAAY;;;;;;;EAQZ,gBAAgB;;;;;;EAOhB;;;;;EAMA;;;;EAKA;;;;;;;;;UC9CwB,SAAS;;;;EAIjC,aAAa;;;;;;;;EASb;;;;EAKA,OAAO;;;;EAKP,WAAW;;;;EAKX,aAAa;;;;EAKb,aAAa;;;;;;;EAQb;;;;EAKA;;;;EAKA;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,QAAQ;;;;;;;;;;;;;;;EAgBR;;;;EAKA,UAAU;;;;EAKV;;;;;;;;;;UCrHwB;;;;;;EAMxB;;;;;EAMA;;;;;EAMA,QAAQ;;;;;;;;;EAUR,cAAc,cAAc;;;;UCnCJ;EACxB,WAAW;EACX,SAAS;EAET,gBAAgB;EAChB,YAAY;EACZ;;;;;EAMA,YAAY,IAAI;;;;EAKhB;;;;EAKA,SAAS;;;;;;;EAQT,gBAAgB;;;;;;;EAQhB;;;;;;EAOA;;;;;;;UCtCwB;;;;EAIxB,aAAa;;;;;EAMb,WAAW;;;;EAKX,SAAS;;;;EAKT,aAAa;EAKb,YAAY;;;;EAKZ;;;;;;;;EASA;;;;;;;EAQA;;;;;;EAOA;;;;EAKA;;;;;;;EAQA;;;;;;;;;;EAWA,iBAAiB,IAAI;;;;EAKrB;;;;;;EAOA,SAAS;;;;;;EAOT,gBAAgB,cAAc;;;;;;;;;EAU9B;;;;;;;;;;;;;;;;EAiBA"}
package/dist/compile.cjs CHANGED
@@ -886,6 +886,21 @@ function isSpecialNode(node) {
886
886
  return node.type === "special";
887
887
  }
888
888
  //#endregion
889
+ //#region src/compile/utils/propKey.ts
890
+ const IDENTIFIER_REGEX = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
891
+ /**
892
+ * Formats a prop name for use as an object key in generated code. Valid
893
+ * identifiers are left unquoted; anything else (e.g. dashed props like
894
+ * `aria-hidden`) is quoted so that the generated code stays valid.
895
+ *
896
+ * @param name The prop name as written on the component or slot
897
+ *
898
+ * @returns The name as an object key text
899
+ */
900
+ function propKey(name) {
901
+ return IDENTIFIER_REGEX.test(name) ? name : JSON.stringify(name);
902
+ }
903
+ //#endregion
889
904
  //#region src/compile/build/utils/nextVarName.ts
890
905
  /**
891
906
  * Makes a supplied variable name (hopefully!) unique by prepending `t_` and
@@ -1707,8 +1722,9 @@ function buildComponentNode(node, status, b, root = false) {
1707
1722
  let value = p.value;
1708
1723
  p.preText ??= "";
1709
1724
  p.postText ??= "";
1710
- if (p.spans.length === 1) addMappedText(p.name ? `${p.name}: ` + p.preText : p.preText, value, p.postText + ",", p.spans[0], status, b);
1711
- else addMappedTextWithOffsets(p.name ? `${p.name}: ` + p.preText : p.preText, value, p.postText + ",", p.spans, p.offsets, p.lengths, status, b);
1725
+ const key = p.name ? `${propKey(p.name)}: ` : "";
1726
+ if (p.spans.length === 1) addMappedText(key + p.preText, value, p.postText + ",", p.spans[0], status, b);
1727
+ else addMappedTextWithOffsets(key + p.preText, value, p.postText + ",", p.spans, p.offsets, p.lengths, status, b);
1712
1728
  }
1713
1729
  b.append("});");
1714
1730
  if (runs.length) buildRun("setProps", runs.join("\n"), status, b);
@@ -2173,8 +2189,10 @@ function buildForNode(node, status, b) {
2173
2189
  appendForVarBindings(b, status, `${node.statement}\n${keyStatement}`);
2174
2190
  addMappedText("", `${node.statement}`, " {", node.span, status, b);
2175
2191
  const dataExpr = singleVar ? forVarNames[0] : `{ ${forVarNames.join(", ")} }`;
2176
- if (key !== void 0) addMappedText(`${listItemsName}.push({ data: ${dataExpr}, key: `, `${keyStatement || "undefined"}`, " });", key.span, status, b);
2177
- else b.append(`${listItemsName}.push({ data: ${dataExpr} });`);
2192
+ if (key !== void 0) {
2193
+ status.imports.add("$peek");
2194
+ addMappedText(`${listItemsName}.push({ data: ${dataExpr}, key: $peek(() => `, `${keyStatement || "undefined"}`, ") });", key.span, status, b);
2195
+ } else b.append(`${listItemsName}.push({ data: ${dataExpr} });`);
2178
2196
  b.append(`}`);
2179
2197
  b.append(`return ${listItemsName};`);
2180
2198
  b.append(`},
@@ -2939,7 +2957,7 @@ function buildSlotNode(node, status, b) {
2939
2957
  b.append(`const ${propsName} = $watch({`);
2940
2958
  for (let p of props) {
2941
2959
  let value = p.value;
2942
- addMappedText(`${p.name}: `, value, ",", p.span, status, b);
2960
+ addMappedText(`${propKey(p.name)}: `, value, ",", p.span, status, b);
2943
2961
  }
2944
2962
  b.append("});");
2945
2963
  if (runs.length) buildRun("setProps", runs.join("\n"), status, b);
@@ -3375,7 +3393,7 @@ function buildServerComponentNode(node, status, b) {
3375
3393
  });
3376
3394
  }
3377
3395
  b.append(`const ${propsName} = {`);
3378
- for (let p of props) b.append(p.name ? `${p.name}: ${p.value},` : `${p.value},`);
3396
+ for (let p of props) b.append(p.name ? `${propKey(p.name)}: ${p.value},` : `${p.value},`);
3379
3397
  b.append("};");
3380
3398
  }
3381
3399
  const componentHasSlots = node.children.length;
package/dist/compile.mjs CHANGED
@@ -885,6 +885,21 @@ function isSpecialNode(node) {
885
885
  return node.type === "special";
886
886
  }
887
887
  //#endregion
888
+ //#region src/compile/utils/propKey.ts
889
+ const IDENTIFIER_REGEX = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
890
+ /**
891
+ * Formats a prop name for use as an object key in generated code. Valid
892
+ * identifiers are left unquoted; anything else (e.g. dashed props like
893
+ * `aria-hidden`) is quoted so that the generated code stays valid.
894
+ *
895
+ * @param name The prop name as written on the component or slot
896
+ *
897
+ * @returns The name as an object key text
898
+ */
899
+ function propKey(name) {
900
+ return IDENTIFIER_REGEX.test(name) ? name : JSON.stringify(name);
901
+ }
902
+ //#endregion
888
903
  //#region src/compile/build/utils/nextVarName.ts
889
904
  /**
890
905
  * Makes a supplied variable name (hopefully!) unique by prepending `t_` and
@@ -1706,8 +1721,9 @@ function buildComponentNode(node, status, b, root = false) {
1706
1721
  let value = p.value;
1707
1722
  p.preText ??= "";
1708
1723
  p.postText ??= "";
1709
- if (p.spans.length === 1) addMappedText(p.name ? `${p.name}: ` + p.preText : p.preText, value, p.postText + ",", p.spans[0], status, b);
1710
- else addMappedTextWithOffsets(p.name ? `${p.name}: ` + p.preText : p.preText, value, p.postText + ",", p.spans, p.offsets, p.lengths, status, b);
1724
+ const key = p.name ? `${propKey(p.name)}: ` : "";
1725
+ if (p.spans.length === 1) addMappedText(key + p.preText, value, p.postText + ",", p.spans[0], status, b);
1726
+ else addMappedTextWithOffsets(key + p.preText, value, p.postText + ",", p.spans, p.offsets, p.lengths, status, b);
1711
1727
  }
1712
1728
  b.append("});");
1713
1729
  if (runs.length) buildRun("setProps", runs.join("\n"), status, b);
@@ -2172,8 +2188,10 @@ function buildForNode(node, status, b) {
2172
2188
  appendForVarBindings(b, status, `${node.statement}\n${keyStatement}`);
2173
2189
  addMappedText("", `${node.statement}`, " {", node.span, status, b);
2174
2190
  const dataExpr = singleVar ? forVarNames[0] : `{ ${forVarNames.join(", ")} }`;
2175
- if (key !== void 0) addMappedText(`${listItemsName}.push({ data: ${dataExpr}, key: `, `${keyStatement || "undefined"}`, " });", key.span, status, b);
2176
- else b.append(`${listItemsName}.push({ data: ${dataExpr} });`);
2191
+ if (key !== void 0) {
2192
+ status.imports.add("$peek");
2193
+ addMappedText(`${listItemsName}.push({ data: ${dataExpr}, key: $peek(() => `, `${keyStatement || "undefined"}`, ") });", key.span, status, b);
2194
+ } else b.append(`${listItemsName}.push({ data: ${dataExpr} });`);
2177
2195
  b.append(`}`);
2178
2196
  b.append(`return ${listItemsName};`);
2179
2197
  b.append(`},
@@ -2938,7 +2956,7 @@ function buildSlotNode(node, status, b) {
2938
2956
  b.append(`const ${propsName} = $watch({`);
2939
2957
  for (let p of props) {
2940
2958
  let value = p.value;
2941
- addMappedText(`${p.name}: `, value, ",", p.span, status, b);
2959
+ addMappedText(`${propKey(p.name)}: `, value, ",", p.span, status, b);
2942
2960
  }
2943
2961
  b.append("});");
2944
2962
  if (runs.length) buildRun("setProps", runs.join("\n"), status, b);
@@ -3374,7 +3392,7 @@ function buildServerComponentNode(node, status, b) {
3374
3392
  });
3375
3393
  }
3376
3394
  b.append(`const ${propsName} = {`);
3377
- for (let p of props) b.append(p.name ? `${p.name}: ${p.value},` : `${p.value},`);
3395
+ for (let p of props) b.append(p.name ? `${propKey(p.name)}: ${p.value},` : `${p.value},`);
3378
3396
  b.append("};");
3379
3397
  }
3380
3398
  const componentHasSlots = node.children.length;