marko 6.4.7 → 6.4.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.
Files changed (89) hide show
  1. package/dist/common/constants/closure-signal-prop.d.ts +1 -1
  2. package/dist/common/constants/closure-signal-prop.debug.d.ts +1 -1
  3. package/dist/debug/dom/catch.feat.js +1 -1
  4. package/dist/debug/dom/catch.feat.mjs +1 -1
  5. package/dist/debug/dom/controllable-input.feat.js +1 -1
  6. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  7. package/dist/debug/dom/controllable-open.feat.js +1 -1
  8. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  9. package/dist/debug/dom/controllable-select.feat.js +1 -1
  10. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  11. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  12. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  13. package/dist/debug/dom/controllable.feat.js +1 -1
  14. package/dist/debug/dom/controllable.feat.mjs +1 -1
  15. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  16. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  17. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  18. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  19. package/dist/debug/dom/lazy.feat.js +1 -1
  20. package/dist/debug/dom/lazy.feat.mjs +1 -1
  21. package/dist/debug/dom/placeholder.feat.js +1 -1
  22. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  23. package/dist/debug/{dom-D8znnhpf.js → dom-QkYva5Qx.js} +35 -61
  24. package/dist/debug/{dom-CFCBDift.mjs → dom-VKjkbuuo.mjs} +36 -50
  25. package/dist/debug/dom.js +4 -4
  26. package/dist/debug/dom.mjs +4 -4
  27. package/dist/debug/html.js +20 -13
  28. package/dist/debug/html.mjs +18 -11
  29. package/dist/dom/catch.feat.js +3 -3
  30. package/dist/dom/catch.feat.mjs +1 -1
  31. package/dist/dom/compat.d.ts +1 -1
  32. package/dist/dom/control-flow.d.ts +1 -1
  33. package/dist/dom/controllable-input.feat.js +1 -1
  34. package/dist/dom/controllable-input.feat.mjs +1 -1
  35. package/dist/dom/controllable-open.feat.js +1 -1
  36. package/dist/dom/controllable-open.feat.mjs +1 -1
  37. package/dist/dom/controllable-select.feat.js +1 -1
  38. package/dist/dom/controllable-select.feat.mjs +1 -1
  39. package/dist/dom/controllable-textarea.feat.js +1 -1
  40. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  41. package/dist/dom/controllable.feat.js +1 -1
  42. package/dist/dom/controllable.feat.mjs +1 -1
  43. package/dist/dom/dom.d.ts +2 -3
  44. package/dist/dom/dynamic-tag-script.feat.js +2 -2
  45. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  46. package/dist/dom/dynamic-tag-var.feat.js +3 -3
  47. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  48. package/dist/dom/lazy.feat.js +1 -1
  49. package/dist/dom/lazy.feat.mjs +1 -1
  50. package/dist/dom/placeholder.feat.js +3 -3
  51. package/dist/dom/placeholder.feat.mjs +1 -1
  52. package/dist/dom/resume.d.ts +1 -1
  53. package/dist/dom/scope.d.ts +1 -1
  54. package/dist/dom/signals.d.ts +1 -1
  55. package/dist/{dom-CVAevsbz.mjs → dom-DtKQb840.mjs} +19 -33
  56. package/dist/{dom-Bpkm72vV.js → dom-IujlfJ6b.js} +82 -106
  57. package/dist/dom.js +31 -31
  58. package/dist/dom.mjs +4 -4
  59. package/dist/html/serializer.d.ts +1 -1
  60. package/dist/html/writer.d.ts +3 -3
  61. package/dist/html.d.ts +1 -1
  62. package/dist/html.js +21 -15
  63. package/dist/html.mjs +21 -15
  64. package/dist/translator/core/show.d.ts +3 -4
  65. package/dist/translator/index.js +1253 -1134
  66. package/dist/translator/util/bindings.d.ts +6 -5
  67. package/dist/translator/util/branch-tag.d.ts +1 -1
  68. package/dist/translator/util/constants/slot-kind.d.ts +1 -1
  69. package/dist/translator/util/known-tag.d.ts +6 -2
  70. package/dist/translator/util/module-registrations.d.ts +1 -1
  71. package/dist/translator/util/optional.d.ts +1 -0
  72. package/dist/translator/util/params-tree.d.ts +3 -3
  73. package/dist/translator/util/reasons.d.ts +3 -4
  74. package/dist/translator/util/references.d.ts +13 -8
  75. package/dist/translator/util/replace-with-statements.d.ts +4 -0
  76. package/dist/translator/util/runtime.d.ts +1 -0
  77. package/dist/translator/util/scope-accessor.d.ts +1 -1
  78. package/dist/translator/util/sections.d.ts +42 -17
  79. package/dist/translator/util/signals.d.ts +3 -11
  80. package/dist/translator/util/slots.d.ts +1 -1
  81. package/dist/translator/util/solve-reasons.d.ts +6 -0
  82. package/dist/translator/util/static-text.d.ts +1 -0
  83. package/dist/translator/util/structure.d.ts +3 -2
  84. package/dist/translator/util/tag-import.d.ts +0 -2
  85. package/dist/translator/util/write-guard.d.ts +4 -1
  86. package/dist/translator/visitors/placeholder.d.ts +4 -4
  87. package/package.json +4 -4
  88. package/tags-html.d.ts +3 -0
  89. package/dist/translator/visitors/constants/sibling-text.d.ts +0 -6
@@ -429,18 +429,14 @@ function mapToString(data, sep, cb) {
429
429
  return "";
430
430
  }
431
431
  function findSorted(compare, data, item) {
432
- let max = data.length;
433
- let pos = 0;
434
- while (pos < max) {
435
- const mid = pos + max >>> 1;
436
- const cur = data[mid];
437
- const compareResult = compare(cur, item);
438
- if (compareResult === 0) return cur;
439
- if (compareResult > 0) max = mid;
440
- else pos = mid + 1;
441
- }
432
+ const index = searchSorted(compare, data, item);
433
+ if (index >= 0) return data[index];
442
434
  }
443
435
  function findIndexSorted(compare, data, item) {
436
+ const index = searchSorted(compare, data, item);
437
+ return index < 0 ? -1 : index;
438
+ }
439
+ function searchSorted(compare, data, item) {
444
440
  let max = data.length;
445
441
  let pos = 0;
446
442
  while (pos < max) {
@@ -450,28 +446,17 @@ function findIndexSorted(compare, data, item) {
450
446
  if (compareResult > 0) max = mid;
451
447
  else pos = mid + 1;
452
448
  }
453
- return -1;
449
+ return ~pos;
454
450
  }
455
451
  function addSorted(compare, data, item) {
452
+ let pos = searchSorted(compare, data, item);
453
+ if (pos >= 0) return data;
454
+ pos = ~pos;
456
455
  const len = data.length;
457
- let max = len;
458
- let pos = 0;
459
- while (pos < max) {
460
- const mid = pos + max >>> 1;
461
- const compareResult = compare(data[mid], item);
462
- if (compareResult === 0) return data;
463
- if (compareResult > 0) max = mid;
464
- else pos = mid + 1;
465
- }
466
456
  const result = new Array(len + 1);
467
457
  for (let i = 0; i < pos; i++) result[i] = data[i];
468
- let cur = item;
469
- while (pos < len) {
470
- const next = cur;
471
- cur = data[pos];
472
- result[pos++] = next;
473
- }
474
- result[len] = cur;
458
+ result[pos] = item;
459
+ while (pos < len) result[pos + 1] = data[pos++];
475
460
  return result;
476
461
  }
477
462
  function partitionPoint(data, key, compareKeys, bound) {
@@ -651,6 +636,30 @@ function getCompileStage(file = (0, _marko_compiler_babel_utils.getFile)()) {
651
636
  return file.___compileStage;
652
637
  }
653
638
  //#endregion
639
+ //#region src/translator/util/replace-with-statements.ts
640
+ const replacements = /* @__PURE__ */ new WeakMap();
641
+ function replaceWithStatements(path, statements) {
642
+ path.skip();
643
+ const inserted = replacements.get(path.node);
644
+ if (inserted) {
645
+ if (statements) for (const statement of statements) inserted.push(statement);
646
+ } else replacements.set(path.node, statements || null);
647
+ }
648
+ function insertStatementBefore(path, statement) {
649
+ const inserted = replacements.get(path.node);
650
+ if (inserted) inserted.push(statement);
651
+ else replacements.set(path.node, [statement]);
652
+ }
653
+ function writeBodyStatements(body) {
654
+ const statements = [];
655
+ for (const child of body.body) {
656
+ const replacement = replacements.get(child);
657
+ if (replacement === void 0) statements.push(child);
658
+ else if (replacement) for (const statement of replacement) statements.push(statement);
659
+ }
660
+ body.body = statements;
661
+ }
662
+ //#endregion
654
663
  //#region src/translator/util/state.ts
655
664
  function createOutputState(init) {
656
665
  return createKeyedState(_marko_compiler_babel_utils.getProgram, init);
@@ -769,7 +778,7 @@ function generateUidIdentifier(name) {
769
778
  }
770
779
  function declareConstBefore(tag, name, expr) {
771
780
  const id = generateUidIdentifier(name);
772
- tag.insertBefore(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(id, expr)]));
781
+ insertStatementBefore(tag, _marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(id, expr)]));
773
782
  return id;
774
783
  }
775
784
  const [getSharedUIDs] = createOutputState(() => /* @__PURE__ */ new Map());
@@ -958,58 +967,6 @@ const ModuleRead = "moduleRead";
958
967
  const SectionRef = "sectionRef";
959
968
  const ExportRef = "exportRef";
960
969
  //#endregion
961
- //#region src/translator/util/slots.ts
962
- const slotUtil = new Sorted(compareSlots);
963
- function ensureSlot(binding, kind = 0, section, group) {
964
- const owner = getCanonicalBinding(binding);
965
- return findSlot(owner, kind, section, group) || addSlot(kind, section || owner.section, owner, group);
966
- }
967
- function findSlot(binding, kind = 0, section, group) {
968
- const owner = getCanonicalBinding(binding);
969
- return findIn((section || owner.section).slots, owner.uid, kind, group);
970
- }
971
- function ensureSectionSlot(owner, kind, section = owner) {
972
- return findSectionSlot(owner, kind, section) || addSlot(kind, section, owner, void 0);
973
- }
974
- function findSectionSlot(owner, kind, section = owner) {
975
- return findIn(section.slots, getOwnerOrder(owner), kind, void 0);
976
- }
977
- function addSlot(kind, section, owner, group) {
978
- const slot = {
979
- kind,
980
- section,
981
- owner,
982
- group,
983
- reason: void 0,
984
- reasonExprs: void 0
985
- };
986
- section.slots = slotUtil.add(section.slots, slot);
987
- return slot;
988
- }
989
- function findIn(slots, order, kind, group) {
990
- if (slots === void 0) return;
991
- if (!Array.isArray(slots)) return compareSlotTo(slots, order, kind, group) ? void 0 : slots;
992
- let pos = 0;
993
- let max = slots.length;
994
- while (pos < max) {
995
- const mid = pos + max >>> 1;
996
- const slot = slots[mid];
997
- const result = compareSlotTo(slot, order, kind, group);
998
- if (result === 0) return slot;
999
- if (result > 0) max = mid;
1000
- else pos = mid + 1;
1001
- }
1002
- }
1003
- function compareSlots(a, b) {
1004
- return compareSlotTo(a, getOwnerOrder(b.owner), b.kind, b.group);
1005
- }
1006
- function compareSlotTo(slot, order, kind, group) {
1007
- return getOwnerOrder(slot.owner) - order || slot.kind - kind || (group ? compareReferences(slot.group, group) : 0);
1008
- }
1009
- function getOwnerOrder(owner) {
1010
- return "uid" in owner ? owner.uid : -1 - owner.id;
1011
- }
1012
- //#endregion
1013
970
  //#region src/translator/util/cyclic-memo.ts
1014
971
  let computations = 0;
1015
972
  let provisionalAt = Infinity;
@@ -1062,11 +1019,64 @@ function createPassPathMemo(compute, cycleAnswer) {
1062
1019
  };
1063
1020
  }
1064
1021
  function ensurePropKeys(pathKeys, property) {
1065
- let next = pathKeys.props?.get(property);
1066
- if (!next) (pathKeys.props ??= /* @__PURE__ */ new Map()).set(property, next = {});
1022
+ let next = pathKeys.properties?.get(property);
1023
+ if (!next) (pathKeys.properties ??= /* @__PURE__ */ new Map()).set(property, next = {});
1067
1024
  return next;
1068
1025
  }
1069
1026
  //#endregion
1027
+ //#region src/translator/util/slots.ts
1028
+ function ensureSlot(binding, kind = 0, section, group) {
1029
+ const owner = getCanonicalBinding(binding);
1030
+ return ensureIn(section || owner.section, owner, kind, group);
1031
+ }
1032
+ function findSlot(binding, kind = 0, section, group) {
1033
+ const owner = getCanonicalBinding(binding);
1034
+ return findIn((section || owner.section).slots, owner.uid, kind, group);
1035
+ }
1036
+ function ensureSectionSlot(owner, kind, section = owner) {
1037
+ return ensureIn(section, owner, kind, void 0);
1038
+ }
1039
+ function findSectionSlot(owner, kind, section = owner) {
1040
+ return findIn(section.slots, getOwnerOrder(owner), kind, void 0);
1041
+ }
1042
+ function ensureIn(section, owner, kind, group) {
1043
+ const { slots } = section;
1044
+ const index = searchIn(slots, getOwnerOrder(owner), kind, group);
1045
+ if (index >= 0) return slots[index];
1046
+ const slot = {
1047
+ kind,
1048
+ section,
1049
+ owner,
1050
+ group,
1051
+ reason: void 0,
1052
+ reasonExprs: void 0
1053
+ };
1054
+ slots.splice(~index, 0, slot);
1055
+ return slot;
1056
+ }
1057
+ function findIn(slots, order, kind, group) {
1058
+ const index = searchIn(slots, order, kind, group);
1059
+ if (index >= 0) return slots[index];
1060
+ }
1061
+ function searchIn(slots, order, kind, group) {
1062
+ let pos = 0;
1063
+ let max = slots.length;
1064
+ while (pos < max) {
1065
+ const mid = pos + max >>> 1;
1066
+ const result = compareSlotTo(slots[mid], order, kind, group);
1067
+ if (result === 0) return mid;
1068
+ if (result > 0) max = mid;
1069
+ else pos = mid + 1;
1070
+ }
1071
+ return ~pos;
1072
+ }
1073
+ function compareSlotTo(slot, order, kind, group) {
1074
+ return getOwnerOrder(slot.owner) - order || slot.kind - kind || (group ? compareReferences(slot.group, group) : 0);
1075
+ }
1076
+ function getOwnerOrder(owner) {
1077
+ return "uid" in owner ? owner.uid : -1 - owner.id;
1078
+ }
1079
+ //#endregion
1070
1080
  //#region src/translator/util/get-root.ts
1071
1081
  function getMarkoRoot(path) {
1072
1082
  let curPath = path;
@@ -1264,13 +1274,21 @@ function compareSources(a, b) {
1264
1274
  function mergeSources(a, b) {
1265
1275
  if (!a) return b;
1266
1276
  if (!b) return a;
1267
- if (a.state === b.state && a.param === b.param && a.global === b.global && a.always === b.always) return a;
1268
- return createSources(bindingUtil.union(a.state, b.state), unionParamSources(a.param, b.param), a.global || b.global, a.always || b.always);
1277
+ const state = bindingUtil.union(a.state, b.state);
1278
+ const param = unionParamSources(a.param, b.param);
1279
+ const global = a.global || b.global;
1280
+ const always = a.always || b.always;
1281
+ if (state === a.state && param === a.param && global === a.global && always === a.always) return a;
1282
+ if (state === b.state && param === b.param && global === b.global && always === b.always) return b;
1283
+ return createSources(state, param, global, always);
1269
1284
  }
1270
1285
  function unionParamSources(a, b) {
1271
1286
  const merged = bindingUtil.union(a, b);
1272
1287
  if (merged === a || merged === b) return merged;
1273
- return bindingUtil.filter(merged, (binding) => !someUpToAliasRoot(binding.aliasOf, isInParams, merged));
1288
+ return bindingUtil.union(dropCovered(a, b), dropCovered(b, a));
1289
+ }
1290
+ function dropCovered(params, other) {
1291
+ return bindingUtil.filter(params, (binding) => !someUpToAliasRoot(binding.aliasOf, isInParams, other));
1274
1292
  }
1275
1293
  function isInParams(binding, params) {
1276
1294
  return bindingUtil.has(params, binding);
@@ -1437,11 +1455,10 @@ function trackReferencesForBinding(babelBinding, binding) {
1437
1455
  }
1438
1456
  if (markoRoot?.type === "MarkoAttribute" && markoRoot.parentPath === babelBinding.path && !getFnRoot(ref)) throw ref.buildCodeFrameError(`\`${ref.node.name}\` is the [tag variable](https://markojs.com/docs/reference/language#tag-variables) this tag declares, so its own attributes cannot read it.`);
1439
1457
  else if (isReferenceHoisted(babelBinding.path, ref)) {
1440
- const invoked = isInvokedFunction(ref);
1441
- if (invoked) setReferencesScope(ref);
1458
+ setReferencesScope(ref);
1442
1459
  addReadToExpression(ref, binding, {
1443
1460
  hoisted: getCommonSection(refSection, binding.section),
1444
- invoked
1461
+ invoked: isInvokedFunction(ref)
1445
1462
  });
1446
1463
  } else if (binding.type !== 3 || refSection !== binding.section) trackReference(ref, binding);
1447
1464
  else {
@@ -1533,7 +1550,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, aliased, p
1533
1550
  if (!prop.computed && prop.key.type === "Identifier") key = prop.key.name;
1534
1551
  else if (prop.key.type === "StringLiteral") key = prop.key.value;
1535
1552
  else throw scope.path.hub.buildError(prop.key, "Only identifier and string literal keys are supported when destructuring.");
1536
- if (hasRest) excludeProperties = propsUtil.add(excludeProperties, key);
1553
+ if (hasRest) excludeProperties = propertiesUtil.add(excludeProperties, key);
1537
1554
  if (_marko_compiler.types.isLVal(prop.value)) createBindingsAndTrackReferences(prop.value, type, scope, section, patternBinding, key, void 0, void 0, declaresPattern);
1538
1555
  }
1539
1556
  break;
@@ -1599,7 +1616,7 @@ function trackReference(referencePath, binding) {
1599
1616
  prop = `${+prop + reference.restOffset}`;
1600
1617
  reference = reference.aliasOf;
1601
1618
  }
1602
- } else if (!propsUtil.has(reference.excludeProperties, prop)) reference = reference.aliasOf;
1619
+ } else if (!propertiesUtil.has(reference.excludeProperties, prop)) reference = reference.aliasOf;
1603
1620
  }
1604
1621
  if (isInvokedFunction(root.parentPath) && !isEventOrChangeHandler(prop)) break;
1605
1622
  root = root.parentPath;
@@ -1721,20 +1738,20 @@ function addRead(exprExtra, extra, binding, section, getter) {
1721
1738
  return read;
1722
1739
  }
1723
1740
  function dropNodes(node) {
1724
- forEachNodeExtra(node, dropExtra);
1741
+ forEachNodeExtra(node, dropExpr);
1725
1742
  }
1726
1743
  function untrackNodes(node) {
1727
- forEachNodeExtra(node, untrackExtra);
1744
+ forEachNodeExtra(node, untrackExpr);
1728
1745
  }
1729
1746
  function forEachNodeExtra(node, fn) {
1730
1747
  if (Array.isArray(node)) for (const item of node) fn(item.extra ??= {});
1731
1748
  else fn(node.extra ??= {});
1732
1749
  }
1733
- function dropExtra(exprExtra) {
1750
+ function dropExpr(exprExtra) {
1734
1751
  exprExtra.dropped = true;
1735
- untrackExtra(exprExtra);
1752
+ untrackExpr(exprExtra);
1736
1753
  }
1737
- function untrackExtra(exprExtra) {
1754
+ function untrackExpr(exprExtra) {
1738
1755
  /* v8 ignore next 3 -- a merged reference is never dropped */
1739
1756
  if (exprExtra.merged) throw new Error("Cannot drop a merged reference");
1740
1757
  const readsByExpr = getReadsByExpression();
@@ -1776,7 +1793,7 @@ function addReadToExpression(root, binding, getter) {
1776
1793
  const exprRoot = getExprRoot(fnRoot || root);
1777
1794
  const section = ensureSection(exprRoot);
1778
1795
  const rootExtra = exprRoot.node.extra ??= { section };
1779
- const exprExtra = getCanonicalExtra(rootExtra);
1796
+ const exprExtra = getCanonicalExpr(rootExtra);
1780
1797
  if (exprExtra.dropped) return;
1781
1798
  const extra = node.extra ??= {};
1782
1799
  extra.exprRoot = rootExtra;
@@ -1812,18 +1829,18 @@ function getAllTagReferenceNodes(tag, referenceNodes = [], collectAttrTag) {
1812
1829
  }
1813
1830
  return referenceNodes;
1814
1831
  }
1815
- function createResolvedRead(binding, props, inOwnBody = false) {
1832
+ function createResolvedRead(binding, properties, inOwnBody = false) {
1816
1833
  return {
1817
1834
  binding,
1818
- props,
1835
+ properties,
1819
1836
  inOwnBody,
1820
1837
  getter: void 0
1821
1838
  };
1822
1839
  }
1823
- function createResolvedGetterRead(binding, props, getter) {
1840
+ function createResolvedGetterRead(binding, properties, getter) {
1824
1841
  return {
1825
1842
  binding,
1826
- props,
1843
+ properties,
1827
1844
  inOwnBody: false,
1828
1845
  getter
1829
1846
  };
@@ -1835,16 +1852,16 @@ function hasResumableAssignment(binding) {
1835
1852
  return some(binding.assignments, isResumableAssignment);
1836
1853
  }
1837
1854
  function isResumableAssignment({ exprRoot, fnRoot }) {
1838
- return !!getCanonicalExtra(exprRoot).isEffect || !!fnRoot?.reason;
1855
+ return !!getCanonicalExpr(exprRoot).isEffect || !!fnRoot?.reason;
1839
1856
  }
1840
1857
  function isAssignedBindingExtra(extra) {
1841
1858
  return isReferencedExtra(extra) && extra.assignment !== void 0;
1842
1859
  }
1843
1860
  function isRegisteredFnExtra(extra) {
1844
- return isReferencedExtra(extra) && extra.registerId !== void 0;
1861
+ return isReferencedExtra(extra) && extra.registryId !== void 0;
1845
1862
  }
1846
1863
  function getReferencedBindings(extra) {
1847
- return extra && getCanonicalExtra(extra)[kReferencedBindings];
1864
+ return extra && getCanonicalExpr(extra)[kReferencedBindings];
1848
1865
  }
1849
1866
  function getBindingsDerivedFrom(binding) {
1850
1867
  if (binding.aliasOf) return binding.aliasOf;
@@ -1854,7 +1871,7 @@ function getValueReferences(exprs) {
1854
1871
  return reduce(exprs, addValueReferences);
1855
1872
  }
1856
1873
  function addValueReferences(refs, expr) {
1857
- return isReferencedExtra(getCanonicalExtra(expr)) && !expr.initialValue ? bindingUtil.union(refs, getReferencedBindings(expr)) : refs;
1874
+ return isReferencedExtra(getCanonicalExpr(expr)) && !expr.initialValue ? bindingUtil.union(refs, getReferencedBindings(expr)) : refs;
1858
1875
  }
1859
1876
  function getReferencedBindingsInFunction(extra) {
1860
1877
  return extra[kReferencedBindingsInFunction];
@@ -1865,18 +1882,19 @@ function getConstantBindingsInFunction(extra) {
1865
1882
  function setResolvedFunctionReads(extra, referencedBindings, constantBindings) {
1866
1883
  extra[kReferencedBindingsInFunction] = referencedBindings;
1867
1884
  extra[kConstantBindingsInFunction] = constantBindings;
1885
+ extra.referencesScope ||= !!(referencedBindings || constantBindings);
1868
1886
  }
1869
1887
  function setResolvedReads(extra, referencedBindings, lazyBindings) {
1870
1888
  extra[kReferencedBindings] = referencedBindings;
1871
1889
  extra[kLazyBindings] = lazyBindings;
1872
1890
  }
1873
- function getCanonicalExtra(extra) {
1891
+ function getCanonicalExpr(extra) {
1874
1892
  while (extra.merged) extra = extra.merged;
1875
1893
  return extra;
1876
1894
  }
1877
- function addNumericPropertiesUntil(props, len) {
1878
- let result = props;
1879
- for (let i = len; i--;) result = propsUtil.add(result, i + "");
1895
+ function addNumericPropertiesUntil(properties, len) {
1896
+ let result = properties;
1897
+ for (let i = len; i--;) result = propertiesUtil.add(result, i + "");
1880
1898
  return result;
1881
1899
  }
1882
1900
  //#endregion
@@ -1978,11 +1996,18 @@ function getRuntimePath(output) {
1978
1996
  function assertTranslate(helper, name) {
1979
1997
  if (!isTranslate()) throw new Error(`\`${helper}(${JSON.stringify(name)})\` may only be called during the translate stage.`);
1980
1998
  }
1999
+ function absentArg(value) {
2000
+ const arg = _marko_compiler.types.numericLiteral(value);
2001
+ absentArgs.add(arg);
2002
+ return arg;
2003
+ }
2004
+ const absentArgs = /* @__PURE__ */ new WeakSet();
1981
2005
  function trimFalsyArgs(args) {
1982
2006
  const filteredArgs = [];
1983
2007
  for (let i = args.length; i--;) {
1984
2008
  const arg = args[i];
1985
- if (arg || filteredArgs.length) filteredArgs[i] = arg || _marko_compiler.types.buildUndefinedNode();
2009
+ if (filteredArgs.length) filteredArgs[i] = arg || _marko_compiler.types.buildUndefinedNode();
2010
+ else if (arg && !absentArgs.has(arg)) filteredArgs[i] = arg;
1986
2011
  }
1987
2012
  return filteredArgs;
1988
2013
  }
@@ -1996,10 +2021,10 @@ const kRegisteredExports = Symbol("registered exports");
1996
2021
  const [getReferencesByFn] = createAnalysisState(() => /* @__PURE__ */ new Map());
1997
2022
  const [getReferencesByImport] = createAnalysisState(() => /* @__PURE__ */ new Map());
1998
2023
  function trackFunction(fn, fnExtra, markoRoot) {
1999
- reserveExportRegisterId(fnExtra, fn, markoRoot);
2024
+ reserveExportRegistryId(fnExtra, fn, markoRoot);
2000
2025
  if (isStatic(markoRoot)) {
2001
- const refs = getStaticDeclRefs(fn);
2002
- if (refs.size) getReferencesByFn().set(fnExtra, refs);
2026
+ const exprs = getStaticDeclExprs(fn);
2027
+ if (exprs.size) getReferencesByFn().set(fnExtra, exprs);
2003
2028
  } else getReferencesByFn().set(fnExtra, /* @__PURE__ */ new Set([fnExtra.exprRoot]));
2004
2029
  }
2005
2030
  function canIgnoreRegister(markoRoot, exprRoot) {
@@ -2015,7 +2040,7 @@ function finalizeRegistrations() {
2015
2040
  const programExtra = (0, _marko_compiler_babel_utils.getProgram)().node.extra;
2016
2041
  for (const fnExtra of getReferencesByFn().keys()) if (fnExtra.reason) {
2017
2042
  registerFunction(fnExtra);
2018
- programExtra.isInteractive ||= isUnconditionalReason(fnExtra.reason);
2043
+ programExtra.isInteractive ||= !isGuardedReason(fnExtra.reason);
2019
2044
  }
2020
2045
  for (const [{ node, local, registered, fnRoots }, exprExtras] of getReferencesByImport()) {
2021
2046
  const reason = fnRoots ? resolveTemplateReason(exprExtras) : resolveReason(exprExtras);
@@ -2025,7 +2050,7 @@ function finalizeRegistrations() {
2025
2050
  extra.registeredImports ??= /* @__PURE__ */ new Map();
2026
2051
  extra.registeredImports.set(local, registered);
2027
2052
  }
2028
- programExtra.isInteractive ||= isUnconditionalReason(reason);
2053
+ programExtra.isInteractive ||= !isGuardedReason(reason);
2029
2054
  }
2030
2055
  }
2031
2056
  }
@@ -2035,7 +2060,7 @@ function finalizeRegistrations() {
2035
2060
  */
2036
2061
  function trackImportedTemplate(importDecl, local, templateFile) {
2037
2062
  trackImport(importDecl, local, {
2038
- registerId: templateFile.metadata.marko.id,
2063
+ registryId: templateFile.metadata.marko.id,
2039
2064
  exportName: "default",
2040
2065
  filename: templateFile.opts.filename
2041
2066
  }, /* @__PURE__ */ new Set());
@@ -2048,14 +2073,14 @@ function trackImportedTemplate(importDecl, local, templateFile) {
2048
2073
  function trackImport(importDecl, local, registered, fnRoots) {
2049
2074
  const binding = registered && importDecl.scope.getBinding(local);
2050
2075
  if (!binding) return;
2051
- const refs = /* @__PURE__ */ new Set();
2052
- addBindingRefs(binding, refs, /* @__PURE__ */ new Set(), fnRoots);
2053
- if (refs.size) getReferencesByImport().set({
2076
+ const exprs = /* @__PURE__ */ new Set();
2077
+ addBindingExprs(binding, exprs, /* @__PURE__ */ new Set(), fnRoots);
2078
+ if (exprs.size) getReferencesByImport().set({
2054
2079
  node: importDecl.node,
2055
2080
  local,
2056
2081
  registered,
2057
2082
  fnRoots
2058
- }, refs);
2083
+ }, exprs);
2059
2084
  }
2060
2085
  /**
2061
2086
  * Finds the id reserved for an export, following `export ... from` hops. Each
@@ -2097,10 +2122,10 @@ function writeModuleRegistrations(program) {
2097
2122
  for (const child of program.node.body) {
2098
2123
  const registeredImports = _marko_compiler.types.isImportDeclaration(child) && child.extra?.registeredImports;
2099
2124
  if (registeredImports) for (const [local, registered] of registeredImports) {
2100
- if (seen.has(registered.registerId)) continue;
2101
- seen.add(registered.registerId);
2125
+ if (seen.has(registered.registryId)) continue;
2126
+ seen.add(registered.registryId);
2102
2127
  if (isOutputHTML()) {
2103
- if (registered.exportName !== "default") statements.push(buildRegistration(local, registered.registerId));
2128
+ if (registered.exportName !== "default") statements.push(buildRegistration(local, registered.registryId));
2104
2129
  } else (0, _marko_compiler_babel_utils.importDefault)(file, resolveRegisterModule(file, registered));
2105
2130
  }
2106
2131
  else if (child.type === "ExportNamedDeclaration") addExportRegistrations(child, seen, statements);
@@ -2110,7 +2135,7 @@ function writeModuleRegistrations(program) {
2110
2135
  function resolveReason(exprExtras) {
2111
2136
  let reason;
2112
2137
  for (const exprExtra of exprExtras) {
2113
- const extra = getCanonicalExtra(exprExtra);
2138
+ const extra = getCanonicalExpr(exprExtra);
2114
2139
  if (!exprExtra.consumed || extra.retained) reason = mergeSources(reason, landsRetained(extra) ? ALWAYS : getReasonForExpr(extra));
2115
2140
  }
2116
2141
  return reason;
@@ -2118,30 +2143,30 @@ function resolveReason(exprExtras) {
2118
2143
  function resolveTemplateReason(exprExtras) {
2119
2144
  let reason;
2120
2145
  for (const exprExtra of exprExtras) {
2121
- const extra = getCanonicalExtra(exprExtra);
2146
+ const extra = getCanonicalExpr(exprExtra);
2122
2147
  if (!extra.isEffect) reason = mergeSources(reason, getReasonForExpr(extra));
2123
2148
  }
2124
2149
  return reason;
2125
2150
  }
2126
2151
  function isTemplateShipped(fnRoots, exprExtras) {
2127
2152
  for (const fnRoot of fnRoots) if (isRegisteredFnExtra(fnRoot)) return true;
2128
- for (const exprExtra of exprExtras) if (getCanonicalExtra(exprExtra).isEffect) return true;
2153
+ for (const exprExtra of exprExtras) if (getCanonicalExpr(exprExtra).isEffect) return true;
2129
2154
  return false;
2130
2155
  }
2131
- function reserveExportRegisterId(fnExtra, fn, markoRoot) {
2156
+ function reserveExportRegistryId(fnExtra, fn, markoRoot) {
2132
2157
  if (!isStatic(markoRoot)) return;
2133
2158
  const exportNames = getExportNames(fn, markoRoot);
2134
2159
  const exportName = exportNames?.find((name) => _marko_compiler.types.isValidIdentifier(name));
2135
2160
  if (!exportName) return;
2136
2161
  const { markoOpts, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
2137
2162
  const programExtra = (0, _marko_compiler_babel_utils.getProgram)().node.extra;
2138
- const registerId = (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, `${fnExtra.section.id}/export/${exportName}`);
2163
+ const registryId = (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, `${fnExtra.section.id}/export/${exportName}`);
2139
2164
  const registered = {
2140
- registerId,
2165
+ registryId,
2141
2166
  exportName,
2142
2167
  filename
2143
2168
  };
2144
- fnExtra.exportRegisterId = registerId;
2169
+ fnExtra.exportRegistryId = registryId;
2145
2170
  programExtra[kRegisteredExports] ??= /* @__PURE__ */ new Map();
2146
2171
  for (const name of exportNames) programExtra[kRegisteredExports].set(name, registered);
2147
2172
  }
@@ -2164,19 +2189,19 @@ function getExportableName(fn) {
2164
2189
  if (node.type === "FunctionDeclaration") return node.id?.name;
2165
2190
  if (_marko_compiler.types.isVariableDeclarator(parent) && parent.init === node && _marko_compiler.types.isIdentifier(parent.id) && _marko_compiler.types.isVariableDeclaration(fn.parentPath.parent, { kind: "const" })) return parent.id.name;
2166
2191
  }
2167
- function getStaticDeclRefs(path$11, refs = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new Set(), fnRoots) {
2168
- const decl = getDeclarationRoot(path$11);
2192
+ function getStaticDeclExprs(path$10, exprs = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new Set(), fnRoots) {
2193
+ const decl = getDeclarationRoot(path$10);
2169
2194
  if (decl && !seen.has(decl.node)) {
2170
2195
  seen.add(decl.node);
2171
2196
  const ids = decl.getOuterBindingIdentifiers();
2172
2197
  if (ids) for (const name in ids) {
2173
2198
  const binding = decl.scope.getBinding(name);
2174
- if (binding) addBindingRefs(binding, refs, seen, fnRoots);
2199
+ if (binding) addBindingExprs(binding, exprs, seen, fnRoots);
2175
2200
  }
2176
2201
  }
2177
- return refs;
2202
+ return exprs;
2178
2203
  }
2179
- function addBindingRefs(binding, refs, seen, fnRoots) {
2204
+ function addBindingExprs(binding, exprs, seen, fnRoots) {
2180
2205
  for (const ref of binding.referencePaths) {
2181
2206
  if (isInvokedFunction(ref) || ref.parentPath.type === "Program") continue;
2182
2207
  const exprRoot = getExprRoot(ref);
@@ -2186,41 +2211,41 @@ function addBindingRefs(binding, refs, seen, fnRoots) {
2186
2211
  const fnRoot = getFnRoot(ref);
2187
2212
  if (fnRoot) fnRoots.add(fnRoot.node.extra ??= {});
2188
2213
  }
2189
- if (isStatic(markoRoot)) getStaticDeclRefs(ref, refs, seen, fnRoots);
2190
- else refs.add(exprRoot.node.extra ??= {});
2214
+ if (isStatic(markoRoot)) getStaticDeclExprs(ref, exprs, seen, fnRoots);
2215
+ else exprs.add(exprRoot.node.extra ??= {});
2191
2216
  }
2192
2217
  }
2193
2218
  function registerFunction(fnExtra) {
2194
2219
  const { markoOpts, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
2195
2220
  fnExtra.name = generateUid(fnExtra.name);
2196
- fnExtra.registerId = fnExtra.exportRegisterId ?? (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, `${fnExtra.section.id}/${fnExtra.name.slice(1)}`);
2221
+ fnExtra.registryId = fnExtra.exportRegistryId ?? (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, `${fnExtra.section.id}/${fnExtra.name.slice(1)}`);
2197
2222
  }
2198
2223
  function addExportRegistrations(node, seen, statements) {
2199
2224
  const { declaration } = node;
2200
2225
  if (!declaration) return;
2201
- const add = (local, registerId) => {
2202
- if (seen.has(registerId)) return;
2203
- seen.add(registerId);
2204
- statements.push(buildRegistration(local, registerId));
2226
+ const add = (local, registryId) => {
2227
+ if (seen.has(registryId)) return;
2228
+ seen.add(registryId);
2229
+ statements.push(buildRegistration(local, registryId));
2205
2230
  };
2206
2231
  if (declaration.type === "FunctionDeclaration") {
2207
- if (isRegisteredFnExtra(declaration.extra)) add(declaration.id.name, declaration.extra.registerId);
2232
+ if (isRegisteredFnExtra(declaration.extra)) add(declaration.id.name, declaration.extra.registryId);
2208
2233
  return;
2209
2234
  }
2210
2235
  if (isOutputHTML() || declaration.type !== "VariableDeclaration") return;
2211
2236
  for (const declarator of declaration.declarations) {
2212
2237
  const extra = declarator.init?.extra;
2213
- if (isRegisteredFnExtra(extra) && _marko_compiler.types.isIdentifier(declarator.id)) add(declarator.id.name, extra.registerId);
2238
+ if (isRegisteredFnExtra(extra) && _marko_compiler.types.isIdentifier(declarator.id)) add(declarator.id.name, extra.registryId);
2214
2239
  }
2215
2240
  }
2216
- function buildRegistration(local, registerId) {
2217
- return _marko_compiler.types.expressionStatement(isOutputHTML() ? callRuntime("_resume", _marko_compiler.types.identifier(local), _marko_compiler.types.stringLiteral(registerId)) : registerRuntimeValue(registerId, _marko_compiler.types.identifier(local)));
2241
+ function buildRegistration(local, registryId) {
2242
+ return _marko_compiler.types.expressionStatement(isOutputHTML() ? callRuntime("_resume", _marko_compiler.types.identifier(local), _marko_compiler.types.stringLiteral(registryId)) : registerRuntimeValue(registryId, _marko_compiler.types.identifier(local)));
2218
2243
  }
2219
- function resolveRegisterModule(file, { filename, exportName, registerId }) {
2244
+ function resolveRegisterModule(file, { filename, exportName, registryId }) {
2220
2245
  const importer = file.opts.filename;
2221
2246
  return getMarkoOpts().resolveVirtualDependency(importer, {
2222
2247
  virtualPath: `${relativePath(importer, filename)}.register-${exportName}.js`,
2223
- code: `import { ${exportName} as value } from "./${path.default.basename(filename)}";\nimport { _resumed } from "${getRuntimePath("dom")}";\n_resumed${isValidPropertyIdentifier(registerId) ? `.${registerId}` : `[${JSON.stringify(registerId)}]`} = value;\n`
2248
+ code: `import { ${exportName} as value } from "./${path.default.basename(filename)}";\nimport { _resumed } from "${getRuntimePath("dom")}";\n_resumed${isValidPropertyIdentifier(registryId) ? `.${registryId}` : `[${JSON.stringify(registryId)}]`} = value;\n`
2224
2249
  });
2225
2250
  }
2226
2251
  function relativePath(from, to) {
@@ -2276,12 +2301,13 @@ function getBranchExprReason(section) {
2276
2301
  const { derives, branchExpr } = section;
2277
2302
  if (derives) {
2278
2303
  let reason = mergeSources(getRendererReason(section) || void 0, getSourcesForDerived(derives));
2279
- forEach(section.callSections, (callSection) => {
2304
+ forEach(section.renderedBy, (call) => {
2305
+ const callSection = call.childScopeBinding.section;
2280
2306
  reason = mergeSources(reason, getBranchExprReasonUntil(callSection, isSameOrAncestorSection(section, callSection) ? section : section.parent));
2281
2307
  });
2282
2308
  return reason;
2283
2309
  }
2284
- if (section.branch?.await) return;
2310
+ if (section.branch?.kind === "await") return;
2285
2311
  return branchExpr ? getSourcesForExpr(branchExpr) : ALWAYS;
2286
2312
  }
2287
2313
  function getBranchExprReasonUntil(section, ancestor) {
@@ -2304,7 +2330,8 @@ function addClosureReasons(section) {
2304
2330
  });
2305
2331
  }
2306
2332
  function addCallOwnerReasons(body) {
2307
- if (body.readsOwner) forEach(body.callSections, (callSection) => {
2333
+ if (body.readsOwner) forEach(body.renderedBy, (call) => {
2334
+ const callSection = call.childScopeBinding.section;
2308
2335
  addOwnerReason(callSection, body.parent, getBranchExprReasonUntil(callSection, body.parent));
2309
2336
  });
2310
2337
  }
@@ -2322,33 +2349,52 @@ function addRegisteredFnReasons(fnReadsByExpression) {
2322
2349
  }
2323
2350
  }
2324
2351
  }
2352
+ const LANDS_RETAINED = 1;
2353
+ const LANDS_RETAINED_INPUT = 2;
2354
+ const LANDS_UNSEEN = 4;
2325
2355
  const UNREAD = {
2326
2356
  reason: void 0,
2327
- reads: void 0
2357
+ lands: 0
2328
2358
  };
2329
2359
  const ALWAYS_READ = {
2330
2360
  reason: ALWAYS,
2331
- reads: void 0
2361
+ lands: 0
2362
+ };
2363
+ const UNSEEN_READ = {
2364
+ reason: void 0,
2365
+ lands: LANDS_UNSEEN
2366
+ };
2367
+ const RETAINED_TAG_NAME_READ = {
2368
+ reason: void 0,
2369
+ lands: LANDS_RETAINED
2370
+ };
2371
+ const RETAINED_INPUT_READ = {
2372
+ reason: void 0,
2373
+ lands: 3
2332
2374
  };
2333
- const extraReaders = createPassMemo(computeExtraReaders, UNREAD);
2375
+ const exprReaders = createPassMemo(computeExprReaders, UNREAD);
2334
2376
  const bindingReaders = createPassPathMemo(computeBindingReaders, UNREAD);
2335
2377
  function getReasonForBinding(binding, properties) {
2336
2378
  return bindingReaders(binding, properties).reason;
2337
2379
  }
2338
2380
  function getReasonForExpr(extra) {
2339
- return extra.isEffect ? ALWAYS : extraReaders(extra).reason;
2381
+ return extra.isEffect ? ALWAYS : exprReaders(extra).reason;
2382
+ }
2383
+ function bindingLandsRetained(binding, properties) {
2384
+ return !!(bindingReaders(binding, properties).lands & LANDS_RETAINED_INPUT);
2385
+ }
2386
+ function getContentSites({ binding, properties }) {
2387
+ const { lands, sites, deepSites } = reduce(binding, (readers, part) => mergeReaders(readers, bindingReaders(part, properties)), UNREAD);
2388
+ return {
2389
+ unseen: !!(lands & LANDS_UNSEEN),
2390
+ sites,
2391
+ deepSites
2392
+ };
2340
2393
  }
2341
2394
  function landsRetained(extra) {
2342
- if (extra.retained) return true;
2343
- if (!extra.isEffect) {
2344
- const { reads } = extraReaders(extra);
2345
- if (reads) {
2346
- for (const read of reads) if (read.retained) return true;
2347
- }
2348
- }
2349
- return false;
2395
+ return !!extra.retained || !extra.isEffect && !!(exprReaders(extra).lands & LANDS_RETAINED);
2350
2396
  }
2351
- function computeExtraReaders(extra) {
2397
+ function computeExprReaders(extra) {
2352
2398
  return readersOfDerives(extra, void 0);
2353
2399
  }
2354
2400
  function readersOfDerives(extra, part, properties) {
@@ -2362,9 +2408,10 @@ function readersOfDerives(extra, part, properties) {
2362
2408
  function readersOfDerived(extra, binding, part, properties) {
2363
2409
  const linked = bindingReaders(binding, getDerivedPath(extra, binding, part, properties));
2364
2410
  const exprs = extra.callSiteExprs;
2365
- return linked.reason && exprs ? {
2366
- reason: mapParamReason(binding.section.program, linked.reason, exprs, true),
2367
- reads: linked.reads
2411
+ return exprs && (linked.reason || linked.sites) ? {
2412
+ reason: linked.reason && mapParamReason(binding.section.program, linked.reason, exprs, true),
2413
+ lands: linked.lands,
2414
+ deepSites: mergeSites(linked.deepSites, linked.sites)
2368
2415
  } : linked;
2369
2416
  }
2370
2417
  function getDerivedPath(extra, binding, part, properties) {
@@ -2379,7 +2426,7 @@ function getDerivedPath(extra, binding, part, properties) {
2379
2426
  }
2380
2427
  function isReferenceTo(extra, binding) {
2381
2428
  const { read } = extra;
2382
- return !!read && read.props === void 0 && getCanonicalBinding(read.binding) === getCanonicalBinding(binding);
2429
+ return !!read && read.properties === void 0 && getCanonicalBinding(read.binding) === getCanonicalBinding(binding);
2383
2430
  }
2384
2431
  function isPartOf(binding, value) {
2385
2432
  return !!value && binding.aliasOf === value && !isDirectAlias(binding);
@@ -2389,7 +2436,7 @@ function computeBindingReaders(binding, properties) {
2389
2436
  const reason = findSlot(binding)?.reason;
2390
2437
  let readers = reason ? {
2391
2438
  reason,
2392
- reads: void 0
2439
+ lands: 0
2393
2440
  } : UNREAD;
2394
2441
  const aliased = binding.aliasOf;
2395
2442
  if (properties !== true && aliased) readers = mergeReaders(readers, bindingReaders(aliased, properties === void 0 ? binding.property : concat(binding.property, properties)));
@@ -2398,7 +2445,9 @@ function computeBindingReaders(binding, properties) {
2398
2445
  if (!(head === "content" && expr.rendersContent && bindingUtil.has(expr.spreadFrom, binding))) readers = mergeReaders(readers, ALWAYS_READ);
2399
2446
  continue;
2400
2447
  }
2401
- readers = mergeReaders(withLandingRead(readers, expr), readersOfDerives(expr, binding, properties));
2448
+ readers = mergeReaders(readers, landingReaders(expr, binding));
2449
+ readers = mergeReaders(readers, renderingReaders(expr, binding));
2450
+ readers = mergeReaders(readers, readersOfDerives(expr, binding, properties));
2402
2451
  }
2403
2452
  for (const alias of binding.aliases) readers = mergeReaders(readers, bindingReaders(alias, properties));
2404
2453
  if (properties === void 0) return readers;
@@ -2407,7 +2456,7 @@ function computeBindingReaders(binding, properties) {
2407
2456
  return readers;
2408
2457
  }
2409
2458
  const property = first(properties);
2410
- if (propsUtil.has(binding.excludeProperties, property)) return UNREAD;
2459
+ if (propertiesUtil.has(binding.excludeProperties, property)) return UNREAD;
2411
2460
  readers = mergePropertyReaders(readers, binding, property, properties);
2412
2461
  for (const alias of binding.aliases) readers = mergePropertyReaders(readers, alias, property, properties);
2413
2462
  return readers;
@@ -2420,25 +2469,35 @@ function mergeReaders(a, b) {
2420
2469
  if (a === UNREAD) return b;
2421
2470
  if (b === UNREAD) return a;
2422
2471
  const reason = mergeSources(a.reason, b.reason);
2423
- const reads = unionReads(a.reads, b.reads);
2424
- if (reason === a.reason && reads === a.reads) return a;
2425
- if (reason === b.reason && reads === b.reads) return b;
2472
+ const lands = a.lands | b.lands;
2473
+ const sites = mergeSites(a.sites, b.sites);
2474
+ const deepSites = mergeSites(a.deepSites, b.deepSites);
2475
+ if (reason === a.reason && lands === a.lands && sites === a.sites && deepSites === a.deepSites) return a;
2476
+ if (reason === b.reason && lands === b.lands && sites === b.sites && deepSites === b.deepSites) return b;
2426
2477
  return {
2427
2478
  reason,
2428
- reads
2479
+ lands,
2480
+ sites,
2481
+ deepSites
2429
2482
  };
2430
2483
  }
2431
- function withLandingRead(readers, read) {
2432
- return readers.reads?.has(read) ? readers : {
2433
- reason: readers.reason,
2434
- reads: new Set(readers.reads).add(read)
2435
- };
2484
+ function mergeSites(a, b) {
2485
+ return reduce(b, (sites, site) => some(sites, (held) => held === site) ? sites : push(sites, site), a);
2436
2486
  }
2437
- function unionReads(a, b) {
2438
- if (!a || !b || a === b) return a || b;
2439
- let result;
2440
- for (const read of b) if (!a.has(read)) (result ??= new Set(a)).add(read);
2441
- return result || a;
2487
+ function landingReaders(read, binding) {
2488
+ return !read.retained ? UNREAD : every(binding.reads.get(read), isTagNameRead) ? RETAINED_TAG_NAME_READ : RETAINED_INPUT_READ;
2489
+ }
2490
+ function isTagNameRead({ extra }) {
2491
+ return !!extra.exprRoot?.tagName;
2492
+ }
2493
+ function renderingReaders(expr, binding) {
2494
+ const reads = binding.reads.get(expr);
2495
+ if (reads && every(reads, isTagNameRead)) return {
2496
+ reason: void 0,
2497
+ lands: 0,
2498
+ sites: first(reads).extra.exprRoot.tagName
2499
+ };
2500
+ return expr.derives ? UNREAD : UNSEEN_READ;
2442
2501
  }
2443
2502
  //#endregion
2444
2503
  //#region src/common/helpers.ts
@@ -2534,103 +2593,335 @@ function isNullishOrFalse(value) {
2534
2593
  }
2535
2594
  const decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36);
2536
2595
  //#endregion
2537
- //#region src/translator/util/tag-import.ts
2538
- const triggerRegExp = /\s*([\w-]+)\s*([^?|]+?)?\s*(?:\?([^|]*?))?\s*(?:\||$)/g;
2539
- const derivedImports = /* @__PURE__ */ new WeakSet();
2540
- function importOrSelfReferenceName(file, request, name, nameHint) {
2541
- if (isCircularRequest(file, request)) return _marko_compiler.types.identifier(name);
2542
- return (0, _marko_compiler_babel_utils.importNamed)(file, request, name, nameHint);
2596
+ //#region src/common/errors.ts
2597
+ const lowercaseOnAttrReg = /^on[a-z]/;
2598
+ function assertExclusiveAttrs(attrs, onError = throwErr, isSet = isTruthy) {
2599
+ if (attrs) {
2600
+ let exclusiveAttrs;
2601
+ if (isSet(attrs.checkedChange)) (exclusiveAttrs ||= []).push("checkedChange");
2602
+ if ("checkedValue" in attrs) {
2603
+ (exclusiveAttrs ||= []).push("checkedValue");
2604
+ if ("checked" in attrs) exclusiveAttrs.push("checked");
2605
+ } else if (isSet(attrs.checkedValueChange)) {
2606
+ (exclusiveAttrs ||= []).push("checkedValueChange");
2607
+ if ("checked" in attrs) exclusiveAttrs.push("checked");
2608
+ }
2609
+ if (isSet(attrs.valueChange)) {
2610
+ (exclusiveAttrs ||= []).push("valueChange");
2611
+ if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
2612
+ }
2613
+ if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
2614
+ }
2543
2615
  }
2544
- function isCircularRequest(file, request) {
2545
- const { filename } = file.opts;
2546
- return request === filename || request[0] === "." && path.default.resolve(filename, "..", request) === filename;
2616
+ function isTruthy(value) {
2617
+ return value;
2547
2618
  }
2548
- function trackTagImport(tagImport) {
2549
- const tags = (0, _marko_compiler_babel_utils.getFile)().metadata.marko.tags;
2550
- if (!tags.includes(tagImport)) tags.push(tagImport);
2619
+ function throwErr(msg) {
2620
+ throw new Error(msg);
2551
2621
  }
2552
- function getImportFacts(importDecl) {
2553
- const { node } = importDecl;
2554
- const extra = node.extra ??= {};
2555
- if (!derivedImports.has(node)) {
2556
- derivedImports.add(node);
2557
- const tagImport = (0, _marko_compiler_babel_utils.resolveTagImport)(importDecl, node.source.value);
2558
- if (tagImport) extra.tagImport = tagImport;
2559
- const loadAttrPath = getLoadAttr(importDecl);
2560
- const loadImport = loadAttrPath && getLoadImportConfig(loadAttrPath.get("value"));
2561
- if (loadImport && getMarkoOpts().linkAssets) extra.loadImport = loadImport;
2622
+ function joinWithAnd(a) {
2623
+ switch (a.length) {
2624
+ case 0: return "";
2625
+ case 1: return a[0];
2626
+ case 2: return `${a[0]} and ${a[1]}`;
2627
+ default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
2562
2628
  }
2563
- return extra;
2564
2629
  }
2565
- function getLoadAttr(importDecl) {
2566
- return importDecl.node.attributes?.length ? importDecl.get("attributes").find((p) => getLiteralName(p.node.key) === "load") : void 0;
2630
+ //#endregion
2631
+ //#region src/html/attrs.ts
2632
+ function _attr_class(value) {
2633
+ return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
2567
2634
  }
2568
- function getLoadImportConfig(attrValue) {
2569
- const raw = attrValue.node.value;
2570
- if (raw === "render") return { render: true };
2571
- const triggers = [];
2572
- for (const match of raw.matchAll(triggerRegExp)) {
2573
- const type = parseTriggerType(match[1]);
2574
- const selector = match[2];
2575
- const query = match[3];
2576
- if (!type) throw attrValue.buildCodeFrameError(`Unknown trigger type "${match[1]}". Supported triggers are "visible", "idle", "media", and "on*".`);
2577
- if (type === "render") throw attrValue.buildCodeFrameError("The \"render\" trigger must be used alone.");
2578
- if (type === "idle") {
2579
- if (selector) throw attrValue.buildCodeFrameError(`Selector is not supported for the "idle" trigger.`);
2580
- } else if (!selector) throw attrValue.buildCodeFrameError(type === "media" ? `A media query is required for the "media" trigger. (e.g. "media(max-width:768px)")` : `A selector is required for the "${type}" trigger. (e.g. "${type}.my-element")`);
2581
- const trigger = selector ? {
2582
- type,
2583
- selector
2584
- } : { type };
2585
- if (query) {
2586
- const params = new URLSearchParams(query);
2587
- switch (type) {
2588
- case "visible": {
2589
- let rootMargin;
2590
- for (const [key, value] of params) {
2591
- if (key !== "rootMargin") throw attrValue.buildCodeFrameError(`Unknown param "${key}" for the "visible" trigger. Supported params: "rootMargin".`);
2592
- rootMargin = value;
2593
- }
2594
- if (rootMargin) trigger.options = { rootMargin };
2595
- break;
2596
- }
2597
- case "idle": {
2598
- let timeout;
2599
- for (const [key, value] of params) {
2600
- if (key !== "timeout") throw attrValue.buildCodeFrameError(`Unknown param "${key}" for the "idle" trigger. Supported params: "timeout".`);
2601
- timeout = Number(value);
2602
- }
2603
- if (timeout) trigger.options = { timeout };
2604
- break;
2605
- }
2606
- default: throw attrValue.buildCodeFrameError(`Params are not supported for the "${type}" trigger.`);
2607
- }
2608
- }
2609
- triggers.push(trigger);
2610
- }
2611
- if (!triggers.length) throw attrValue.buildCodeFrameError("The \"load\" attribute requires \"render\" or at least one trigger (e.g. \"visible.my-element\").");
2612
- return {
2613
- render: false,
2614
- triggers
2615
- };
2635
+ function _attr_style(value) {
2636
+ return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
2616
2637
  }
2617
- function parseTriggerType(type) {
2618
- switch (type) {
2619
- case "idle":
2620
- case "media":
2621
- case "render":
2622
- case "visible": return type;
2623
- default: return isEventHandler(type) ? `on-${getEventType(type)}` : void 0;
2638
+ function _attr(name, value) {
2639
+ return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
2640
+ }
2641
+ function stringAttr(name, value) {
2642
+ return value && " " + name + attrAssignment(value);
2643
+ }
2644
+ function stringifyAttr(name, value) {
2645
+ switch (typeof value) {
2646
+ case "string": return " " + name + attrAssignment(value);
2647
+ case "boolean": return " " + name;
2648
+ case "number": return " " + name + "=" + value;
2624
2649
  }
2650
+ return " " + name + attrAssignment(value + "");
2625
2651
  }
2626
- //#endregion
2627
- //#region src/translator/util/tag-name-type.ts
2628
- const kTagNameDynamic = Symbol("tag name dynamic");
2629
- const MARKO_FILE_REG = /^<.*>$|\.marko$/;
2630
- const TAG_NAME_IDENTIFIER_REG$1 = /^[A-Z][a-zA-Z0-9_$]*$/;
2631
- function analyzeTagNameType(tag) {
2632
- const extra = tag.node.extra ??= {};
2633
- if (extra.tagNameType === void 0) {
2652
+ const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
2653
+ const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
2654
+ const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
2655
+ function attrAssignment(value) {
2656
+ return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
2657
+ }
2658
+ function escapeSingleQuotedAttrValue(value) {
2659
+ return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
2660
+ }
2661
+ function replaceUnsafeSingleQuoteAttrChar(match) {
2662
+ return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
2663
+ }
2664
+ function escapeDoubleQuotedAttrValue(value) {
2665
+ return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
2666
+ }
2667
+ function replaceUnsafeDoubleQuoteAttrChar(match) {
2668
+ return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
2669
+ }
2670
+ //#endregion
2671
+ //#region src/html/writer.ts
2672
+ let $chunk;
2673
+ function getState() {
2674
+ return $chunk.boundary.state;
2675
+ }
2676
+ globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
2677
+ //#endregion
2678
+ //#region src/html/content.ts
2679
+ var content_exports = /* @__PURE__ */ __exportAll({
2680
+ _escape: () => _escape,
2681
+ _escape_comment: () => _escape_comment,
2682
+ _escape_script: () => _escape_script,
2683
+ _escape_style: () => _escape_style,
2684
+ _escape_style_value: () => _escape_style_value,
2685
+ _to_text: () => _to_text,
2686
+ _unescaped: () => _unescaped,
2687
+ quoteScriptTemplateLiteral: () => quoteScriptTemplateLiteral
2688
+ });
2689
+ function _to_text(val) {
2690
+ return val || val === 0 ? val + "" : "";
2691
+ }
2692
+ function _unescaped(val) {
2693
+ return val ? val + "" : val === 0 ? "0" : "";
2694
+ }
2695
+ const unsafeXMLReg = /[<&\r]/g;
2696
+ const replaceUnsafeXML = (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&#13;";
2697
+ const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
2698
+ function _escape(val) {
2699
+ return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
2700
+ }
2701
+ const unsafeScriptReg = /<(\/?script|!--)/gi;
2702
+ const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\u003C$1") : str;
2703
+ function _escape_script(val) {
2704
+ return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
2705
+ }
2706
+ const unsafeScriptTemplateLiteralReg = /[`\\\r]|\$\{|<(?=\/?script|!--)/gi;
2707
+ const replaceUnsafeScriptTemplateLiteral = (c) => c === "<" ? "\\x3C" : c === "\r" ? "\\r" : "\\" + c;
2708
+ const quoteScriptTemplateLiteral = (str) => "`" + (unsafeScriptTemplateLiteralReg.test(str) ? str.replace(unsafeScriptTemplateLiteralReg, replaceUnsafeScriptTemplateLiteral) : str) + "`";
2709
+ const unsafeStyleReg = /<(\/style)/gi;
2710
+ const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
2711
+ function _escape_style(val) {
2712
+ return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
2713
+ }
2714
+ function _escape_style_value(val) {
2715
+ return val || val === 0 ? escapeStyleValue(val + "") : "";
2716
+ }
2717
+ const unsafeCommentReg = />/g;
2718
+ function escapeCommentStr(str) {
2719
+ if (unsafeCommentReg.test(str)) str = str.replace(unsafeCommentReg, "&gt;");
2720
+ return str.startsWith(getState().commentPrefix) ? "&#" + str.charCodeAt(0) + ";" + str.slice(1) : str;
2721
+ }
2722
+ function _escape_comment(val) {
2723
+ return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
2724
+ }
2725
+ //#endregion
2726
+ //#region src/translator/util/evaluate.ts
2727
+ const kEvaluated = Symbol("evaluated");
2728
+ function evaluate(value) {
2729
+ return (value.extra ??= {})[kEvaluated] ??= computeEvaluated(value);
2730
+ }
2731
+ function computeEvaluated(value) {
2732
+ const computed = (0, _marko_compiler_babel_utils.computeNode)(value);
2733
+ return computed ? {
2734
+ confident: true,
2735
+ computed: computed.value,
2736
+ nullable: computed.value == null,
2737
+ pure: true
2738
+ } : {
2739
+ confident: false,
2740
+ computed: void 0,
2741
+ nullable: isNullableExpr(value),
2742
+ pure: !traverseContains(value, isImpure)
2743
+ };
2744
+ }
2745
+ function isImpure(node) {
2746
+ switch (node.type) {
2747
+ case "ArrowFunctionExpression":
2748
+ case "ClassPrivateMethod":
2749
+ case "ClassPrivateProperty":
2750
+ case "FunctionExpression": return skip;
2751
+ case "ClassMethod":
2752
+ case "ObjectMethod": return node.computed && traverseContains(node.key, isImpure) || skip;
2753
+ case "ClassAccessorProperty":
2754
+ case "ClassProperty": return node.static ? void 0 : node.computed && traverseContains(node.key, isImpure) || skip;
2755
+ case "CallExpression": return node.callee.type === "ArrowFunctionExpression" || node.callee.type === "FunctionExpression" ? traverseContains(node.arguments, isImpure) || traverseContains(node.callee.params, isImpure) || traverseContains(node.callee.body, isImpure) || skip : true;
2756
+ case "AssignmentExpression":
2757
+ case "NewExpression":
2758
+ case "OptionalCallExpression":
2759
+ case "TaggedTemplateExpression":
2760
+ case "ThrowStatement":
2761
+ case "UpdateExpression": return true;
2762
+ case "UnaryExpression": return node.operator === "delete";
2763
+ }
2764
+ }
2765
+ function isNullableExpr(expr) {
2766
+ switch (expr.type) {
2767
+ case "ArrayExpression":
2768
+ case "ArrowFunctionExpression":
2769
+ case "BigIntLiteral":
2770
+ case "BinaryExpression":
2771
+ case "BooleanLiteral":
2772
+ case "ClassExpression":
2773
+ case "FunctionExpression":
2774
+ case "NewExpression":
2775
+ case "NumericLiteral":
2776
+ case "ObjectExpression":
2777
+ case "RegExpLiteral":
2778
+ case "StringLiteral":
2779
+ case "TemplateLiteral":
2780
+ case "UpdateExpression": return false;
2781
+ case "AssignmentExpression": switch (expr.operator) {
2782
+ case "=": return isNullableExpr(expr.right);
2783
+ case "*=":
2784
+ case "/=":
2785
+ case "%=":
2786
+ case "+=":
2787
+ case "-=":
2788
+ case "<<=":
2789
+ case ">>=":
2790
+ case ">>>=":
2791
+ case "&=":
2792
+ case "^=":
2793
+ case "|=":
2794
+ case "**=": return false;
2795
+ case "||=":
2796
+ case "??=": return isNullableExpr(expr.right);
2797
+ case "&&=": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
2798
+ default: return true;
2799
+ }
2800
+ case "AwaitExpression": return isNullableExpr(expr.argument);
2801
+ case "ConditionalExpression": return isNullableExpr(expr.consequent) || isNullableExpr(expr.alternate);
2802
+ case "LogicalExpression": switch (expr.operator) {
2803
+ case "||":
2804
+ case "??": return isNullableExpr(expr.right);
2805
+ case "&&": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
2806
+ default: return true;
2807
+ }
2808
+ case "ParenthesizedExpression": return isNullableExpr(expr.expression);
2809
+ case "SequenceExpression": return isNullableExpr(expr.expressions[expr.expressions.length - 1]);
2810
+ case "UnaryExpression": return expr.operator === "void";
2811
+ default: return true;
2812
+ }
2813
+ }
2814
+ //#endregion
2815
+ //#region src/translator/util/static-text.ts
2816
+ function isStaticText(node) {
2817
+ switch (node?.type) {
2818
+ case "MarkoText": return true;
2819
+ case "MarkoPlaceholder": return getPlaceholderContentType(node) === 4;
2820
+ }
2821
+ }
2822
+ function followsStaticText(path) {
2823
+ let prev = path.getPrevSibling();
2824
+ while (prev.node && getNodeContentType(prev, "endType") === null) prev = prev.getPrevSibling();
2825
+ return isStaticText(prev.node);
2826
+ }
2827
+ function getPlaceholderContentType(placeholder) {
2828
+ const text = getStaticPlaceholderText(placeholder);
2829
+ return text === "" ? null : text !== void 0 && placeholder.escape ? 4 : 2;
2830
+ }
2831
+ function getStaticPlaceholderText(placeholder) {
2832
+ const { confident, computed } = evaluate(placeholder.value);
2833
+ if (confident) return placeholder.escape ? _escape(computed) : _unescaped(computed);
2834
+ }
2835
+ //#endregion
2836
+ //#region src/translator/util/tag-import.ts
2837
+ const triggerRegExp = /\s*([\w-]+)\s*([^?|]+?)?\s*(?:\?([^|]*?))?\s*(?:\||$)/g;
2838
+ const derivedImports = /* @__PURE__ */ new WeakSet();
2839
+ function trackTagImport(tagImport) {
2840
+ const tags = (0, _marko_compiler_babel_utils.getFile)().metadata.marko.tags;
2841
+ if (!tags.includes(tagImport)) tags.push(tagImport);
2842
+ }
2843
+ function getImportFacts(importDecl) {
2844
+ const { node } = importDecl;
2845
+ const extra = node.extra ??= {};
2846
+ if (!derivedImports.has(node)) {
2847
+ derivedImports.add(node);
2848
+ const tagImport = (0, _marko_compiler_babel_utils.resolveTagImport)(importDecl, node.source.value);
2849
+ if (tagImport) extra.tagImport = tagImport;
2850
+ const loadAttrPath = getLoadAttr(importDecl);
2851
+ const loadImport = loadAttrPath && getLoadImportConfig(loadAttrPath.get("value"));
2852
+ if (loadImport && getMarkoOpts().linkAssets) extra.loadImport = loadImport;
2853
+ }
2854
+ return extra;
2855
+ }
2856
+ function getLoadAttr(importDecl) {
2857
+ return importDecl.node.attributes?.length ? importDecl.get("attributes").find((p) => getLiteralName(p.node.key) === "load") : void 0;
2858
+ }
2859
+ function getLoadImportConfig(attrValue) {
2860
+ const raw = attrValue.node.value;
2861
+ if (raw === "render") return { render: true };
2862
+ const triggers = [];
2863
+ for (const match of raw.matchAll(triggerRegExp)) {
2864
+ const type = parseTriggerType(match[1]);
2865
+ const selector = match[2];
2866
+ const query = match[3];
2867
+ if (!type) throw attrValue.buildCodeFrameError(`Unknown trigger type "${match[1]}". Supported triggers are "visible", "idle", "media", and "on*".`);
2868
+ if (type === "render") throw attrValue.buildCodeFrameError("The \"render\" trigger must be used alone.");
2869
+ if (type === "idle") {
2870
+ if (selector) throw attrValue.buildCodeFrameError(`Selector is not supported for the "idle" trigger.`);
2871
+ } else if (!selector) throw attrValue.buildCodeFrameError(type === "media" ? `A media query is required for the "media" trigger. (e.g. "media(max-width:768px)")` : `A selector is required for the "${type}" trigger. (e.g. "${type}.my-element")`);
2872
+ const trigger = selector ? {
2873
+ type,
2874
+ selector
2875
+ } : { type };
2876
+ if (query) {
2877
+ const params = new URLSearchParams(query);
2878
+ switch (type) {
2879
+ case "visible": {
2880
+ let rootMargin;
2881
+ for (const [key, value] of params) {
2882
+ if (key !== "rootMargin") throw attrValue.buildCodeFrameError(`Unknown param "${key}" for the "visible" trigger. Supported params: "rootMargin".`);
2883
+ rootMargin = value;
2884
+ }
2885
+ if (rootMargin) trigger.options = { rootMargin };
2886
+ break;
2887
+ }
2888
+ case "idle": {
2889
+ let timeout;
2890
+ for (const [key, value] of params) {
2891
+ if (key !== "timeout") throw attrValue.buildCodeFrameError(`Unknown param "${key}" for the "idle" trigger. Supported params: "timeout".`);
2892
+ timeout = Number(value);
2893
+ }
2894
+ if (timeout) trigger.options = { timeout };
2895
+ break;
2896
+ }
2897
+ default: throw attrValue.buildCodeFrameError(`Params are not supported for the "${type}" trigger.`);
2898
+ }
2899
+ }
2900
+ triggers.push(trigger);
2901
+ }
2902
+ if (!triggers.length) throw attrValue.buildCodeFrameError("The \"load\" attribute requires \"render\" or at least one trigger (e.g. \"visible.my-element\").");
2903
+ return {
2904
+ render: false,
2905
+ triggers
2906
+ };
2907
+ }
2908
+ function parseTriggerType(type) {
2909
+ switch (type) {
2910
+ case "idle":
2911
+ case "media":
2912
+ case "render":
2913
+ case "visible": return type;
2914
+ default: return isEventHandler(type) ? `on-${getEventType(type)}` : void 0;
2915
+ }
2916
+ }
2917
+ //#endregion
2918
+ //#region src/translator/util/tag-name-type.ts
2919
+ const kTagNameDynamic = Symbol("tag name dynamic");
2920
+ const MARKO_FILE_REG = /^<.*>$|\.marko$/;
2921
+ const TAG_NAME_IDENTIFIER_REG$1 = /^[A-Z][a-zA-Z0-9_$]*$/;
2922
+ function analyzeTagNameType(tag) {
2923
+ const extra = tag.node.extra ??= {};
2924
+ if (extra.tagNameType === void 0) {
2634
2925
  const name = tag.get("name");
2635
2926
  let load;
2636
2927
  if (name.isStringLiteral()) {
@@ -3001,6 +3292,193 @@ function isMarkoPlaceholder(node) {
3001
3292
  return _marko_compiler.types.isMarkoPlaceholder(node);
3002
3293
  }
3003
3294
  //#endregion
3295
+ //#region src/translator/util/with-comment.ts
3296
+ function withLeadingComment(node, value) {
3297
+ if (value) {
3298
+ const comment = {
3299
+ type: "CommentBlock",
3300
+ value: ` ${value} `
3301
+ };
3302
+ node.leadingComments = node.leadingComments ? [...node.leadingComments, comment] : [comment];
3303
+ }
3304
+ return node;
3305
+ }
3306
+ //#endregion
3307
+ //#region src/translator/util/write-guard.ts
3308
+ function isSameReason(a, b) {
3309
+ return a === b || (a && b ? a.always && b.always || compareSources(a, b) === 0 : false);
3310
+ }
3311
+ const groupCheckPrefixes = {
3312
+ _write_guard: "wg",
3313
+ _write_if: "wi"
3314
+ };
3315
+ const [getSectionGuards] = createOutputSectionState((section) => ({
3316
+ shares: /* @__PURE__ */ new Map(),
3317
+ declarators: [_marko_compiler.types.variableDeclarator(scopeReasonIdentifier(section), callRuntime("_scope_reason"))]
3318
+ }));
3319
+ function buildGroupMask(groups) {
3320
+ let mask = 0;
3321
+ let maskNames = "";
3322
+ let dynamic;
3323
+ const props = [];
3324
+ let needsObject = false;
3325
+ let any = false;
3326
+ for (let i = 0; i < groups.length; i++) {
3327
+ const { value, names } = groups[i];
3328
+ if (value === void 0) continue;
3329
+ any = true;
3330
+ if (value === 0) continue;
3331
+ if (i >= 15) needsObject = true;
3332
+ else if (typeof value === "number") {
3333
+ mask |= value << 1 + 2 * i;
3334
+ if (names) maskNames += maskNames ? ` | ${names}` : names;
3335
+ } else {
3336
+ const shifted = _marko_compiler.types.binaryExpression("<<", value, withLeadingComment(_marko_compiler.types.numericLiteral(1 + 2 * i), names));
3337
+ dynamic = dynamic ? _marko_compiler.types.binaryExpression("|", dynamic, shifted) : shifted;
3338
+ }
3339
+ props.push(_marko_compiler.types.objectProperty(withLeadingComment(_marko_compiler.types.numericLiteral(i), names), typeof value === "number" ? _marko_compiler.types.numericLiteral(value) : value));
3340
+ }
3341
+ if (needsObject) return _marko_compiler.types.objectExpression(props);
3342
+ if (!any) return;
3343
+ const literal = mask ? withLeadingComment(_marko_compiler.types.numericLiteral(mask), maskNames) : void 0;
3344
+ return literal && dynamic ? _marko_compiler.types.binaryExpression("|", literal, dynamic) : literal || dynamic || _marko_compiler.types.numericLiteral(0);
3345
+ }
3346
+ function getScopeReasonStatement(section) {
3347
+ return hasGuardedReason(section) ? _marko_compiler.types.variableDeclaration("const", getSectionGuards(section).declarators) : _marko_compiler.types.expressionStatement(callRuntime("_scope_reason"));
3348
+ }
3349
+ function getWriteReason(binding) {
3350
+ return findSlot(binding)?.reason;
3351
+ }
3352
+ function getBranchWriteReason(section) {
3353
+ return findSectionSlot(section, 9)?.reason;
3354
+ }
3355
+ function getWriteGuard(section, reason, omitUnconditional) {
3356
+ if (!isDynamicWriteGuard(section, reason)) {
3357
+ if (!reason) return _marko_compiler.types.numericLiteral(0);
3358
+ return omitUnconditional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.always ? void 0 : reason.state));
3359
+ }
3360
+ const bit = getGroupsBit(reason.param);
3361
+ if (bit !== void 0) return bit && omitUnconditional ? void 0 : _marko_compiler.types.numericLiteral(bit);
3362
+ return orEachParamGroup(reason.param, "_write_guard");
3363
+ }
3364
+ function getWriteGuardForAny(section, reasons, omitUnconditional) {
3365
+ if (!Array.isArray(reasons)) return getWriteGuard(section, reasons, omitUnconditional);
3366
+ for (const reason of reasons) if (getWriteBit(section, reason) === 1) return omitUnconditional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.state));
3367
+ let expr;
3368
+ for (const reason of reasons) if (getWriteBit(section, reason) !== 0) expr = orGuard(expr, getWriteGuard(section, reason, false));
3369
+ return expr || _marko_compiler.types.numericLiteral(0);
3370
+ }
3371
+ function getExprIfWritten(section, reason, expr) {
3372
+ const ownReason = mapBodyParams(section, reason);
3373
+ if (!isGuardedReason(ownReason)) return ownReason && expr;
3374
+ const bit = getGroupsBit(ownReason.param);
3375
+ if (bit !== void 0) return bit ? expr : void 0;
3376
+ return andGuard(orEachParamGroup(ownReason.param, "_write_if"), expr);
3377
+ }
3378
+ function isEverWritten(section, reason) {
3379
+ const ownReason = mapBodyParams(section, reason);
3380
+ return isGuardedReason(ownReason) ? getGroupsBit(ownReason.param) !== 0 : !!ownReason;
3381
+ }
3382
+ function isWrittenForCall(section, reason, call, callSection) {
3383
+ if (getWriteBit(section, reason) === 1) return true;
3384
+ const { childScopeBinding, childSection } = call;
3385
+ return !!childScopeBinding && isDynamicWriteGuard(section, reason) && reduceParamGroups(reason.param, (written, groupSection, group) => written || groupSection === childSection && getWriteBit(callSection, findSlot(childScopeBinding, 5, callSection, childSection.paramReasonGroups[getParamReasonGroupIndex(childSection, group)])?.reason) === 1, false);
3386
+ }
3387
+ function getWriteBit(section, reason) {
3388
+ return isDynamicWriteGuard(section, reason) ? getGroupsBit(reason.param) : reason ? 1 : 0;
3389
+ }
3390
+ function getGroupsBit(params) {
3391
+ return reduceParamGroups(params, addGroupBit, 0);
3392
+ }
3393
+ function addGroupBit(bit, section, group) {
3394
+ const groupBit = getStaticGroupBit(section, group);
3395
+ return bit === 1 || groupBit === 1 ? 1 : bit === 0 && groupBit === 0 ? 0 : void 0;
3396
+ }
3397
+ function orEachParamGroup(params, check) {
3398
+ return reduceParamGroups(params, orGroupChecks[check], void 0);
3399
+ }
3400
+ const orGroupChecks = {
3401
+ _write_guard: orGroupCheck("_write_guard"),
3402
+ _write_if: orGroupCheck("_write_if")
3403
+ };
3404
+ function orGroupCheck(check) {
3405
+ return (expr, section, group) => getStaticGroupBit(section, group) === 0 ? expr : orGuard(expr, getOrShareSectionGuard(section, group, check));
3406
+ }
3407
+ function orGuard(guard, other) {
3408
+ return guard ? _marko_compiler.types.logicalExpression("||", guard, other) : other;
3409
+ }
3410
+ function andGuard(guard, expr) {
3411
+ return guard ? _marko_compiler.types.logicalExpression("&&", guard, expr) : expr;
3412
+ }
3413
+ function getOrShareSectionGuard(section, params, check) {
3414
+ if (!section.paramReasonGroups) return scopeReasonIdentifier(section);
3415
+ const state = getSectionGuards(section);
3416
+ let tracking = state.shares.get(check);
3417
+ if (!tracking) state.shares.set(check, tracking = createGuardShares());
3418
+ const index = getParamReasonGroupIndex(section, params);
3419
+ const name = tracking.names.get(index);
3420
+ if (name) return _marko_compiler.types.identifier(name);
3421
+ const guard = callRuntime(check, scopeReasonIdentifier(section), withLeadingComment(_marko_compiler.types.numericLiteral(index), getDebugNames(params)));
3422
+ const pending = tracking.pending.get(index);
3423
+ if (!pending) {
3424
+ const expr = _marko_compiler.types.parenthesizedExpression(guard);
3425
+ tracking.pending.set(index, expr);
3426
+ return expr;
3427
+ }
3428
+ const shared = generateUid(`${groupCheckPrefixes[check]}__${getDebugNamesAsIdentifier(params)}`);
3429
+ tracking.names.set(index, shared);
3430
+ tracking.pending.delete(index);
3431
+ state.declarators.push(_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(shared), guard));
3432
+ pending.expression = _marko_compiler.types.identifier(shared);
3433
+ return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(shared));
3434
+ }
3435
+ function isDynamicWriteGuard(section, reason) {
3436
+ return isGuardedReason(reason) && !isCrossSection(section, reason);
3437
+ }
3438
+ function isCrossSection(section, reason) {
3439
+ return some(reason.param, (param) => !isSameOrAncestorSection(param.section, section));
3440
+ }
3441
+ function getStaticGroupBit(body, group) {
3442
+ return getBodyGroupBit(body.paramReasonGroups[getParamReasonGroupIndex(body, group)]);
3443
+ }
3444
+ const [getBodyGroupBit] = createAnalysisMemo((group) => {
3445
+ const body = first(group).section;
3446
+ return isOnlyCalled(body) ? getCallsBit(body, group) : void 0;
3447
+ }, void 0);
3448
+ function getCallsBit(body, group) {
3449
+ const renderedBy = body.renderedBy;
3450
+ let bit;
3451
+ for (const call of Array.isArray(renderedBy) ? renderedBy : [renderedBy]) {
3452
+ const callSection = call.childScopeBinding.section;
3453
+ const callBit = getWriteBit(callSection, findSlot(call.childScopeBinding, 5, callSection, group)?.reason);
3454
+ if (callBit === void 0 || bit !== void 0 && bit !== callBit) return;
3455
+ bit = callBit;
3456
+ }
3457
+ return bit;
3458
+ }
3459
+ function isOnlyCalled(body) {
3460
+ return !!body.renderedBy && !!body.derives && !some(body.derives.binding, isUsed);
3461
+ }
3462
+ function isUsed(binding) {
3463
+ return !!binding.reads.size || !!binding.aliases.size || !!binding.propertyAliases.size;
3464
+ }
3465
+ function createGuardShares() {
3466
+ return {
3467
+ names: /* @__PURE__ */ new Map(),
3468
+ pending: /* @__PURE__ */ new Map()
3469
+ };
3470
+ }
3471
+ function hasGuardedReason(section) {
3472
+ if (section.paramReasonGroups || isGuardedReason(mapBodyParams(section, section.reason))) return true;
3473
+ return section.slots.some(isConditionalSlot);
3474
+ }
3475
+ function isConditionalSlot(slot) {
3476
+ return isGuardedReason(mapBodyParams(slot.section, slot.reason));
3477
+ }
3478
+ function scopeReasonIdentifier(section) {
3479
+ return _marko_compiler.types.identifier(ensureSharedUid(`scope${section.id}_reason`, section));
3480
+ }
3481
+ //#endregion
3004
3482
  //#region src/translator/util/sections.ts
3005
3483
  const sectionUtil = new Sorted(function compareSections(a, b) {
3006
3484
  return a.id - b.id;
@@ -3030,13 +3508,13 @@ function ensureBodySection(path) {
3030
3508
  selector: void 0,
3031
3509
  intersections: void 0,
3032
3510
  isHoistThrough: void 0,
3033
- slots: void 0,
3511
+ slots: [],
3034
3512
  reason: void 0,
3035
3513
  paramReasonGroups: void 0,
3036
3514
  returnValueExpr: void 0,
3037
3515
  content: getContentInfo(path),
3038
3516
  branchExpr: void 0,
3039
- callSections: void 0,
3517
+ renderedBy: void 0,
3040
3518
  knownTags: void 0,
3041
3519
  derives: void 0,
3042
3520
  dropped: !!extra.dropped,
@@ -3081,11 +3559,23 @@ function forEachSection(fn) {
3081
3559
  sections?.forEach(fn);
3082
3560
  }
3083
3561
  function getDynamicTagContentClosures(section) {
3084
- if (section.branchExpr?.tagNameType === 2) return getClosuresFromAbove(section, section);
3562
+ const { derives } = section;
3563
+ if (section.branchExpr?.tagNameType === 2 || derives && some(derives.binding, (binding) => bindingLandsRetained(binding, derives.properties))) return bindingUtil.filter(getClosuresFromAbove(section, section, /* @__PURE__ */ new Set()), mayBeUnwritten);
3564
+ }
3565
+ function mayBeUnwritten(closure) {
3566
+ const reason = getWriteReason(closure);
3567
+ return !reason || isGuardedReason(reason);
3085
3568
  }
3086
- function getClosuresFromAbove(section, top) {
3569
+ function getClosuresFromAbove(section, top, seen) {
3087
3570
  let closures = bindingUtil.leadingRun(section.referencedClosures, bindingToSection, sectionUtil.compare, top);
3088
- for (const child of section.children) closures = bindingUtil.union(closures, getClosuresFromAbove(child, top));
3571
+ for (const child of section.children) closures = bindingUtil.union(closures, getClosuresFromAbove(child, top, seen));
3572
+ for (const tagExtra of section.knownTags || []) {
3573
+ const body = tagExtra.childSection;
3574
+ if (!seen.has(body)) {
3575
+ seen.add(body);
3576
+ closures = bindingUtil.union(closures, getClosuresFromAbove(body, isSameOrAncestorSection(top, body) ? top : body, seen));
3577
+ }
3578
+ }
3089
3579
  return closures;
3090
3580
  }
3091
3581
  function forEachAncestorSection(from, to, fn, arg) {
@@ -3109,8 +3599,8 @@ function getContentInfo(path) {
3109
3599
  singleChild: false
3110
3600
  };
3111
3601
  }
3112
- const inlined = end.type === "MarkoTag" && getInlinedSection(end);
3113
- return inlined ? inlined.content : {
3602
+ const knownChild = end.type === "MarkoTag" && getKnownChildSection(end);
3603
+ return knownChild ? knownChild.content : {
3114
3604
  startType: endType,
3115
3605
  endType,
3116
3606
  singleChild: endType !== 1
@@ -3122,7 +3612,7 @@ function getContentInfo(path) {
3122
3612
  function getNodeContentType(path, edge) {
3123
3613
  switch (path.type) {
3124
3614
  case "MarkoText": return 4;
3125
- case "MarkoPlaceholder": return 2;
3615
+ case "MarkoPlaceholder": return getPlaceholderContentType(path.node);
3126
3616
  case "MarkoScriptlet":
3127
3617
  case "MarkoComment":
3128
3618
  case "ImportDeclaration":
@@ -3131,14 +3621,75 @@ function getNodeContentType(path, edge) {
3131
3621
  case "ExportDefaultDeclaration": return null;
3132
3622
  case "MarkoTag": {
3133
3623
  const tag = path;
3134
- const tagSection = getInlinedSection(tag);
3624
+ const tagSection = getKnownChildSection(tag);
3135
3625
  if (!tagSection) return getTagContentType(tag);
3136
3626
  return tagSection.content ? tagSection.content[edge] : null;
3137
3627
  }
3138
3628
  }
3139
3629
  return 1;
3140
3630
  }
3141
- function getInlinedSection(tag) {
3631
+ function isKnownChild(section) {
3632
+ return !section.parent || !!section.renderedBy;
3633
+ }
3634
+ const [getSectionTextBefore] = createAnalysisMemo((section) => getTextBeforeIn(section, void 0), true);
3635
+ function getTextBeforeIn(section, content) {
3636
+ const { branch, derives } = section;
3637
+ if (branch) {
3638
+ const { tag } = branch;
3639
+ const tagSection = tag.nodeBinding.section;
3640
+ return !isStartMarked(branch, section, content) && (branch.kind === "for" && mayEndWithText(section) || (tag.textBefore ?? (content ? getTextBeforeIn(tagSection, content) : getSectionTextBefore(tagSection))));
3641
+ }
3642
+ if (!section.parent) return void 0;
3643
+ return !derives || !!section.renderedBy || mayContentFollowText(section);
3644
+ }
3645
+ function mayContentFollowText(section) {
3646
+ const { tag } = section.derives;
3647
+ const { unseen, sites, deepSites } = getContentSites(section.derives);
3648
+ const tagFollowsText = () => tag.textBefore ?? getSectionTextBefore(section.parent) ?? true;
3649
+ return unseen || !!tag.tagNameNullable && tagFollowsText() || some(sites, (site) => getSiteTextBefore(site, section) ?? tagFollowsText()) || some(deepSites, (site) => getSiteTextBefore(site, void 0) ?? true);
3650
+ }
3651
+ function getSiteTextBefore(site, content) {
3652
+ return site.textBefore ?? getTextBeforeIn(site.nodeBinding.section, content);
3653
+ }
3654
+ function isStartMarked(branch, section, content) {
3655
+ const { nodeBinding } = branch.tag;
3656
+ const tagSection = nodeBinding.section;
3657
+ return branch.kind === "try" || (branch.kind === "await" ? isAlwaysWritten(tagSection, section.reason, content) : isAlwaysWritten(tagSection, getBranchWriteReason(section), content) && isAlwaysWritten(tagSection, getWriteReason(nodeBinding), content));
3658
+ }
3659
+ function isAlwaysWritten(section, reason, content) {
3660
+ return content ? isWrittenForCall(section, reason, content.derives.tag, content.parent) : getWriteBit(section, reason) === 1;
3661
+ }
3662
+ function mayEndWithText(section) {
3663
+ return !!section.content && mayRenderText(section.content.endType);
3664
+ }
3665
+ function mayMergeWithText(path, before) {
3666
+ let sibling = getSibling(path, before);
3667
+ let parent = path.parentPath;
3668
+ for (;;) if (!sibling.node) {
3669
+ const inlinedTag = getInlinedBodyTag(parent);
3670
+ if (!inlinedTag) return getSectionForBody(parent) ? void 0 : false;
3671
+ sibling = getSibling(inlinedTag, before);
3672
+ parent = inlinedTag.parentPath;
3673
+ } else {
3674
+ const contentType = getNodeContentType(sibling, before ? "endType" : "startType");
3675
+ if (contentType !== null) return mayRenderText(contentType);
3676
+ sibling = getSibling(sibling, before);
3677
+ }
3678
+ }
3679
+ function getSibling(path, before) {
3680
+ return before ? path.getPrevSibling() : path.getNextSibling();
3681
+ }
3682
+ function getInlinedBodyTag(parent) {
3683
+ if (parent.isMarkoTagBody()) {
3684
+ const tag = parent.parentPath;
3685
+ const facts = getTagFacts(tag);
3686
+ if (facts.controlFlow && facts.inlineBody) return tag;
3687
+ }
3688
+ }
3689
+ function mayRenderText(contentType) {
3690
+ return contentType === 4 || contentType === 1 || contentType === 2;
3691
+ }
3692
+ function getKnownChildSection(tag) {
3142
3693
  return tag.node.extra?.defineBodySection || !isCoreTag(tag) && analyzeTagNameType(tag) === 1 && !tag.node.extra.tagNameLoad && (0, _marko_compiler_babel_utils.loadFileForTag)(tag).ast.program.extra.section;
3143
3694
  }
3144
3695
  function getRendererReason(section) {
@@ -3152,7 +3703,8 @@ function getRendererReason(section) {
3152
3703
  return ALWAYS;
3153
3704
  }
3154
3705
  function isOptionalBranch(section) {
3155
- return !!section.branch?.optional;
3706
+ const kind = section.branch?.kind;
3707
+ return kind === "if" || kind === "for";
3156
3708
  }
3157
3709
  function isInParentSection(binding, section) {
3158
3710
  return section.parent?.id === binding.section.id;
@@ -3190,14 +3742,11 @@ function getCommonSection(section, other) {
3190
3742
  }
3191
3743
  function ensureSectionReasonGroups(section) {
3192
3744
  ensureReasonGroups(section, section.reason);
3193
- forEach(section.slots, ensureSlotReasonGroups);
3194
- }
3195
- function ensureSlotReasonGroups(slot) {
3196
- ensureReasonGroups(slot.section, slot.reason);
3745
+ for (const slot of section.slots) ensureReasonGroups(slot.section, slot.reason);
3197
3746
  }
3198
3747
  function ensureReasonGroups(section, reason) {
3199
3748
  const ownReason = mapBodyParams(section, reason);
3200
- if (isConditionalReason(ownReason)) forEachParamGroup(ownReason.param, ensureParamReasonGroup);
3749
+ if (isGuardedReason(ownReason)) forEachParamGroup(ownReason.param, ensureParamReasonGroup);
3201
3750
  }
3202
3751
  function ensureParamReasonGroup(section, group) {
3203
3752
  const { paramReasonGroups } = section;
@@ -3260,9 +3809,9 @@ function setContentDerives(tag, tagExtra, binding, exprs, properties, skip) {
3260
3809
  //#region src/translator/util/params-tree.ts
3261
3810
  function exposeParamsTree(binding, bodyAnalyzed) {
3262
3811
  binding.exposed = true;
3263
- const props = {
3812
+ const tree = {
3264
3813
  binding,
3265
- props: void 0,
3814
+ properties: void 0,
3266
3815
  rest: void 0
3267
3816
  };
3268
3817
  if (!binding.reads.size) {
@@ -3273,15 +3822,15 @@ function exposeParamsTree(binding, bodyAnalyzed) {
3273
3822
  if (++aliasCount > 1) break;
3274
3823
  }
3275
3824
  if (!restAlias) {
3276
- props.props = Object.create(null);
3277
- for (const [property, alias] of binding.propertyAliases) props.props[property] = exposeParamsTree(alias, bodyAnalyzed);
3825
+ tree.properties = Object.create(null);
3826
+ for (const [property, alias] of binding.propertyAliases) tree.properties[property] = exposeParamsTree(alias, bodyAnalyzed);
3278
3827
  } else if (aliasCount === 1) {
3279
3828
  if (hasSupersetExcludeProperties(binding, restAlias.excludeProperties)) {
3280
- props.rest = exposeParamsTree(restAlias, bodyAnalyzed);
3281
- props.props = Object.create(null);
3829
+ tree.rest = exposeParamsTree(restAlias, bodyAnalyzed);
3830
+ tree.properties = Object.create(null);
3282
3831
  forEach(restAlias.excludeProperties, (property) => {
3283
3832
  const propAlias = binding.propertyAliases.get(property);
3284
- if (propAlias) props.props[property] = exposeParamsTree(propAlias, bodyAnalyzed);
3833
+ if (propAlias) tree.properties[property] = exposeParamsTree(propAlias, bodyAnalyzed);
3285
3834
  });
3286
3835
  }
3287
3836
  }
@@ -3289,7 +3838,7 @@ function exposeParamsTree(binding, bodyAnalyzed) {
3289
3838
  const exportNames = (0, _marko_compiler_babel_utils.getProgram)().node.extra.exportNames;
3290
3839
  if (isTemplateParam(binding) && !exportNames.params.has(binding)) exportNames.params.set(binding, generateUid(binding.name));
3291
3840
  if (isDirectContentBinding(binding) && !exportNames.directContent.has(binding)) exportNames.directContent.set(binding, generateUid(`${binding.name}_direct`));
3292
- return props;
3841
+ return tree;
3293
3842
  }
3294
3843
  function isDirectContentBinding(binding) {
3295
3844
  if (binding.reads.size !== 1) return false;
@@ -3304,33 +3853,33 @@ function isPossiblyRead(alias) {
3304
3853
  }
3305
3854
  function hasSupersetExcludeProperties(binding, excludeProperties) {
3306
3855
  if (excludeProperties === void 0) return false;
3307
- for (const prop of binding.propertyAliases.keys()) if (!propsUtil.has(excludeProperties, prop)) return false;
3856
+ for (const prop of binding.propertyAliases.keys()) if (!propertiesUtil.has(excludeProperties, prop)) return false;
3308
3857
  return true;
3309
3858
  }
3310
3859
  function getSettledParamsTree(paramsTree) {
3311
3860
  if (!paramsTree || paramsTree.binding.pruned) return;
3312
- if (!paramsTree.props) return paramsTree;
3313
- const props = Object.create(null);
3314
- for (const name in paramsTree.props) {
3315
- const prop = getSettledParamsTree(paramsTree.props[name]);
3316
- if (prop) props[name] = prop;
3861
+ if (!paramsTree.properties) return paramsTree;
3862
+ const properties = Object.create(null);
3863
+ for (const name in paramsTree.properties) {
3864
+ const prop = getSettledParamsTree(paramsTree.properties[name]);
3865
+ if (prop) properties[name] = prop;
3317
3866
  }
3318
3867
  return {
3319
3868
  binding: paramsTree.binding,
3320
- props,
3869
+ properties,
3321
3870
  rest: getSettledParamsTree(paramsTree.rest)
3322
3871
  };
3323
3872
  }
3324
3873
  function getParamsTreeAt(paramsTree, name) {
3325
- return paramsTree === true ? true : paramsTree.props ? paramsTree.props[name] || (paramsTree.rest ? getParamsTreeAt(paramsTree.rest, name) : void 0) : propsUtil.has(paramsTree.binding.excludeProperties, name) ? void 0 : true;
3874
+ return paramsTree === true ? true : paramsTree.properties ? paramsTree.properties[name] || (paramsTree.rest ? getParamsTreeAt(paramsTree.rest, name) : void 0) : propertiesUtil.has(paramsTree.binding.excludeProperties, name) ? void 0 : true;
3326
3875
  }
3327
- function getAllKnownPropNames(paramsTree) {
3328
- const keys = paramsTree.props ? Object.keys(paramsTree.props) : [];
3329
- if (paramsTree.rest?.props) for (const key of Object.keys(paramsTree.rest.props)) keys.push(key);
3876
+ function getAllKnownPropertyNames(paramsTree) {
3877
+ const keys = paramsTree.properties ? Object.keys(paramsTree.properties) : [];
3878
+ if (paramsTree.rest?.properties) for (const key of Object.keys(paramsTree.rest.properties)) keys.push(key);
3330
3879
  return keys;
3331
3880
  }
3332
- function hasAllKnownProps(paramsTree) {
3333
- return paramsTree.props && (!paramsTree.rest || !!paramsTree.rest.props);
3881
+ function hasAllKnownProperties(paramsTree) {
3882
+ return paramsTree.properties && (!paramsTree.rest || !!paramsTree.rest.properties);
3334
3883
  }
3335
3884
  //#endregion
3336
3885
  //#region src/common/constants/accessor-prefix.ts
@@ -3459,9 +4008,9 @@ function getClosureAccessorId(binding) {
3459
4008
  return id;
3460
4009
  }
3461
4010
  function getSectionInstancesAccessor(section) {
3462
- return isOptionalBranch(section) ? getAccessorPrefix().BranchScopes + getScopeAccessor(section.branch.nodeBinding) : getAccessorPrefix().ClosureScopes + section.id;
4011
+ return isOptionalBranch(section) ? getAccessorPrefix().BranchScopes + getScopeAccessor(section.branch.tag.nodeBinding) : getAccessorPrefix().ClosureScopes + section.id;
3463
4012
  }
3464
- function getSectionInstancesAccessorLiteral(section) {
4013
+ function getSectionScopesAccessorLiteral(section) {
3465
4014
  return _marko_compiler.types.stringLiteral(getSectionInstancesAccessor(section));
3466
4015
  }
3467
4016
  //#endregion
@@ -3527,7 +4076,8 @@ function finalizeSetupWork() {
3527
4076
  });
3528
4077
  }
3529
4078
  function setCallSectionsSetup(body) {
3530
- forEach(body.callSections, (callSection) => {
4079
+ forEach(body.renderedBy, (call) => {
4080
+ const callSection = call.childScopeBinding.section;
3531
4081
  if (!callSection.hasSetupWork) {
3532
4082
  callSection.hasSetupWork = true;
3533
4083
  setCallSectionsSetup(callSection);
@@ -3538,7 +4088,7 @@ function hasOwnSetupWork(section) {
3538
4088
  const info = getSetupInfo(section);
3539
4089
  if (info.always || section.referencedClosures || callsOtherTemplateSetup(section)) return true;
3540
4090
  for (const expr of info.exprs) {
3541
- const extra = getCanonicalExtra(expr);
4091
+ const extra = getCanonicalExpr(expr);
3542
4092
  if (!extra.dropped && !getReferencedBindings(extra)) return true;
3543
4093
  }
3544
4094
  return false;
@@ -3581,13 +4131,13 @@ function onlyComparesKey(closure, canonical, bodySection, keyBinding) {
3581
4131
  return found;
3582
4132
  }
3583
4133
  function resolvesTo(read, canonical) {
3584
- const binding = getPropertyAlias(read.binding, read.props);
4134
+ const binding = getPropertyAlias(read.binding, read.properties);
3585
4135
  return !!binding && getCanonicalBinding(binding) === canonical;
3586
4136
  }
3587
4137
  function resolvesThrough(read, canonical) {
3588
4138
  let binding = read.binding;
3589
4139
  let through = false;
3590
- forEach(read.props, (prop) => {
4140
+ forEach(read.properties, (prop) => {
3591
4141
  if (binding) {
3592
4142
  through ||= getCanonicalBinding(binding) === canonical;
3593
4143
  binding = binding.propertyAliases.get(prop);
@@ -3597,7 +4147,7 @@ function resolvesThrough(read, canonical) {
3597
4147
  }
3598
4148
  function readsKey(read, keyBinding) {
3599
4149
  if (!read || read.getter) return false;
3600
- const binding = getPropertyAlias(read.binding, read.props);
4150
+ const binding = getPropertyAlias(read.binding, read.properties);
3601
4151
  return !!binding && getCanonicalBinding(binding) === getCanonicalBinding(keyBinding);
3602
4152
  }
3603
4153
  //#endregion
@@ -3612,7 +4162,7 @@ function getDeclaredBindingExpression(binding, inPlace = false) {
3612
4162
  if (!aliased) return _marko_compiler.types.identifier(canonicalBinding.name);
3613
4163
  if (property !== void 0) {
3614
4164
  const alias = getDeclaredAlias(aliased);
3615
- if (alias && !propsUtil.has(alias.excludeProperties, property)) return toMemberExpression(_marko_compiler.types.identifier(alias.name), alias.restOffset ? `${+property - alias.restOffset}` : property, !inPlace && alias.nullable);
4165
+ if (alias && !propertiesUtil.has(alias.excludeProperties, property)) return toMemberExpression(_marko_compiler.types.identifier(alias.name), alias.restOffset ? `${+property - alias.restOffset}` : property, !inPlace && alias.nullable);
3616
4166
  return toMemberExpression(getDeclaredBindingExpression(aliased, inPlace), property, !inPlace && aliased.nullable);
3617
4167
  }
3618
4168
  return getDeclaredBindingExpression(aliased, inPlace);
@@ -3628,33 +4178,42 @@ function withPreviousLocation(newNode, originalNode) {
3628
4178
  //#endregion
3629
4179
  //#region src/translator/util/read-replacement.ts
3630
4180
  function getReadReplacement(node, signal) {
4181
+ if (isOutputDOM() && !isOptimize() && node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" && node.object.extra?.binding?.type === 6 && getReferencedBindings(node.object.extra.exprRoot)) return callRuntime("_global_read", node.object, _marko_compiler.types.stringLiteral(node.property.name));
3631
4182
  const { extra } = node;
3632
4183
  if (!extra || extra.assignment) return;
3633
4184
  const { read, binding } = extra;
3634
4185
  if (!read) {
3635
- if (binding && node.type === "Identifier" && node.name !== binding.name) node.name = binding.name;
4186
+ if (binding) {
4187
+ if (binding.type === 6) {
4188
+ if (isOutputDOM()) {
4189
+ const globals = toMemberExpression(scopeIdentifier, getAccessorProp().Global);
4190
+ globals.extra = extra;
4191
+ return globals;
4192
+ }
4193
+ } else if (node.type === "Identifier" && node.name !== binding.name) node.name = binding.name;
4194
+ }
3636
4195
  return;
3637
4196
  }
3638
4197
  if (read.getter?.invoked) return;
3639
4198
  const base = isOutputDOM() ? getDOMReadBase(read, extra.section, signal) : getHTMLReadBase(node, read);
3640
4199
  if (!base) return;
3641
- const expr = reduce(read.props, addMember, base);
4200
+ const expr = reduce(read.properties, addMember, base);
3642
4201
  if (node.type === "Identifier" && expr.type === "Identifier") {
3643
4202
  node.name = expr.name;
3644
4203
  return;
3645
4204
  }
3646
- return getChainReplacement(node, expr, isOutputDOM() ? size(read.props) : Infinity);
4205
+ return getChainReplacement(node, expr, isOutputDOM() ? size(read.properties) : Infinity);
3647
4206
  }
3648
4207
  function getDOMReadBase(read, section, signal) {
3649
- const { binding, props, getter } = read;
4208
+ const { binding, properties, getter } = read;
3650
4209
  if (read.localFn) return isRegisteredFnExtra(read.localFn) ? toMemberExpression(localsIdentifier, getLocalsScopeAccessor(binding)) : _marko_compiler.types.identifier(binding.name);
3651
- if (props === void 0) {
4210
+ if (properties === void 0) {
3652
4211
  const inlined = getSignals(section).get(binding)?.inline?.value;
3653
4212
  if (inlined) return _marko_compiler.types.cloneNode(inlined, true);
3654
4213
  }
3655
4214
  if (signal?.referencedBindings === binding && !signal.storesValue) return getSignalValueIdentifier(signal);
3656
4215
  if (getter?.hoisted) return binding.aliasOf ? callRuntime("_hoist_read_error") : _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, getter.hoisted), [getScopeExpression(section, getter.hoisted)]);
3657
- if (props === void 0 && binding.type === 0) return getter && _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, binding.section), [getScopeExpression(section, binding.section)]);
4216
+ if (properties === void 0 && binding.type === 0) return getter && _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, binding.section), [getScopeExpression(section, binding.section)]);
3658
4217
  if (!isOptimize() && read.inOwnBody && isChildReturnVar(binding)) return callRuntime("_assert_init", section ? getScopeExpression(section, binding.section) : scopeIdentifier, getScopeAccessorLiteral(binding));
3659
4218
  return createScopeReadExpression(binding, section);
3660
4219
  }
@@ -3756,7 +4315,7 @@ function translateVar(tag, initialValue, kind = "const", statements) {
3756
4315
  });
3757
4316
  const declaration = _marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(tagVar, initialValue)]);
3758
4317
  if (statements) statements.push(declaration);
3759
- else tag.insertBefore(declaration);
4318
+ else insertStatementBefore(tag, declaration);
3760
4319
  }
3761
4320
  function isTagVarAssigned(tag) {
3762
4321
  return !!(tag.node.var.type === "Identifier" && tag.scope.getBinding(tag.node.var.name)?.constantViolations.length);
@@ -3793,7 +4352,7 @@ function removeUndeclared(pattern, section) {
3793
4352
  function translateAliasInSection(tag, id, alias, kind) {
3794
4353
  const aliased = alias.aliasOf;
3795
4354
  const value = getDeclaredBindingExpression(aliased);
3796
- getSectionTarget(tag, alias.section).insertBefore(_marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(id, alias.property === void 0 ? value : toMemberExpression(value, alias.property, aliased.nullable))]));
4355
+ insertStatementBefore(getSectionTarget(tag, alias.section), _marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(id, alias.property === void 0 ? value : toMemberExpression(value, alias.property, aliased.nullable))]));
3797
4356
  }
3798
4357
  function translateRest(tag, id, rest, kind) {
3799
4358
  const source = getCanonicalBinding(rest.aliasOf);
@@ -3805,7 +4364,7 @@ function translateRest(tag, id, rest, kind) {
3805
4364
  inPlace = false;
3806
4365
  }
3807
4366
  const value = getDeclaredBindingExpression(from, inPlace);
3808
- target.insertBefore(_marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(getRestPattern(rest, id, from, false), inPlace ? value : withRestFallback(rest, from, value))]));
4367
+ insertStatementBefore(target, _marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(getRestPattern(rest, id, from, false), inPlace ? value : withRestFallback(rest, from, value))]));
3809
4368
  }
3810
4369
  function getRestPattern(rest, id, from, shorthand) {
3811
4370
  const restElement = _marko_compiler.types.restElement(id);
@@ -3840,139 +4399,6 @@ function getDestructurePattern(id) {
3840
4399
  }
3841
4400
  }
3842
4401
  //#endregion
3843
- //#region src/translator/util/with-comment.ts
3844
- function withLeadingComment(node, value) {
3845
- if (value) {
3846
- const comment = {
3847
- type: "CommentBlock",
3848
- value: ` ${value} `
3849
- };
3850
- node.leadingComments = node.leadingComments ? [...node.leadingComments, comment] : [comment];
3851
- }
3852
- return node;
3853
- }
3854
- //#endregion
3855
- //#region src/translator/util/write-guard.ts
3856
- function isSameReason(a, b) {
3857
- return a === b || (a && b ? a.always && b.always || compareSources(a, b) === 0 : false);
3858
- }
3859
- const groupCheckPrefixes = {
3860
- _write_guard: "wg",
3861
- _write_if: "wi"
3862
- };
3863
- const [getSectionGuards] = createOutputSectionState((section) => ({
3864
- hoists: /* @__PURE__ */ new Map(),
3865
- declarators: [_marko_compiler.types.variableDeclarator(scopeReasonIdentifier(section), callRuntime("_scope_reason"))]
3866
- }));
3867
- function buildGroupMask(groups) {
3868
- let mask = 0;
3869
- let maskNames = "";
3870
- let dynamic;
3871
- const props = [];
3872
- let needsObject = false;
3873
- let any = false;
3874
- for (let i = 0; i < groups.length; i++) {
3875
- const { value, names } = groups[i];
3876
- if (value === void 0) continue;
3877
- any = true;
3878
- if (value === 0) continue;
3879
- if (i >= 15) needsObject = true;
3880
- else if (typeof value === "number") {
3881
- mask |= value << 1 + 2 * i;
3882
- if (names) maskNames += maskNames ? ` | ${names}` : names;
3883
- } else {
3884
- const shifted = _marko_compiler.types.binaryExpression("<<", value, withLeadingComment(_marko_compiler.types.numericLiteral(1 + 2 * i), names));
3885
- dynamic = dynamic ? _marko_compiler.types.binaryExpression("|", dynamic, shifted) : shifted;
3886
- }
3887
- props.push(_marko_compiler.types.objectProperty(withLeadingComment(_marko_compiler.types.numericLiteral(i), names), typeof value === "number" ? _marko_compiler.types.numericLiteral(value) : value));
3888
- }
3889
- if (needsObject) return _marko_compiler.types.objectExpression(props);
3890
- if (!any) return;
3891
- const literal = mask ? withLeadingComment(_marko_compiler.types.numericLiteral(mask), maskNames) : void 0;
3892
- return literal && dynamic ? _marko_compiler.types.binaryExpression("|", literal, dynamic) : literal || dynamic || _marko_compiler.types.numericLiteral(0);
3893
- }
3894
- function getScopeReasonStatement(section) {
3895
- return hasConditionalReason(section) ? _marko_compiler.types.variableDeclaration("const", getSectionGuards(section).declarators) : _marko_compiler.types.expressionStatement(callRuntime("_scope_reason"));
3896
- }
3897
- function getWriteReason(binding) {
3898
- return findSlot(binding)?.reason;
3899
- }
3900
- function getBranchWriteReason(section) {
3901
- return findSectionSlot(section, 9)?.reason;
3902
- }
3903
- function getWriteGuard(section, reason, omitUnconditional) {
3904
- if (!isDynamicWriteGuard(section, reason)) {
3905
- if (!reason) return _marko_compiler.types.numericLiteral(0);
3906
- return omitUnconditional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.always ? void 0 : reason.state));
3907
- }
3908
- return orEachParamGroup(reason.param, "_write_guard");
3909
- }
3910
- function getWriteGuardForAny(section, reasons, omitUnconditional) {
3911
- if (!Array.isArray(reasons)) return getWriteGuard(section, reasons, omitUnconditional);
3912
- for (const reason of reasons) if (!isConditionalReason(reason)) return omitUnconditional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.state));
3913
- let expr;
3914
- for (const reason of reasons) expr = orGuard(expr, getWriteGuard(section, reason, false));
3915
- return expr;
3916
- }
3917
- function getExprIfWritten(section, reason, expr) {
3918
- const ownReason = mapBodyParams(section, reason);
3919
- if (!isConditionalReason(ownReason)) return ownReason && expr;
3920
- return andGuard(orEachParamGroup(ownReason.param, "_write_if"), expr);
3921
- }
3922
- function orEachParamGroup(params, check) {
3923
- return reduceParamGroups(params, (expr, section, group) => orGuard(expr, getOrHoistSectionGuard(section, group, check)), void 0);
3924
- }
3925
- function orGuard(guard, other) {
3926
- return guard ? _marko_compiler.types.logicalExpression("||", guard, other) : other;
3927
- }
3928
- function andGuard(guard, expr) {
3929
- return guard ? _marko_compiler.types.logicalExpression("&&", guard, expr) : expr;
3930
- }
3931
- function getOrHoistSectionGuard(section, params, check) {
3932
- if (!section.paramReasonGroups) return scopeReasonIdentifier(section);
3933
- const state = getSectionGuards(section);
3934
- let tracking = state.hoists.get(check);
3935
- if (!tracking) state.hoists.set(check, tracking = createGuardHoists());
3936
- const index = getParamReasonGroupIndex(section, params);
3937
- const name = tracking.names.get(index);
3938
- if (name) return _marko_compiler.types.identifier(name);
3939
- const guard = callRuntime(check, scopeReasonIdentifier(section), withLeadingComment(_marko_compiler.types.numericLiteral(index), getDebugNames(params)));
3940
- const pending = tracking.pending.get(index);
3941
- if (!pending) {
3942
- const expr = _marko_compiler.types.parenthesizedExpression(guard);
3943
- tracking.pending.set(index, expr);
3944
- return expr;
3945
- }
3946
- const hoisted = generateUid(`${groupCheckPrefixes[check]}__${getDebugNamesAsIdentifier(params)}`);
3947
- tracking.names.set(index, hoisted);
3948
- tracking.pending.delete(index);
3949
- state.declarators.push(_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(hoisted), guard));
3950
- pending.expression = _marko_compiler.types.identifier(hoisted);
3951
- return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(hoisted));
3952
- }
3953
- function isDynamicWriteGuard(section, reason) {
3954
- return isConditionalReason(reason) && !isCrossSection(section, reason);
3955
- }
3956
- function isCrossSection(section, reason) {
3957
- return some(reason.param, (param) => !isSameOrAncestorSection(param.section, section));
3958
- }
3959
- function createGuardHoists() {
3960
- return {
3961
- names: /* @__PURE__ */ new Map(),
3962
- pending: /* @__PURE__ */ new Map()
3963
- };
3964
- }
3965
- function hasConditionalReason(section) {
3966
- if (section.paramReasonGroups || isConditionalReason(mapBodyParams(section, section.reason))) return true;
3967
- return some(section.slots, isConditionalSlot);
3968
- }
3969
- function isConditionalSlot(slot) {
3970
- return isConditionalReason(mapBodyParams(slot.section, slot.reason));
3971
- }
3972
- function scopeReasonIdentifier(section) {
3973
- return _marko_compiler.types.identifier(ensureSharedUid(`scope${section.id}_reason`, section));
3974
- }
3975
- //#endregion
3976
4402
  //#region src/translator/util/build-string-expression.ts
3977
4403
  function buildStringExpression(parts, useIife) {
3978
4404
  const strs = [""];
@@ -4054,7 +4480,7 @@ function consumeHTML(path) {
4054
4480
  }
4055
4481
  function flushBefore(path) {
4056
4482
  const expr = consumeHTML(path);
4057
- if (expr) path.insertBefore(expr)[0].skip();
4483
+ if (expr) insertStatementBefore(path, expr);
4058
4484
  }
4059
4485
  function flushInto(path) {
4060
4486
  const target = path.isProgram() ? path : path.get("body");
@@ -4067,7 +4493,7 @@ function markNode(path, nodeBinding, reason, deferred) {
4067
4493
  if (isOutputHTML()) {
4068
4494
  if (reason) {
4069
4495
  const section = getSection(path);
4070
- writeTo$1(path, deferred)`${callRuntime("_el_resume", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), getWriteGuard(section, reason, true))}`;
4496
+ writeTo$1(path, deferred)`${callRuntime("_el_mark", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), getWriteGuard(section, reason, true))}`;
4071
4497
  }
4072
4498
  }
4073
4499
  }
@@ -4078,19 +4504,21 @@ function unwrapWrite(write) {
4078
4504
  //#region src/translator/util/signals.ts
4079
4505
  const [getSignals] = createOutputSectionState(() => /* @__PURE__ */ new Map());
4080
4506
  const [getClosureSignalBuilder, _setClosureSignalBuilder] = createOutputSectionState();
4081
- function setClosureSignalBuilder(tag, hop, build = (_closure, render) => buildClosureHop(hop, render)) {
4082
- _setClosureSignalBuilder(getSectionForBody(tag.get("body")), build);
4507
+ function setClosureSignalBuilder(tag, build) {
4508
+ const section = getSectionForBody(tag.get("body"));
4509
+ _setClosureSignalBuilder(section, build || ((_closure, render) => buildClosureHop(section, render)));
4083
4510
  }
4084
- function buildClosureHop(hop, render) {
4085
- const accessor = getScopeAccessorLiteral(hop.nodeBinding, true);
4086
- return hop.kind === "if" ? callRuntime("_if_closure", accessor, _marko_compiler.types.numericLiteral(hop.index), render) : callRuntime("_for_closure", accessor, render);
4511
+ function buildClosureHop(section, render) {
4512
+ const branch = section.branch;
4513
+ const accessor = getScopeAccessorLiteral(branch.tag.nodeBinding, true);
4514
+ return branch.kind === "if" ? callRuntime("_if_closure", accessor, _marko_compiler.types.numericLiteral(branch.index), render) : callRuntime("_for_closure", accessor, render);
4087
4515
  }
4088
4516
  const [getOwnerResumedByMarker, setOwnerResumedByMarker] = createOutputSectionState();
4089
4517
  function setSectionOwnerResumedByMarker(section) {
4090
4518
  setOwnerResumedByMarker(section, true);
4091
4519
  }
4092
4520
  function getContentClosureValues(bodySection) {
4093
- const contentClosures = bindingUtil.filter(getDynamicTagContentClosures(bodySection), mayBeUnwritten);
4521
+ const contentClosures = getDynamicTagContentClosures(bodySection);
4094
4522
  if (!contentClosures) return;
4095
4523
  const scope = generateUidIdentifier("scope");
4096
4524
  const closures = Array.isArray(contentClosures) ? contentClosures : [contentClosures];
@@ -4111,9 +4539,6 @@ function getContentClosureValues(bodySection) {
4111
4539
  levels: levels.reverse()
4112
4540
  };
4113
4541
  }
4114
- function mayBeUnwritten(closure) {
4115
- return !isUnconditionalReason(getWriteReason(closure));
4116
- }
4117
4542
  const [getScopeProperties] = createOutputSectionState(() => /* @__PURE__ */ new Map());
4118
4543
  function writeSlot(slot, expression) {
4119
4544
  const reason = slot?.reason;
@@ -4198,7 +4623,7 @@ function getSignal(section, referencedBindings, name) {
4198
4623
  const render = buildSignalFn(signal);
4199
4624
  const closureSignalBuilder = getClosureSignalBuilder(section);
4200
4625
  if (closureSignalBuilder && !isDynamicClosure(section, closure)) return closureSignalBuilder(closure, render);
4201
- return callRuntime("_closure_get", getClosureAccessorLiteral(closure), render, isInParentSection(closure, section) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), isChangeableDynamicClosure(section, closure) ? _marko_compiler.types.stringLiteral(getResumeRegisterId(section, closure, "subscribe")) : void 0);
4626
+ return callRuntime("_closure_get", getClosureAccessorLiteral(closure), render, isInParentSection(closure, section) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), isChangeableDynamicClosure(section, closure) ? _marko_compiler.types.stringLiteral(getResumeRegistryId(section, closure, "subscribe")) : void 0);
4202
4627
  };
4203
4628
  }
4204
4629
  return signal;
@@ -4351,7 +4776,7 @@ function getSignalValueIdentifier(signal) {
4351
4776
  function isOwnValueRead(node, binding) {
4352
4777
  const extra = node.extra;
4353
4778
  const read = extra?.read;
4354
- return !!read && !extra.assignment && read.binding === binding && read.props === void 0 && !read.getter?.invoked;
4779
+ return !!read && !extra.assignment && read.binding === binding && read.properties === void 0 && !read.getter?.invoked;
4355
4780
  }
4356
4781
  function subscribe(references, intersection) {
4357
4782
  if (references) forEach(references, (binding) => {
@@ -4397,9 +4822,11 @@ function addStatement(type, targetSection, expr, statement, isPure) {
4397
4822
  if (!isPure || type === "effect") signal.storesValue = true;
4398
4823
  }
4399
4824
  function addTagStatement(tag, statement) {
4400
- if (isOutputHTML()) tag.insertBefore(statement);
4401
- else addStatement("render", getSection(tag), tag.node.attributes[0]?.value.extra, statement);
4402
- tag.remove();
4825
+ if (isOutputHTML()) insertStatementBefore(tag, statement);
4826
+ else {
4827
+ addStatement("render", getSection(tag), tag.node.attributes[0]?.value.extra, statement);
4828
+ replaceWithStatements(tag);
4829
+ }
4403
4830
  }
4404
4831
  function addValue(targetSection, expr, signal, value) {
4405
4832
  const parentSignal = getSignal(targetSection, getReferencedBindings(expr));
@@ -4417,7 +4844,7 @@ function buildResumeRegisterKey(section, referencedBindings, type) {
4417
4844
  }
4418
4845
  return `${section.id}${name}${type ? "/" + type : ""}`;
4419
4846
  }
4420
- function getResumeRegisterId(section, referencedBindings, type) {
4847
+ function getResumeRegistryId(section, referencedBindings, type) {
4421
4848
  const { markoOpts, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
4422
4849
  const key = buildResumeRegisterKey(section, referencedBindings, type);
4423
4850
  return (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, key);
@@ -4440,7 +4867,7 @@ function writeSignals(section) {
4440
4867
  traverseReplace(signal, "effect", replaceEffectNode);
4441
4868
  const effectIdentifier = getSignalEffectIdentifier(signal);
4442
4869
  const effectFn = _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], toOnlyExpressionOrBlock(signal.effect));
4443
- effectDeclarator = _marko_compiler.types.variableDeclarator(effectIdentifier, callRuntime("_script", _marko_compiler.types.stringLiteral(getResumeRegisterId(section, signal.referencedBindings)), effectFn));
4870
+ effectDeclarator = _marko_compiler.types.variableDeclarator(effectIdentifier, callRuntime("_script", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signal.referencedBindings)), effectFn));
4444
4871
  }
4445
4872
  let signalDeclaration;
4446
4873
  if (signal.build) {
@@ -4448,7 +4875,7 @@ function writeSignals(section) {
4448
4875
  const buildsEagerForward = _marko_compiler.types.isIdentifier(value) || _marko_compiler.types.isCallExpression(value) && _marko_compiler.types.isIdentifier(value.arguments.at(-1));
4449
4876
  if (!value || !signal.register && !signal.referenced && _marko_compiler.types.isFunction(value) && _marko_compiler.types.isBlockStatement(value.body) && !value.body.body.length) return;
4450
4877
  if (_marko_compiler.types.isCallExpression(value)) trimEmptyArgs(value.arguments);
4451
- if (signal.register) value = callRuntime("_var_resume", _marko_compiler.types.stringLiteral(getResumeRegisterId(section, signal.referencedBindings, "var")), value);
4878
+ if (signal.register) value = callRuntime("_var_resume", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signal.referencedBindings, "var")), value);
4452
4879
  if (buildsEagerForward) forEach(signal.forwards, writeSignal);
4453
4880
  const signalDeclarator = _marko_compiler.types.variableDeclarator(signal.identifier, value);
4454
4881
  signalDeclaration = !section.parent && !signal.referencedBindings && (_marko_compiler.types.isFunctionExpression(value) || _marko_compiler.types.isArrowFunctionExpression(value)) ? _marko_compiler.types.functionDeclaration(signal.identifier, value.params, _marko_compiler.types.isExpression(value.body) ? _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(value.body)]) : value.body) : _marko_compiler.types.variableDeclaration("const", [signalDeclarator]);
@@ -4469,16 +4896,16 @@ function writeGetters(section) {
4469
4896
  const getterIdentifier = getBindingGetterIdentifier(binding, hoistSection);
4470
4897
  const accessors = [getScopeAccessorLiteral(binding, true)];
4471
4898
  if (hoistSection) forEachAncestorSection(binding.section, hoistSection, pushInstancesAccessor, accessors);
4472
- (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(getterIdentifier, hoistSection ? hasReference ? callRuntime("_hoist_resume", _marko_compiler.types.stringLiteral(getResumeRegisterId(hoistSection, binding, "hoist")), ...accessors) : callRuntime("_hoist", ...accessors) : callRuntime("_el", _marko_compiler.types.stringLiteral(getResumeRegisterId(section, binding)), ...accessors))]));
4899
+ (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(getterIdentifier, hoistSection ? hasReference ? callRuntime("_hoist_resume", _marko_compiler.types.stringLiteral(getResumeRegistryId(hoistSection, binding, "hoist")), ...accessors) : callRuntime("_hoist", ...accessors) : callRuntime("_el", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, binding)), ...accessors))]));
4473
4900
  }
4474
4901
  });
4475
4902
  }
4476
4903
  function pushInstancesAccessor(section, accessors) {
4477
- const instancesAccessor = getSectionInstancesAccessorLiteral(section);
4904
+ const instancesAccessor = getSectionScopesAccessorLiteral(section);
4478
4905
  const { branch } = section;
4479
- accessors.push(branch?.index !== void 0 && Array.isArray(branch.nodeBinding.branchBodies) ? _marko_compiler.types.arrayExpression([
4906
+ accessors.push(branch?.kind === "if" && Array.isArray(branch.tag.nodeBinding.branchBodies) ? _marko_compiler.types.arrayExpression([
4480
4907
  instancesAccessor,
4481
- _marko_compiler.types.stringLiteral(getAccessorPrefix().ConditionalRenderer + getScopeAccessor(branch.nodeBinding)),
4908
+ _marko_compiler.types.stringLiteral(getAccessorPrefix().ConditionalRenderer + getScopeAccessor(branch.tag.nodeBinding)),
4482
4909
  _marko_compiler.types.numericLiteral(branch.index)
4483
4910
  ]) : instancesAccessor);
4484
4911
  }
@@ -4487,12 +4914,12 @@ function writeRegisteredFns() {
4487
4914
  const statements = [];
4488
4915
  for (const registeredFn of registeredFns) {
4489
4916
  let fn;
4490
- if (registeredFn.referencedBindings || registeredFn.referencesScope || registeredFn.referencedLocals) {
4917
+ if (registeredFn.referencesScope || registeredFn.referencedLocals) {
4491
4918
  let params;
4492
4919
  let prologue;
4493
4920
  if (registeredFn.referencedLocals) {
4494
4921
  params = [localsIdentifier];
4495
- if (registeredFn.referencedBindings || registeredFn.referencesScope) prologue = [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(scopeIdentifier, _marko_compiler.types.memberExpression(localsIdentifier, _marko_compiler.types.identifier(getAccessorProp().Owner)))])];
4922
+ if (registeredFn.referencesScope) prologue = [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(scopeIdentifier, _marko_compiler.types.memberExpression(localsIdentifier, _marko_compiler.types.identifier(getAccessorProp().Owner)))])];
4496
4923
  } else params = [scopeIdentifier];
4497
4924
  const body = toReturnedFunction(registeredFn.node, prologue);
4498
4925
  fn = _marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(registeredFn.id), _marko_compiler.types.arrowFunctionExpression(params, body.length === 1 && body[0].type === "ReturnStatement" ? body[0].argument : _marko_compiler.types.blockStatement(body)))]);
@@ -4500,7 +4927,7 @@ function writeRegisteredFns() {
4500
4927
  else fn = _marko_compiler.types.functionDeclaration(_marko_compiler.types.identifier(registeredFn.id), registeredFn.node.params, registeredFn.node.body.type === "BlockStatement" ? registeredFn.node.body : _marko_compiler.types.blockStatement([_marko_compiler.types.returnStatement(registeredFn.node.body)]), registeredFn.node.generator, registeredFn.node.async);
4501
4928
  statements.push(fn);
4502
4929
  }
4503
- for (const registeredFn of registeredFns) statements.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registeredFn.registerId, _marko_compiler.types.identifier(registeredFn.id))));
4930
+ for (const registeredFn of registeredFns) statements.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registeredFn.registryId, _marko_compiler.types.identifier(registeredFn.id))));
4504
4931
  (0, _marko_compiler_babel_utils.getProgram)().node.body.push(...statements);
4505
4932
  }
4506
4933
  function toReturnedFunction(rawFn, prologue) {
@@ -4537,10 +4964,10 @@ function writeHTMLResumeStatements(path) {
4537
4964
  const closureIndex = getDynamicClosureIndex(closure, section);
4538
4965
  if (closureIndex) writeSlot(findSlot(closure, 3, section), _marko_compiler.types.numericLiteral(closureIndex));
4539
4966
  const closureScopesReason = findSlot(closure, 2)?.reason;
4540
- const subscribeArg = isConditionalReason(closureScopesReason) && !isSameReason(closureScopesReason, sectionReason) ? getExprIfWritten(closure.section, closureScopesReason, identifier) : identifier;
4967
+ const subscribeArg = isGuardedReason(closureScopesReason) && !isSameReason(closureScopesReason, sectionReason) ? getExprIfWritten(closure.section, closureScopesReason, identifier) : identifier;
4541
4968
  const changeable = isChangeableDynamicClosure(section, closure);
4542
- addWriteScopeBuilder(section, (expr) => {
4543
- const resumeId = changeable && _marko_compiler.types.stringLiteral(getResumeRegisterId(section, closure, "subscribe"));
4969
+ if (subscribeArg) addWriteScopeBuilder(section, (expr) => {
4970
+ const resumeId = changeable && _marko_compiler.types.stringLiteral(getResumeRegistryId(section, closure, "subscribe"));
4544
4971
  return callRuntime("_subscribe", subscribeArg, expr, resumeId, resumeId && markerGuard);
4545
4972
  });
4546
4973
  }
@@ -4548,7 +4975,7 @@ function writeHTMLResumeStatements(path) {
4548
4975
  });
4549
4976
  for (let i = allSignals.length; i--;) if (allSignals[i].hasHTMLEffect) {
4550
4977
  const signalRefs = allSignals[i].referencedBindings;
4551
- body.push(_marko_compiler.types.expressionStatement(callRuntime("_script", scopeIdIdentifier, _marko_compiler.types.stringLiteral(getResumeRegisterId(section, signalRefs)), markerGuard)));
4978
+ body.push(_marko_compiler.types.expressionStatement(callRuntime("_script", scopeIdIdentifier, _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signalRefs)), markerGuard)));
4552
4979
  }
4553
4980
  const debug = !isOptimize();
4554
4981
  const writeScopeBuilder = getSectionWriteScopeBuilder(section);
@@ -4564,7 +4991,8 @@ function writeHTMLResumeStatements(path) {
4564
4991
  if (!reason) return;
4565
4992
  const accessor = getScopeAccessor(binding);
4566
4993
  pendingProperties.delete(accessor);
4567
- scopeProperties.push(toObjectProperty(accessor, ifWritten(reason, getDeclaredBindingExpression(binding))));
4994
+ const value = ifWritten(reason, getDeclaredBindingExpression(binding));
4995
+ if (value) scopeProperties.push(toObjectProperty(accessor, value));
4568
4996
  if (debug) {
4569
4997
  const { root, access } = getDebugAccess(binding, false, toAccess);
4570
4998
  const locExpr = root.loc && _marko_compiler.types.stringLiteral(getDebugLoc(root.loc));
@@ -4579,10 +5007,14 @@ function writeHTMLResumeStatements(path) {
4579
5007
  const ownerReason = findSectionSlot(section, 7)?.reason;
4580
5008
  if (ownerReason) {
4581
5009
  pendingProperties.delete(ownerAccessor);
4582
- if (!getOwnerResumedByMarker(section)) scopeProperties.push(toObjectProperty(ownerAccessor, ifWritten(ownerReason, callRuntime("_scope_with_id", getScopeIdIdentifier(section.parent)))));
5010
+ const owner = !getOwnerResumedByMarker(section) && ifWritten(ownerReason, callRuntime("_scope_with_id", getScopeIdIdentifier(section.parent)));
5011
+ if (owner) scopeProperties.push(toObjectProperty(ownerAccessor, owner));
4583
5012
  }
4584
5013
  }
4585
- for (const [key, { expression, reason }] of pendingProperties) scopeProperties.push(toObjectProperty(key, ifWritten(reason, expression)));
5014
+ for (const [key, { expression, reason }] of pendingProperties) {
5015
+ const value = ifWritten(reason, expression);
5016
+ if (value) scopeProperties.push(toObjectProperty(key, value));
5017
+ }
4586
5018
  if (sectionReason) {
4587
5019
  for (const prop of scopeProperties) if (prop.key.type === "Identifier" && prop.value.type === "Identifier" && prop.key.name === prop.value.name) prop.shorthand = true;
4588
5020
  const writeScopeArgs = [scopeIdIdentifier, _marko_compiler.types.objectExpression(scopeProperties)];
@@ -4591,8 +5023,8 @@ function writeHTMLResumeStatements(path) {
4591
5023
  for (const [accessor, varLoc] of getSectionDebugVars(section)) (debugVars ||= []).push(toObjectProperty(accessor, _marko_compiler.types.valueToNode(varLoc)));
4592
5024
  if (debugVars) writeScopeArgs.push(_marko_compiler.types.objectExpression(debugVars));
4593
5025
  }
4594
- const writeCall = writeScopeBuilder ? writeScopeBuilder(callRuntime("_scope", ...writeScopeArgs)) : callRuntime("_scope", ...writeScopeArgs);
4595
- body.push(_marko_compiler.types.expressionStatement(getExprIfWritten(section, sectionReason, writeCall)));
5026
+ const write = getExprIfWritten(section, sectionReason, writeScopeBuilder ? writeScopeBuilder(callRuntime("_scope", ...writeScopeArgs)) : callRuntime("_scope", ...writeScopeArgs));
5027
+ if (write) body.push(_marko_compiler.types.expressionStatement(write));
4596
5028
  }
4597
5029
  if (!isOptionalBranch(section) && (section.hasAbortSignal || !!section.referencedClosures || sectionReason && some(section.bindings, isLetBinding)) && markerGuard) {
4598
5030
  const call = callRuntime("_resume_branch", scopeIdIdentifier);
@@ -4739,25 +5171,23 @@ function registerFnExpression(node) {
4739
5171
  if (isRegisteredFnExtra(extra)) {
4740
5172
  const id = extra.name;
4741
5173
  const referencesScope = extra.referencesScope;
4742
- const referencedBindings = getReferencedBindingsInFunction(extra);
4743
5174
  const referencedLocals = extra.referencedLocalBindingsInFunction;
4744
5175
  getRegisteredFns().push({
4745
5176
  id,
4746
5177
  node,
4747
- registerId: extra.registerId,
5178
+ registryId: extra.registryId,
4748
5179
  section: extra.section,
4749
5180
  referencesScope,
4750
- referencedBindings,
4751
5181
  referencedLocals
4752
5182
  });
4753
5183
  if (referencedLocals) {
4754
5184
  const properties = [];
4755
- if (referencesScope || referencedBindings) properties.push(_marko_compiler.types.objectProperty(_marko_compiler.types.identifier(getAccessorProp().Owner), scopeIdentifier));
5185
+ if (referencesScope) properties.push(_marko_compiler.types.objectProperty(_marko_compiler.types.identifier(getAccessorProp().Owner), scopeIdentifier));
4756
5186
  forEach(referencedLocals, (binding) => {
4757
5187
  properties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
4758
5188
  });
4759
5189
  return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [_marko_compiler.types.objectExpression(properties)]);
4760
- } else if (referencesScope || referencedBindings) return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [scopeIdentifier]);
5190
+ } else if (referencesScope) return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [scopeIdentifier]);
4761
5191
  else return _marko_compiler.types.identifier(id);
4762
5192
  }
4763
5193
  }
@@ -4801,7 +5231,7 @@ function translateAttrs(tag, paramsTree = true, skip, statements = [], contentKe
4801
5231
  if (child.isMarkoTag()) {
4802
5232
  if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
4803
5233
  const attrTagMeta = attrTagLookup[getTagName(child)];
4804
- if (propsUtil.has(skip, attrTagMeta.name)) continue;
5234
+ if (propertiesUtil.has(skip, attrTagMeta.name)) continue;
4805
5235
  if (attrTagMeta.dynamic) i = addDynamicAttrTagStatements(attrTags, i, attrTagLookup, statements, paramsTree, contentKey);
4806
5236
  else {
4807
5237
  const translatedAttrTag = translateAttrs(child, getParamsTreeAt(paramsTree, attrTagMeta.name), void 0, statements, contentKey);
@@ -4932,7 +5362,7 @@ function buildContent$1(body) {
4932
5362
  if (isOutputHTML()) {
4933
5363
  const serialized = getRendererReason(bodySection);
4934
5364
  body.node.body.unshift(getScopeReasonStatement(bodySection));
4935
- return callRuntime(serialized ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(getResumeRegisterId(bodySection, "content")), _marko_compiler.types.arrowFunctionExpression(body.node.params, _marko_compiler.types.blockStatement(body.node.body)), getScopeIdIdentifier(getSection(getAttributeTagParent(body.parentPath))), serialized && getRegisteredLocals(bodySection));
5365
+ return callRuntime(serialized ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(getResumeRegistryId(bodySection, "content")), _marko_compiler.types.arrowFunctionExpression(body.node.params, _marko_compiler.types.blockStatement(body.node.body)), getScopeIdIdentifier(getSection(getAttributeTagParent(body.parentPath))), serialized && getRegisteredLocals(bodySection));
4936
5366
  } else {
4937
5367
  const renderer = getSectionRendererIdentifier(bodySection);
4938
5368
  if (renderer) {
@@ -4951,7 +5381,7 @@ function getLocalClosureValues(bodySection) {
4951
5381
  if (bodySection.localClosures) return _marko_compiler.types.objectExpression(toArray(bodySection.localClosures, (closure) => toObjectProperty(getScopeAccessor(closure, true), getDeclaredBindingExpression(closure))));
4952
5382
  }
4953
5383
  function getSingleKnownSpread(paramsTree, attributes) {
4954
- if (paramsTree === true || !hasAllKnownProps(paramsTree)) return;
5384
+ if (paramsTree === true || !hasAllKnownProperties(paramsTree)) return;
4955
5385
  let binding;
4956
5386
  for (let i = attributes.length; i--;) {
4957
5387
  const attr = attributes[i];
@@ -4959,7 +5389,7 @@ function getSingleKnownSpread(paramsTree, attributes) {
4959
5389
  const spreadFrom = attr.value.extra?.spreadFrom;
4960
5390
  if (binding || !spreadFrom || Array.isArray(spreadFrom)) return;
4961
5391
  binding = spreadFrom;
4962
- } else if (binding && !propsUtil.has(binding.excludeProperties, attr.name)) return;
5392
+ } else if (binding && !propertiesUtil.has(binding.excludeProperties, attr.name)) return;
4963
5393
  }
4964
5394
  return binding;
4965
5395
  }
@@ -4967,7 +5397,6 @@ function getSingleKnownSpread(paramsTree, attributes) {
4967
5397
  //#region src/translator/util/known-tag.ts
4968
5398
  const [getTagVarBindings] = createOutputSectionState(() => []);
4969
5399
  const [getCallSiteSourcesByParam] = createAnalysisState(() => /* @__PURE__ */ new Map());
4970
- const kChildSection = Symbol("known tag child section");
4971
5400
  const kParamsTree = Symbol("known tag params tree");
4972
5401
  const kKnownExprs = Symbol("known tag exprs");
4973
5402
  const [getRecursiveTags] = createAnalysisState(() => []);
@@ -4976,16 +5405,17 @@ function knownTagAnalyze(tag, childSection, childParamsTree) {
4976
5405
  const section = ensureSection(tag);
4977
5406
  const tagBody = tag.get("body");
4978
5407
  const tagExtra = tag.node.extra ??= {};
5408
+ tagExtra.textBefore = mayMergeWithText(tag, true);
4979
5409
  tagExtra.childScopeBinding = createBinding("#childScope", 0, section);
5410
+ tagExtra.childSection = childSection;
4980
5411
  ensureBodySection(tagBody);
4981
5412
  trackParamsReferences(tagBody, 2);
4982
5413
  (section.knownTags ||= []).push(tagExtra);
4983
- tagExtra[kChildSection] = childSection;
4984
5414
  const varBinding = trackVarReferences(tag, 4);
4985
5415
  const recursive = isSameOrAncestorSection(childSection, section);
4986
5416
  let exprs;
4987
5417
  if (childSection.program === section.program) {
4988
- childSection.callSections = sectionUtil.add(childSection.callSections, section);
5418
+ childSection.renderedBy = push(childSection.renderedBy, tagExtra);
4989
5419
  if (recursive) getRecursiveTags().push(tag);
4990
5420
  else exprs = analyzeKnownTagParams(tag, exposeChildParamsTree(childSection));
4991
5421
  } else exprs = analyzeKnownTagParams(tag, childParamsTree);
@@ -5009,7 +5439,7 @@ function knownTagAnalyze(tag, childSection, childParamsTree) {
5009
5439
  }
5010
5440
  function analyzeRecursiveTags() {
5011
5441
  for (const tag of getRecursiveTags()) {
5012
- const childSection = tag.node.extra[kChildSection];
5442
+ const childSection = tag.node.extra.childSection;
5013
5443
  assertTerminates(tag, childSection);
5014
5444
  const exprs = analyzeKnownTagParams(tag, exposeChildParamsTree(childSection));
5015
5445
  if (tag.node.var) {
@@ -5024,8 +5454,8 @@ function assertTerminates(tag, childSection) {
5024
5454
  const callers = /* @__PURE__ */ new Set([getSection(tag)]);
5025
5455
  for (const caller of callers) {
5026
5456
  if (caller === childSection) throw tag.get("name").buildCodeFrameError(`A ${childSection === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section ? "template" : "`<define>`"} that renders itself outside a branch never terminates. Render \`<${getTagNameHint(tag.node)}>\` inside a branch that eventually stops, such as \`<if>\`.`);
5027
- forEach(caller.callSections, (callSection) => {
5028
- callers.add(callSection);
5457
+ forEach(caller.renderedBy, (call) => {
5458
+ callers.add(call.childScopeBinding.section);
5029
5459
  });
5030
5460
  }
5031
5461
  }
@@ -5037,7 +5467,7 @@ function analyzeKnownTagParams(tag, paramsTree) {
5037
5467
  const attrExprs = /* @__PURE__ */ new Set([tagExtra]);
5038
5468
  tagExtra[kParamsTree] = paramsTree;
5039
5469
  const exprs = tagExtra[kKnownExprs] = analyzeParams(tagExtra, getSection(tag), tag, paramsTree, attrExprs);
5040
- setTagContentDerives(tag, paramsTree?.props?.[0]?.binding, exprs);
5470
+ setTagContentDerives(tag, paramsTree?.properties?.[tag.node.arguments?.length ?? 0]?.binding, exprs);
5041
5471
  addReasonExprs(ensureSlot(tagExtra.childScopeBinding), fromIter(attrExprs));
5042
5472
  return exprs;
5043
5473
  }
@@ -5048,12 +5478,12 @@ function getReturnParams(section) {
5048
5478
  function assertReturns(tag, childSection) {
5049
5479
  if (!childSection.returnValueExpr) throw tag.get("var").buildCodeFrameError(`The \`${getTagNameHint(tag.node)}\` tag does not [\`<return>\`](https://markojs.com/docs/reference/core-tag#return) a value, so it does not support a [tag variable](https://markojs.com/docs/reference/language#tag-variables). Remove the variable, or add a \`<return>\` to the tag.`);
5050
5480
  }
5051
- function isChildScopeResumed(tagExtra) {
5052
- return !!findSlot(tagExtra.childScopeBinding)?.reason;
5481
+ function isChildScopeResumed(section, tagExtra) {
5482
+ return isEverWritten(section, findSlot(tagExtra.childScopeBinding)?.reason);
5053
5483
  }
5054
5484
  function getRenderArgs(tag, properties) {
5055
5485
  const args = tag.node.arguments;
5056
- const renderArgs = args?.length && !args.every(isDroppedNode) ? args.map(toRenderArg) : [];
5486
+ const renderArgs = args?.length && (properties.length || !args.every(isDroppedNode)) ? args.map(toRenderArg) : [];
5057
5487
  if (!renderArgs.length || properties.length) renderArgs.push(propsToExpression(properties));
5058
5488
  return renderArgs;
5059
5489
  }
@@ -5061,39 +5491,39 @@ function isDroppedNode(node) {
5061
5491
  return !!node.extra?.dropped;
5062
5492
  }
5063
5493
  function toRenderArg(arg) {
5064
- return isDroppedNode(arg) ? _marko_compiler.types.buildUndefinedNode() : arg;
5494
+ return isDroppedNode(arg) ? absentArg(0) : arg;
5065
5495
  }
5066
5496
  function knownTagTranslateHTML(tag, tagIdentifier) {
5067
5497
  const { node } = tag;
5068
5498
  const tagExtra = node.extra;
5069
- const childSection = tagExtra[kChildSection];
5499
+ const childSection = tagExtra.childSection;
5070
5500
  const paramsTree = getSettledParamsTree(tagExtra[kParamsTree]);
5071
5501
  writeHTMLResumeStatements(tag);
5072
5502
  const tagVar = node.var;
5073
5503
  const section = getSection(tag);
5074
- const attrsTree = paramsTree?.props?.[tag.node.arguments?.length || 0];
5075
- const { properties, statements } = paramsTree && !paramsTree.props || attrsTree ? translateAttrs(tag, attrsTree) : {
5504
+ const attrsTree = paramsTree?.properties?.[tag.node.arguments?.length || 0];
5505
+ const { properties, statements } = paramsTree && !paramsTree.properties || attrsTree ? translateAttrs(tag, attrsTree) : {
5076
5506
  properties: [],
5077
5507
  statements: []
5078
5508
  };
5079
5509
  const childScopeBinding = tagExtra.childScopeBinding;
5080
5510
  let varStatement;
5081
- if (isChildScopeResumed(tagExtra)) {
5082
- const peekScopeId = generateUidIdentifier(childScopeBinding?.name);
5511
+ if (isChildScopeResumed(section, tagExtra)) {
5512
+ const peekScopeId = generateUidIdentifier(childScopeBinding.name);
5083
5513
  statements.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(peekScopeId, callRuntime("_peek_scope_id"))]));
5084
5514
  const childScopeSlot = findSlot(childScopeBinding);
5085
5515
  writeSlot(childScopeSlot, callRuntime("_existing_scope", peekScopeId));
5086
- if (tagVar) varStatement = _marko_compiler.types.expressionStatement(getExprIfWritten(section, childScopeSlot.reason, callRuntime("_var", getScopeIdIdentifier(section), getScopeOffsetAccessorLiteral(childScopeBinding), peekScopeId, _marko_compiler.types.stringLiteral(getResumeRegisterId(section, tagVar.extra?.binding, "var")))));
5516
+ if (tagVar) varStatement = _marko_compiler.types.expressionStatement(getExprIfWritten(section, childScopeSlot.reason, callRuntime("_var", getScopeIdIdentifier(section), getScopeOffsetAccessorLiteral(childScopeBinding), peekScopeId, _marko_compiler.types.stringLiteral(getResumeRegistryId(section, tagVar.extra?.binding, "var")))));
5087
5517
  }
5088
5518
  if (childSection.paramReasonGroups) {
5089
5519
  const childGroupMask = buildChildGroupMask(section, childScopeBinding, childSection.paramReasonGroups);
5090
- if (childGroupMask) tag.insertBefore(_marko_compiler.types.expressionStatement(callRuntime("_set_scope_reason", childGroupMask)));
5520
+ if (childGroupMask) statements.unshift(_marko_compiler.types.expressionStatement(callRuntime("_set_scope_reason", childGroupMask)));
5091
5521
  }
5092
5522
  if (tagVar) {
5093
5523
  translateVar(tag, _marko_compiler.types.callExpression(tagIdentifier, getRenderArgs(tag, properties)), "let", statements);
5094
5524
  if (varStatement) statements.push(varStatement);
5095
5525
  } else statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(tagIdentifier, getRenderArgs(tag, properties))));
5096
- for (const replacement of tag.replaceWithMultiple(statements)) replacement.skip();
5526
+ replaceWithStatements(tag, statements);
5097
5527
  }
5098
5528
  function knownTagTranslateDOM(tag, getBindingIdentifier, callSetup) {
5099
5529
  const tagSection = getSection(tag);
@@ -5104,7 +5534,7 @@ function knownTagTranslateDOM(tag, getBindingIdentifier, callSetup) {
5104
5534
  if (node.var) {
5105
5535
  const varBinding = node.var.extra.binding;
5106
5536
  const signal = initValue(varBinding);
5107
- signal.register = isChildScopeResumed(extra);
5537
+ signal.register = isChildScopeResumed(getSection(tag), extra);
5108
5538
  signal.referenced = true;
5109
5539
  signal.buildAssignment = (valueSection, value) => buildVarChange(createScopeReadExpression(childScopeBinding, valueSection), value, varBinding);
5110
5540
  getTagVarBindings(tagSection).push(_marko_compiler.types.expressionStatement(callRuntime("_var", scopeIdentifier, getScopeAccessorLiteral(childScopeBinding, true), signal.identifier)));
@@ -5122,8 +5552,8 @@ function getCallSiteSources(param) {
5122
5552
  if (sourcesByParam.has(param)) return sourcesByParam.get(param);
5123
5553
  const body = param.section;
5124
5554
  let sources;
5125
- forEach(body.callSections, (callSection) => {
5126
- for (const tagExtra of callSection.knownTags) if (tagExtra[kChildSection] === body) sources = mergeSources(sources, getSourcesForExprs(mapParamBindingToExpr(tagExtra[kKnownExprs], param)));
5555
+ forEach(body.renderedBy, (call) => {
5556
+ sources = mergeSources(sources, getSourcesForExprs(mapParamBindingToExpr(call[kKnownExprs], param)));
5127
5557
  });
5128
5558
  sourcesByParam.set(param, sources);
5129
5559
  return sources;
@@ -5136,8 +5566,8 @@ function addKnownTagReasons(section) {
5136
5566
  for (const tagExtra of section.knownTags || []) {
5137
5567
  const { childScopeBinding } = tagExtra;
5138
5568
  const knownExprs = tagExtra[kKnownExprs];
5139
- const childSection = tagExtra[kChildSection];
5140
- if (knownExprs && childScopeBinding && childSection.paramReasonGroups) {
5569
+ const { childSection } = tagExtra;
5570
+ if (knownExprs && childSection.paramReasonGroups) {
5141
5571
  for (const group of childSection.paramReasonGroups) if (!findSlot(childScopeBinding, 5, section, group)) {
5142
5572
  const slot = ensureSlot(childScopeBinding, 5, section, group);
5143
5573
  slot.reasonExprs = mapParamReasonToExpr(knownExprs, group);
@@ -5148,7 +5578,7 @@ function addKnownTagReasons(section) {
5148
5578
  }
5149
5579
  function callsOtherTemplateSetup(section) {
5150
5580
  for (const tagExtra of section.knownTags || []) {
5151
- const childSection = tagExtra[kChildSection];
5581
+ const { childSection } = tagExtra;
5152
5582
  if (tagExtra.tagNameLoad || childSection.program !== section.program && childSection.hasSetupWork) return true;
5153
5583
  }
5154
5584
  return false;
@@ -5176,7 +5606,7 @@ function analyzeParams(rootTagExtra, section, tag, paramsTree, rootAttrExprs) {
5176
5606
  const known = paramsExpr.known = {};
5177
5607
  let i = 0;
5178
5608
  if (tag.node.arguments) for (const arg of tag.node.arguments) {
5179
- const argTree = paramsTree.props[i];
5609
+ const argTree = paramsTree.properties[i];
5180
5610
  if (argTree) {
5181
5611
  const argValueExtra = arg.extra ??= {};
5182
5612
  known[i] = { value: argValueExtra };
@@ -5186,7 +5616,7 @@ function analyzeParams(rootTagExtra, section, tag, paramsTree, rootAttrExprs) {
5186
5616
  } else dropNodes(arg);
5187
5617
  i++;
5188
5618
  }
5189
- const attrsTree = paramsTree.props[i];
5619
+ const attrsTree = paramsTree.properties[i];
5190
5620
  if (attrsTree) known[i] = analyzeAttrs(rootTagExtra, section, tag, attrsTree, rootAttrExprs, paramsExpr);
5191
5621
  else {
5192
5622
  const args = tag.node.arguments;
@@ -5198,14 +5628,14 @@ function analyzeParams(rootTagExtra, section, tag, paramsTree, rootAttrExprs) {
5198
5628
  }
5199
5629
  function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, rootExprs) {
5200
5630
  const inputExpr = {};
5201
- if (!paramsTree.props) {
5631
+ if (!paramsTree.properties) {
5202
5632
  inputExpr.value = setDerivedFromTag(section, tag, paramsTree.binding, rootExprs);
5203
5633
  return inputExpr;
5204
5634
  }
5205
5635
  const known = inputExpr.known = {};
5206
5636
  const attrTagLookup = analyzeAttributeTags(tag);
5207
5637
  const seen = /* @__PURE__ */ new Set();
5208
- const remaining = new Set(getAllKnownPropNames(paramsTree));
5638
+ const remaining = new Set(getAllKnownPropertyNames(paramsTree));
5209
5639
  const dropReferenceNodes = [];
5210
5640
  let restReferenceNodes;
5211
5641
  if (attrTagLookup) {
@@ -5233,7 +5663,7 @@ function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, roo
5233
5663
  else if (childAttrTree === true) {
5234
5664
  getAllTagReferenceNodes(child.node, restReferenceNodes ||= []);
5235
5665
  known[attrTagMeta.name] = { value: rootTagExtra };
5236
- } else if (childAttrTree.props && !(attrTagMeta.repeated && childAttrTree.rest)) {
5666
+ } else if (childAttrTree.properties && !(attrTagMeta.repeated && childAttrTree.rest)) {
5237
5667
  if (remaining.delete(attrTagMeta.name)) known[attrTagMeta.name] = analyzeAttrs(rootTagExtra, section, child, childAttrTree, rootAttrExprs, rootExprs);
5238
5668
  else dropAttrTag(child.node, dropReferenceNodes);
5239
5669
  } else analyzeDynamicAttrTagChildGroup(attrTagMeta.group, child);
@@ -5331,7 +5761,7 @@ function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, roo
5331
5761
  setDerivedFrom(attrTree === true ? paramsTree.rest.binding : attrTree.binding, propExtra, rootExprs);
5332
5762
  }
5333
5763
  else if (spreadReferenceNodes) {
5334
- if (remaining.size || paramsTree.rest && !paramsTree.rest.props) {
5764
+ if (remaining.size || paramsTree.rest && !paramsTree.rest.properties) {
5335
5765
  inputExpr.value = mergeReferences(section, tag.node, spreadReferenceNodes);
5336
5766
  setDerivedFrom(paramsTree.rest?.binding || paramsTree.binding, inputExpr.value, rootExprs);
5337
5767
  } else dropNodes(spreadReferenceNodes);
@@ -5341,13 +5771,13 @@ function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, roo
5341
5771
  setDerivedFrom(paramsTree.rest.binding, inputExpr.value, rootExprs);
5342
5772
  }
5343
5773
  if (remaining.size) addSetupWork(section);
5344
- if (paramsTree.rest && !paramsTree.rest.props) addSetupExpr(section, tag.node);
5774
+ if (paramsTree.rest && !paramsTree.rest.properties) addSetupExpr(section, tag.node);
5345
5775
  }
5346
5776
  dropNodes(dropReferenceNodes);
5347
5777
  return inputExpr;
5348
5778
  }
5349
5779
  function readsParamsByName(tag, paramsTree) {
5350
- return !!paramsTree.props && !paramsTree.rest && !tag.node.arguments?.some(isSpreadArgument);
5780
+ return !!paramsTree.properties && !paramsTree.rest && !tag.node.arguments?.some(isSpreadArgument);
5351
5781
  }
5352
5782
  function isSpreadArgument(arg) {
5353
5783
  return arg.type === "SpreadElement";
@@ -5385,11 +5815,11 @@ function writeParamsToSignals(tag, paramsTree, hint, info) {
5385
5815
  }
5386
5816
  let i = 0;
5387
5817
  if (tag.node.arguments) for (const arg of tag.node.arguments) {
5388
- const argTree = paramsTree.props[i];
5818
+ const argTree = paramsTree.properties[i];
5389
5819
  if (argTree) writeToSignal(info, info.getBindingIdentifier(argTree.binding, `${hint}_param_${i}`), arg.extra, arg, true);
5390
5820
  i++;
5391
5821
  }
5392
- const attrsTree = paramsTree.props[i];
5822
+ const attrsTree = paramsTree.properties[i];
5393
5823
  if (attrsTree) writeAttrsToSignals(tag, attrsTree, `${hint}_input`, info);
5394
5824
  }
5395
5825
  function applyAttrObject(tag, paramsTree, tagInputIdentifier, info) {
@@ -5404,14 +5834,14 @@ function applyAttrObject(tag, paramsTree, tagInputIdentifier, info) {
5404
5834
  writeToSignal(info, tagInputIdentifier, tagExtra, translatedProps, true);
5405
5835
  }
5406
5836
  function writeAttrsToSignals(tag, paramsTree, hint, info) {
5407
- if (!paramsTree.props) {
5837
+ if (!paramsTree.properties) {
5408
5838
  applyAttrObject(tag, paramsTree, info.getBindingIdentifier(paramsTree.binding, hint), info);
5409
5839
  return;
5410
5840
  }
5411
5841
  const attrTagLookup = analyzeAttributeTags(tag);
5412
5842
  const seen = /* @__PURE__ */ new Set();
5413
5843
  const tagExtra = tag.node.extra;
5414
- const remaining = new Set(getAllKnownPropNames(paramsTree));
5844
+ const remaining = new Set(getAllKnownPropertyNames(paramsTree));
5415
5845
  const contentProps = [];
5416
5846
  if (attrTagLookup) {
5417
5847
  const attrTags = tag.get("attributeTags");
@@ -5445,7 +5875,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
5445
5875
  const translatedAttrs = translateAttrs(child, true, void 0, statements);
5446
5876
  addStatement("render", info.tagSection, tagExtra, statements);
5447
5877
  addAttrTag(contentProps, attrTagMeta, _marko_compiler.types.objectExpression(translatedAttrs.properties));
5448
- } else if (attrTagMeta.repeated && (!childAttrTree.props || childAttrTree.rest)) {
5878
+ } else if (attrTagMeta.repeated && (!childAttrTree.properties || childAttrTree.rest)) {
5449
5879
  if (remaining.delete(attrTagMeta.name)) applyAttrObject(child, childAttrTree, info.getBindingIdentifier(childAttrTree.binding, `${hint}_${attrTagMeta.name}`), info);
5450
5880
  } else {
5451
5881
  remaining.delete(attrTagMeta.name);
@@ -5524,7 +5954,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
5524
5954
  const propBinding = getPropertyAlias(knownSpread, prop);
5525
5955
  writeToSignal(info, propSignal, getKnownExprsAt(info.knownExprs, getParamsTreeAt(paramsTree, prop).binding).value, createScopeReadExpression(propBinding, info.tagSection), true);
5526
5956
  }
5527
- else if (hasSpread && (remaining.size || paramsTree.rest && !paramsTree.rest.props)) {
5957
+ else if (hasSpread && (remaining.size || paramsTree.rest && !paramsTree.rest.properties)) {
5528
5958
  const spreadExpr = propsToExpression(inputProps);
5529
5959
  let spreadId = spreadExpr;
5530
5960
  if (!isSimpleReference(spreadExpr)) {
@@ -5532,7 +5962,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
5532
5962
  addStatement("render", info.tagSection, tagExtra, [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(spreadId, spreadExpr)])]);
5533
5963
  }
5534
5964
  for (const name of remaining) writeToSignal(info, getSignalIdentifier(info, paramsTree, hint, name), tagExtra, toMemberExpression(_marko_compiler.types.cloneNode(spreadId, true), name));
5535
- if (paramsTree.rest && !paramsTree.rest.props) {
5965
+ if (paramsTree.rest && !paramsTree.rest.properties) {
5536
5966
  const props = [];
5537
5967
  const restId = _marko_compiler.types.identifier(paramsTree.rest.binding.name);
5538
5968
  forEach(paramsTree.rest.binding.excludeProperties, (name) => {
@@ -5545,7 +5975,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
5545
5975
  }
5546
5976
  } else {
5547
5977
  for (const name of remaining) writeToSignal(info, getSignalIdentifier(info, paramsTree, hint, name), void 0);
5548
- if (paramsTree.rest && !paramsTree.rest.props) writeToSignal(info, info.getBindingIdentifier(paramsTree.rest.binding, hint + "_$rest"), tagExtra, _marko_compiler.types.objectExpression(inputProps), true);
5978
+ if (paramsTree.rest && !paramsTree.rest.properties) writeToSignal(info, info.getBindingIdentifier(paramsTree.rest.binding, hint + "_$rest"), tagExtra, _marko_compiler.types.objectExpression(inputProps), true);
5549
5979
  }
5550
5980
  }
5551
5981
  function writeToSignal(info, signal, expr, value, isPure) {
@@ -5578,9 +6008,11 @@ function getGroupParamsTrees(group, attrTagLookup, paramsTree) {
5578
6008
  //#region src/translator/util/reasons.ts
5579
6009
  function addReason(slot, reason) {
5580
6010
  if (reason) {
5581
- const curReason = slot.reason;
5582
- const newReason = mergeSources(curReason, reason);
5583
- if (curReason !== newReason) setSlotReason(slot, newReason);
6011
+ const newReason = mergeSources(slot.reason, reason);
6012
+ if (slot.reason !== newReason) {
6013
+ reasonsVersion++;
6014
+ slot.reason = newReason;
6015
+ }
5584
6016
  }
5585
6017
  }
5586
6018
  function addAlwaysReason(binding) {
@@ -5609,18 +6041,15 @@ function mapBodyParams(section, reason, seen) {
5609
6041
  if (params === reason.param) return reason;
5610
6042
  return mergeSources(mapBodyParams(section, mapped, seen), withSources(reason, reason.state, params)) || ALWAYS;
5611
6043
  }
5612
- function isConditionalReason(reason) {
6044
+ function isGuardedReason(reason) {
5613
6045
  return !!reason && !reason.always && !reason.state;
5614
6046
  }
5615
- function isUnconditionalReason(reason) {
5616
- return !!reason && !isConditionalReason(reason);
5617
- }
5618
6047
  function isStateReason(reason) {
5619
6048
  return !!reason && !reason.always && !!reason.state;
5620
6049
  }
5621
6050
  function getSourcesForExpr(expr) {
5622
- const root = getCanonicalExtra(expr);
5623
- return isReferencedExtra(root) ? getSourcesForRef(getReferencedBindings(root)) : void 0;
6051
+ const root = getCanonicalExpr(expr);
6052
+ return isReferencedExtra(root) ? getSourcesForReferencedBindings(getReferencedBindings(root)) : void 0;
5624
6053
  }
5625
6054
  function getSourcesForExprs(exprs) {
5626
6055
  if (exprs) {
@@ -5628,8 +6057,8 @@ function getSourcesForExprs(exprs) {
5628
6057
  return reduce(exprs, mergeExprSources);
5629
6058
  }
5630
6059
  }
5631
- function getSourcesForRef(ref) {
5632
- return reduce(ref, mergeBindingSources);
6060
+ function getSourcesForReferencedBindings(bindings) {
6061
+ return reduce(bindings, mergeBindingSources);
5633
6062
  }
5634
6063
  function getSourcesForDerived({ binding, exprs, properties }) {
5635
6064
  if (exprs) return reduce(binding, (sources, binding) => mergeSources(sources, getSourcesForExprs(mapParamBindingToExpr(exprs, getDeepestPropertyAlias(binding, properties)))));
@@ -5670,7 +6099,7 @@ function mapParamBindingToExpr(exprs, binding) {
5670
6099
  if (isWholeAlias) {
5671
6100
  let result = curExpr.value;
5672
6101
  if (curExpr.known) {
5673
- for (const key in curExpr.known) if (!propsUtil.has(binding.excludeProperties, key)) result = concat(result, curExpr.known[key].value);
6102
+ for (const key in curExpr.known) if (!propertiesUtil.has(binding.excludeProperties, key)) result = concat(result, curExpr.known[key].value);
5674
6103
  }
5675
6104
  return result;
5676
6105
  }
@@ -5683,19 +6112,16 @@ function getKnownExprsAt(exprs, binding) {
5683
6112
  return binding.property === void 0 || !known.known ? known : known.known[binding.property] ?? { value: known.value };
5684
6113
  }
5685
6114
  function applyReasonExprs(section) {
5686
- forEach(section.slots, applySlotExprs);
5687
- }
5688
- function applySlotExprs(slot) {
5689
- addReason(slot, getSourcesForExprs(slot.reasonExprs));
6115
+ for (const slot of section.slots) addReason(slot, getSourcesForExprs(slot.reasonExprs));
5690
6116
  }
5691
6117
  function mergeSlotReasons(section) {
5692
- section.reason = reduce(section.slots, mergeSlotReason, section.reason);
6118
+ section.reason = section.slots.reduce(mergeSlotReason, section.reason);
5693
6119
  }
5694
6120
  function mergeSlotReason(sectionReason, slot) {
5695
6121
  return mergeSources(sectionReason, slot.reason);
5696
6122
  }
5697
6123
  function getNodeReasons(section) {
5698
- return reduce(section.slots, addNodeReason, void 0);
6124
+ return section.slots.reduce(addNodeReason, void 0);
5699
6125
  }
5700
6126
  function addNodeReason(reasons, slot) {
5701
6127
  return slot.reason && slot.kind === 0 && slot.owner.type === 0 ? sourcesUtil.add(reasons, slot.reason) : reasons;
@@ -5704,17 +6130,10 @@ let reasonsVersion = 0;
5704
6130
  function getReasonsVersion() {
5705
6131
  return reasonsVersion;
5706
6132
  }
5707
- function setSlotReason(slot, reason) {
5708
- if (!isSameSources(slot.reason, reason)) reasonsVersion++;
5709
- slot.reason = reason;
5710
- }
5711
6133
  function setParamReasonGroups(section, groups) {
5712
6134
  reasonsVersion++;
5713
6135
  section.paramReasonGroups = groups;
5714
6136
  }
5715
- function isSameSources(a, b) {
5716
- return !!a && compareSources(a, b) === 0;
5717
- }
5718
6137
  //#endregion
5719
6138
  //#region src/translator/util/bindings.ts
5720
6139
  const [getBindings] = createAnalysisState(() => /* @__PURE__ */ new Set());
@@ -5785,13 +6204,13 @@ function ensurePropertyAlias(binding, property) {
5785
6204
  return canonical.propertyAliases.get(property) || createBinding(canonical.name + toIdentifierAccess(property), canonical.type, canonical.section, canonical, property);
5786
6205
  }
5787
6206
  function addAssignedProperty(binding, property) {
5788
- if (binding.assignedProperties !== true) binding.assignedProperties = property === void 0 || propsUtil.add(binding.assignedProperties, property);
6207
+ if (binding.assignedProperties !== true) binding.assignedProperties = property === void 0 || propertiesUtil.add(binding.assignedProperties, property);
5789
6208
  }
5790
6209
  function getAssignedObject(binding) {
5791
6210
  let object;
5792
6211
  for (let alias = binding; alias.aliasOf && !isRest(alias); alias = alias.aliasOf) if (alias.property !== void 0) {
5793
6212
  const parent = getCanonicalBinding(alias.aliasOf);
5794
- if (parent.assignedProperties === true || propsUtil.has(parent.assignedProperties, alias.property)) object = alias.aliasOf;
6213
+ if (parent.assignedProperties === true || propertiesUtil.has(parent.assignedProperties, alias.property)) object = alias.aliasOf;
5795
6214
  }
5796
6215
  return object;
5797
6216
  }
@@ -5836,7 +6255,7 @@ function getAliasRoot(binding) {
5836
6255
  const bindingUtil = new Sorted(function compareBindings(a, b) {
5837
6256
  return a === b ? 0 : a.section.id - b.section.id || +(b.type === 0) - +(a.type === 0) || a.uid - b.uid;
5838
6257
  });
5839
- const propsUtil = new Sorted(function compareProps(a, b) {
6258
+ const propertiesUtil = new Sorted(function compareProperties(a, b) {
5840
6259
  return a < b ? -1 : a > b ? 1 : 0;
5841
6260
  });
5842
6261
  function getCanonicalBinding(binding) {
@@ -5884,11 +6303,11 @@ function getDebugName(binding) {
5884
6303
  const { root, access } = getDebugAccess(binding, isTemplateParam(binding), toAccess);
5885
6304
  return root.name + access;
5886
6305
  }
5887
- function getDebugNames(refs) {
5888
- return mapToString(refs, ", ", getDebugName);
6306
+ function getDebugNames(bindings) {
6307
+ return mapToString(bindings, ", ", getDebugName);
5889
6308
  }
5890
- function getDebugNamesAsIdentifier(refs) {
5891
- return mapToString(refs, "__OR__", getDebugNameAsIdentifier);
6309
+ function getDebugNamesAsIdentifier(bindings) {
6310
+ return mapToString(bindings, "__OR__", getDebugNameAsIdentifier);
5892
6311
  }
5893
6312
  function getDebugNameAsIdentifier(binding) {
5894
6313
  const { root, access } = getDebugAccess(binding, isTemplateParam(binding), toIdentifierAccess);
@@ -5908,8 +6327,8 @@ function isReadBeyondInvoking(binding) {
5908
6327
  function isOwnBinding(binding) {
5909
6328
  return binding.section.program === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
5910
6329
  }
5911
- function hasNonConstantPropertyAlias(ref) {
5912
- for (const alias of ref.propertyAliases.values()) if (alias.type !== 5) return true;
6330
+ function hasNonConstantPropertyAlias(binding) {
6331
+ for (const alias of binding.propertyAliases.values()) if (alias.type !== 5) return true;
5913
6332
  return false;
5914
6333
  }
5915
6334
  function getPropertyPath(binding, ancestor) {
@@ -5938,11 +6357,14 @@ function isOnlyChild(tag) {
5938
6357
  function initBranchSection(bodySection, branchExpr, branch) {
5939
6358
  bodySection.branchExpr = branchExpr;
5940
6359
  bodySection.branch = branch;
5941
- branch.nodeBinding.branchBodies = push(branch.nodeBinding.branchBodies, bodySection);
6360
+ const { nodeBinding } = branch.tag;
6361
+ nodeBinding.branchBodies = push(nodeBinding.branchBodies, bodySection);
5942
6362
  }
5943
6363
  function resumeOwnerByMarkerWhenUnconditional(bodySection, nodeBinding) {
5944
6364
  const branchExprReason = findSlot(nodeBinding, 4)?.reason;
5945
- if (isStateReason(branchExprReason) && some(branchExprReason.state, hasResumableAssignment) && isUnconditionalReason(getBranchWriteReason(bodySection)) && isUnconditionalReason(getWriteReason(nodeBinding))) setSectionOwnerResumedByMarker(bodySection);
6365
+ const branchReason = getBranchWriteReason(bodySection);
6366
+ const nodeReason = getWriteReason(nodeBinding);
6367
+ if (isStateReason(branchExprReason) && some(branchExprReason.state, hasResumableAssignment) && branchReason && !isGuardedReason(branchReason) && nodeReason && !isGuardedReason(nodeReason)) setSectionOwnerResumedByMarker(bodySection);
5946
6368
  }
5947
6369
  function getBranchResumeArgs(tag, branchReasons, singleNode) {
5948
6370
  const tagSection = getSection(tag);
@@ -5974,8 +6396,8 @@ const [getBranchEndTags] = createOutputState(() => /* @__PURE__ */ new Set());
5974
6396
  function isEndTagWrittenByBranch(nodeBinding) {
5975
6397
  return !!nodeBinding && getBranchEndTags().has(nodeBinding);
5976
6398
  }
5977
- function isSingleNodeBranch(bodySection) {
5978
- return !!(bodySection?.content?.singleChild && bodySection.content.startType === 3);
6399
+ function isSingleNodeContent(content) {
6400
+ return !!(content?.singleChild && content.startType === 3);
5979
6401
  }
5980
6402
  function buildForRuntimeCall(type, attrs, params, statements) {
5981
6403
  return _marko_compiler.types.expressionStatement(callRuntime(forTypeToRuntime(type), ...getBaseArgsInForTag(type, attrs), _marko_compiler.types.arrowFunctionExpression(params, _marko_compiler.types.blockStatement(statements))));
@@ -6076,189 +6498,59 @@ function assertNoBodyContent(tag) {
6076
6498
  function buildAttrsError(tag, attrs, msg) {
6077
6499
  return buildRangeError(tag, attrs[0].loc?.start, attrs[attrs.length - 1].loc?.end, msg);
6078
6500
  }
6079
- function buildAttrNameError(tag, attr, msg) {
6080
- const start = attr.loc?.start;
6081
- return buildRangeError(tag, start, start && {
6082
- line: start.line,
6083
- column: start.column + attr.name.length
6084
- }, msg);
6085
- }
6086
- function buildUnsupportedAttrsError(tag, change, hint) {
6087
- const { attributes } = tag.node;
6088
- const valueAttr = attributes.find(isValueAttr);
6089
- const changeAttr = change ? attributes.find(isValueChangeAttr) : void 0;
6090
- const unsupported = attributes.filter((attr) => attr !== valueAttr && attr !== changeAttr);
6091
- const [attr] = unsupported;
6092
- return buildAttrsError(tag, unsupported, withHint(`The ${coreTagLink(tag)} only supports the ${valueAttrLink}${change ? " and its change handler" : ""}.`, attr.type === "MarkoAttribute" ? hint?.(attr) : void 0));
6093
- }
6094
- function buildRangeError(tag, start, end, msg) {
6095
- return start && end ? tag.hub.buildError({ loc: {
6096
- start,
6097
- end
6098
- } }, msg, Error) : tag.get("name").buildCodeFrameError(msg);
6099
- }
6100
- /** The loop a `<for>` tag's attributes run, which it requires. */
6101
- function assertForType(tag) {
6102
- const type = getForType(tag.node);
6103
- if (!type) throw tag.buildCodeFrameError(`The ${coreTagLink(tag)} requires an \`of=\`, \`in=\`, \`to=\`, or \`until=\` attribute.`);
6104
- return type;
6105
- }
6106
- /** The attributes a loop of `type` takes, besides `by=`. */
6107
- function getForAttrs(type) {
6108
- return type === "of" || type === "in" ? [type] : [
6109
- type,
6110
- "from",
6111
- "step"
6112
- ];
6113
- }
6114
- /** Throws for a param that a loop of `type` never supplies. */
6115
- function assertForParams(tag, type) {
6116
- const extraParam = tag.node.body.params[type === "of" || type === "in" ? 2 : 1];
6117
- if (extraParam && extraParam.type !== "RestElement") throw tag.hub.buildError(extraParam, `The ${coreTagLink(tag)} only provides \`|${type === "of" ? "item, index" : type === "in" ? "key, value" : "num"}|\` with \`${type}=\`, so this parameter is never supplied.`);
6118
- }
6119
- function coreTagLink(tag) {
6120
- const tagName = getTagName(tag);
6121
- const anchor = docsAnchors[tagName] ?? tagName;
6122
- return `[\`<${tagName}>\` tag](https://markojs.com/docs/reference/core-tag${anchor && "#" + anchor})`;
6123
- }
6124
- function withHint(msg, hint) {
6125
- return hint ? `${msg} ${hint}` : msg;
6126
- }
6127
- function isValueAttr(attr) {
6128
- return attr.type === "MarkoAttribute" && attr.name === "value";
6129
- }
6130
- function isValueChangeAttr(attr) {
6131
- return attr.type === "MarkoAttribute" && attr.name === "valueChange";
6132
- }
6133
- //#endregion
6134
- //#region src/common/errors.ts
6135
- const lowercaseOnAttrReg = /^on[a-z]/;
6136
- function assertExclusiveAttrs(attrs, onError = throwErr, isSet = isTruthy) {
6137
- if (attrs) {
6138
- let exclusiveAttrs;
6139
- if (isSet(attrs.checkedChange)) (exclusiveAttrs ||= []).push("checkedChange");
6140
- if ("checkedValue" in attrs) {
6141
- (exclusiveAttrs ||= []).push("checkedValue");
6142
- if ("checked" in attrs) exclusiveAttrs.push("checked");
6143
- } else if (isSet(attrs.checkedValueChange)) {
6144
- (exclusiveAttrs ||= []).push("checkedValueChange");
6145
- if ("checked" in attrs) exclusiveAttrs.push("checked");
6146
- }
6147
- if (isSet(attrs.valueChange)) {
6148
- (exclusiveAttrs ||= []).push("valueChange");
6149
- if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
6150
- }
6151
- if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
6152
- }
6153
- }
6154
- function isTruthy(value) {
6155
- return value;
6156
- }
6157
- function throwErr(msg) {
6158
- throw new Error(msg);
6159
- }
6160
- function joinWithAnd(a) {
6161
- switch (a.length) {
6162
- case 0: return "";
6163
- case 1: return a[0];
6164
- case 2: return `${a[0]} and ${a[1]}`;
6165
- default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
6166
- }
6167
- }
6168
- //#endregion
6169
- //#region src/html/attrs.ts
6170
- function _attr_class(value) {
6171
- return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
6172
- }
6173
- function _attr_style(value) {
6174
- return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
6175
- }
6176
- function _attr(name, value) {
6177
- return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
6178
- }
6179
- function stringAttr(name, value) {
6180
- return value && " " + name + attrAssignment(value);
6181
- }
6182
- function stringifyAttr(name, value) {
6183
- switch (typeof value) {
6184
- case "string": return " " + name + attrAssignment(value);
6185
- case "boolean": return " " + name;
6186
- case "number": return " " + name + "=" + value;
6187
- }
6188
- return " " + name + attrAssignment(value + "");
6189
- }
6190
- const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
6191
- const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
6192
- const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
6193
- function attrAssignment(value) {
6194
- return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
6195
- }
6196
- function escapeSingleQuotedAttrValue(value) {
6197
- return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
6198
- }
6199
- function replaceUnsafeSingleQuoteAttrChar(match) {
6200
- return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
6201
- }
6202
- function escapeDoubleQuotedAttrValue(value) {
6203
- return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
6204
- }
6205
- function replaceUnsafeDoubleQuoteAttrChar(match) {
6206
- return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
6207
- }
6208
- //#endregion
6209
- //#region src/html/writer.ts
6210
- let $chunk;
6211
- function getState() {
6212
- return $chunk.boundary.state;
6501
+ function buildAttrNameError(tag, attr, msg) {
6502
+ const start = attr.loc?.start;
6503
+ return buildRangeError(tag, start, start && {
6504
+ line: start.line,
6505
+ column: start.column + attr.name.length
6506
+ }, msg);
6213
6507
  }
6214
- globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
6215
- //#endregion
6216
- //#region src/html/content.ts
6217
- var content_exports = /* @__PURE__ */ __exportAll({
6218
- _escape: () => _escape,
6219
- _escape_comment: () => _escape_comment,
6220
- _escape_script: () => _escape_script,
6221
- _escape_style: () => _escape_style,
6222
- _escape_style_value: () => _escape_style_value,
6223
- _to_text: () => _to_text,
6224
- _unescaped: () => _unescaped,
6225
- quoteScriptTemplateLiteral: () => quoteScriptTemplateLiteral
6226
- });
6227
- function _to_text(val) {
6228
- return val || val === 0 ? val + "" : "";
6508
+ function buildUnsupportedAttrsError(tag, change, hint) {
6509
+ const { attributes } = tag.node;
6510
+ const valueAttr = attributes.find(isValueAttr);
6511
+ const changeAttr = change ? attributes.find(isValueChangeAttr) : void 0;
6512
+ const unsupported = attributes.filter((attr) => attr !== valueAttr && attr !== changeAttr);
6513
+ const [attr] = unsupported;
6514
+ return buildAttrsError(tag, unsupported, withHint(`The ${coreTagLink(tag)} only supports the ${valueAttrLink}${change ? " and its change handler" : ""}.`, attr.type === "MarkoAttribute" ? hint?.(attr) : void 0));
6229
6515
  }
6230
- function _unescaped(val) {
6231
- return val ? val + "" : val === 0 ? "0" : "";
6516
+ function buildRangeError(tag, start, end, msg) {
6517
+ return start && end ? tag.hub.buildError({ loc: {
6518
+ start,
6519
+ end
6520
+ } }, msg, Error) : tag.get("name").buildCodeFrameError(msg);
6232
6521
  }
6233
- const unsafeXMLReg = /[<&\r]/g;
6234
- const replaceUnsafeXML = (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&#13;";
6235
- const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
6236
- function _escape(val) {
6237
- return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
6522
+ /** The loop a `<for>` tag's attributes run, which it requires. */
6523
+ function assertForType(tag) {
6524
+ const type = getForType(tag.node);
6525
+ if (!type) throw tag.buildCodeFrameError(`The ${coreTagLink(tag)} requires an \`of=\`, \`in=\`, \`to=\`, or \`until=\` attribute.`);
6526
+ return type;
6238
6527
  }
6239
- const unsafeScriptReg = /<(\/?script|!--)/gi;
6240
- const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\u003C$1") : str;
6241
- function _escape_script(val) {
6242
- return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
6528
+ /** The attributes a loop of `type` takes, besides `by=`. */
6529
+ function getForAttrs(type) {
6530
+ return type === "of" || type === "in" ? [type] : [
6531
+ type,
6532
+ "from",
6533
+ "step"
6534
+ ];
6243
6535
  }
6244
- const unsafeScriptTemplateLiteralReg = /[`\\\r]|\$\{|<(?=\/?script|!--)/gi;
6245
- const replaceUnsafeScriptTemplateLiteral = (c) => c === "<" ? "\\x3C" : c === "\r" ? "\\r" : "\\" + c;
6246
- const quoteScriptTemplateLiteral = (str) => "`" + (unsafeScriptTemplateLiteralReg.test(str) ? str.replace(unsafeScriptTemplateLiteralReg, replaceUnsafeScriptTemplateLiteral) : str) + "`";
6247
- const unsafeStyleReg = /<(\/style)/gi;
6248
- const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
6249
- function _escape_style(val) {
6250
- return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
6536
+ /** Throws for a param that a loop of `type` never supplies. */
6537
+ function assertForParams(tag, type) {
6538
+ const extraParam = tag.node.body.params[type === "of" || type === "in" ? 2 : 1];
6539
+ if (extraParam && extraParam.type !== "RestElement") throw tag.hub.buildError(extraParam, `The ${coreTagLink(tag)} only provides \`|${type === "of" ? "item, index" : type === "in" ? "key, value" : "num"}|\` with \`${type}=\`, so this parameter is never supplied.`);
6251
6540
  }
6252
- function _escape_style_value(val) {
6253
- return val || val === 0 ? escapeStyleValue(val + "") : "";
6541
+ function coreTagLink(tag) {
6542
+ const tagName = getTagName(tag);
6543
+ const anchor = docsAnchors[tagName] ?? tagName;
6544
+ return `[\`<${tagName}>\` tag](https://markojs.com/docs/reference/core-tag${anchor && "#" + anchor})`;
6254
6545
  }
6255
- const unsafeCommentReg = />/g;
6256
- function escapeCommentStr(str) {
6257
- if (unsafeCommentReg.test(str)) str = str.replace(unsafeCommentReg, "&gt;");
6258
- return str.startsWith(getState().commentPrefix) ? "&#" + str.charCodeAt(0) + ";" + str.slice(1) : str;
6546
+ function withHint(msg, hint) {
6547
+ return hint ? `${msg} ${hint}` : msg;
6259
6548
  }
6260
- function _escape_comment(val) {
6261
- return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
6549
+ function isValueAttr(attr) {
6550
+ return attr.type === "MarkoAttribute" && attr.name === "value";
6551
+ }
6552
+ function isValueChangeAttr(attr) {
6553
+ return attr.type === "MarkoAttribute" && attr.name === "valueChange";
6262
6554
  }
6263
6555
  //#endregion
6264
6556
  //#region src/translator/util/body-to-text.ts
@@ -6301,7 +6593,7 @@ function buildText(body, coerce, decodeEntities = false) {
6301
6593
  if (templateExpressions.length === 1 && !currentQuasi && !templateQuasis[0].value.cooked && !_marko_compiler.types.isStringLiteral(singleValue)) return singleValue;
6302
6594
  templateQuasis.push(toTemplateElement(currentQuasi, true));
6303
6595
  const literal = _marko_compiler.types.templateLiteral(templateQuasis, templateExpressions);
6304
- literal.extra = placeholderExtra && getCanonicalExtra(placeholderExtra);
6596
+ literal.extra = placeholderExtra && getCanonicalExpr(placeholderExtra);
6305
6597
  return literal;
6306
6598
  }
6307
6599
  return _marko_compiler.types.stringLiteral(currentQuasi);
@@ -6420,6 +6712,14 @@ function pushMarkup(structure, str) {
6420
6712
  function node(path, binding) {
6421
6713
  return addNode(path, binding, false);
6422
6714
  }
6715
+ function text(path, binding, marker) {
6716
+ getSection(path).structure?.push({
6717
+ kind: Node,
6718
+ binding,
6719
+ marker,
6720
+ text: true
6721
+ });
6722
+ }
6423
6723
  function marker(path, binding) {
6424
6724
  addNode(path, binding, true);
6425
6725
  }
@@ -6455,15 +6755,18 @@ function resolveStructure(section) {
6455
6755
  };
6456
6756
  if (section.content?.startType === 1) separate(resolved);
6457
6757
  let textEdge;
6758
+ const writeText = (value) => {
6759
+ if (textEdge === "child") separate(resolved);
6760
+ appendLiteral(resolved.writes, value);
6761
+ textEdge = "own";
6762
+ };
6458
6763
  for (const op of section.structure) if (typeof op === "string") {
6459
6764
  appendLiteral(resolved.writes, op);
6460
6765
  textEdge = void 0;
6461
6766
  } else if (typeof op === "number") resolved.steps.push(op);
6462
6767
  else switch (op.kind) {
6463
6768
  case Text:
6464
- if (textEdge === "child") separate(resolved);
6465
- appendLiteral(resolved.writes, op.value);
6466
- textEdge = "own";
6769
+ writeText(op.value);
6467
6770
  break;
6468
6771
  case ModuleRead:
6469
6772
  resolved.writes.push(toModuleReadExpression(op.read), "");
@@ -6471,12 +6774,14 @@ function resolveStructure(section) {
6471
6774
  break;
6472
6775
  case Node: {
6473
6776
  if (!op.binding) continue;
6777
+ const marker = op.marker ?? isKnownChild(section);
6778
+ if (op.text && !marker) writeText(" ");
6474
6779
  const withVar = hasScopeOffset(op.binding);
6475
- const code = op.marker ? withVar ? 49 : 37 : 32;
6780
+ const code = marker ? withVar ? 49 : 37 : 32;
6476
6781
  flushSteps(resolved);
6477
6782
  resolved.walkComment.push(walkCodeToName[code]);
6478
6783
  appendLiteral(resolved.walks, String.fromCharCode(code));
6479
- if (op.marker) {
6784
+ if (marker) {
6480
6785
  appendLiteral(resolved.writes, "<!>");
6481
6786
  textEdge = void 0;
6482
6787
  }
@@ -6521,7 +6826,7 @@ function resolveRef(ref, part) {
6521
6826
  declareOwnExports();
6522
6827
  return _marko_compiler.types.identifier(name);
6523
6828
  }
6524
- return importOrSelfReferenceName((0, _marko_compiler_babel_utils.getFile)(), ref.path, name, `${ref.hint}_${part}`);
6829
+ return (0, _marko_compiler_babel_utils.importNamed)((0, _marko_compiler_babel_utils.getFile)(), ref.path, name, `${ref.hint}_${part}`);
6525
6830
  }
6526
6831
  const [getSectionMeta] = createOutputSectionState((section) => {
6527
6832
  if (!section.structure || section.dropped) return {
@@ -6701,11 +7006,12 @@ const IfTag = {
6701
7006
  const ifTagExtra = ifTag.node.extra ??= {};
6702
7007
  const mergeReferenceNodes = [];
6703
7008
  const nodeBinding = controlFlowNode(ifTag, ifTagSection);
7009
+ ifTagExtra.textBefore = mayMergeWithText(ifTag, true);
6704
7010
  for (let index = 0; index < branches.length; index++) {
6705
7011
  const [branchTag, branchBodySection] = branches[index];
6706
7012
  if (branchBodySection) initBranchSection(branchBodySection, ifTagExtra, {
6707
- nodeBinding,
6708
- optional: true,
7013
+ kind: "if",
7014
+ tag: ifTagExtra,
6709
7015
  index
6710
7016
  });
6711
7017
  if (branchTag.node.attributes.length) mergeReferenceNodes.push(branchTag.node.attributes[0].value);
@@ -6731,7 +7037,6 @@ const IfTag = {
6731
7037
  if (isLastBranch(tag)) {
6732
7038
  const branches = getBranches(tag);
6733
7039
  const [ifTag] = branches[0];
6734
- const nextTag = tag.getNextSibling();
6735
7040
  let branchReasons;
6736
7041
  let statement;
6737
7042
  for (let i = branches.length; i--;) {
@@ -6751,10 +7056,10 @@ const IfTag = {
6751
7056
  }
6752
7057
  if (branchReasons) {
6753
7058
  const cbNode = _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([statement]));
6754
- statement = _marko_compiler.types.expressionStatement(callRuntime("_if", cbNode, ...getBranchResumeArgs(ifTag, branchReasons, branches.every(([, branchBody]) => isSingleNodeBranch(branchBody)))));
7059
+ statement = _marko_compiler.types.expressionStatement(callRuntime("_if", cbNode, ...getBranchResumeArgs(ifTag, branchReasons, branches.every(([, branchBody]) => isSingleNodeContent(branchBody?.content)))));
6755
7060
  }
6756
- for (const [branchTag] of branches) branchTag.remove();
6757
- nextTag.insertBefore(statement);
7061
+ for (const [branchTag] of branches) replaceWithStatements(branchTag);
7062
+ replaceWithStatements(tag, [statement]);
6758
7063
  }
6759
7064
  }
6760
7065
  },
@@ -6771,12 +7076,8 @@ const IfTag = {
6771
7076
  const [branchTag, branchBodySection] = branches[i];
6772
7077
  const [testAttr] = branchTag.node.attributes;
6773
7078
  const consequent = _marko_compiler.types.numericLiteral(branchBodySection ? i : -1);
6774
- if (branchBodySection) setClosureSignalBuilder(branchTag, {
6775
- kind: "if",
6776
- nodeBinding,
6777
- index: i
6778
- });
6779
- branchTag.remove();
7079
+ if (branchBodySection) setClosureSignalBuilder(branchTag);
7080
+ replaceWithStatements(branchTag);
6780
7081
  expr = testAttr ? _marko_compiler.types.conditionalExpression(testAttr.value, consequent, expr) : consequent;
6781
7082
  }
6782
7083
  const signal = getSignal(ifTagSection, nodeBinding, "if");
@@ -7016,7 +7317,7 @@ function getStaticNativeTagDef(tag) {
7016
7317
  }
7017
7318
  function buildChangeHandlerAttr(tag, attr) {
7018
7319
  const changeAttrName = attr.name + "Change";
7019
- let modifier;
7320
+ let refiningFn;
7020
7321
  if (attr.modifier != null) {
7021
7322
  if (!_marko_compiler.types.isValidIdentifier(attr.modifier)) throw tag.hub.buildError(attr.value.loc?.end && { loc: {
7022
7323
  start: {
@@ -7028,22 +7329,22 @@ function buildChangeHandlerAttr(tag, attr) {
7028
7329
  column: attr.value.loc.start.column - 2
7029
7330
  }
7030
7331
  } }, "Bound attribute refinement shorthand must be a valid JavaScript identifier.");
7031
- modifier = withPreviousLocation(_marko_compiler.types.identifier(attr.modifier), attr);
7332
+ refiningFn = withPreviousLocation(_marko_compiler.types.identifier(attr.modifier), attr);
7032
7333
  }
7033
7334
  if (_marko_compiler.types.isIdentifier(attr.value)) {
7034
7335
  const binding = tag.scope.getBinding(attr.value.name);
7035
- if (!binding) return _marko_compiler.types.markoAttribute(changeAttrName, buildChangeHandlerFunction(attr.value, modifier));
7036
- const modifierKey = modifier?.name ?? "";
7037
- let handlerByModifier = BINDING_CHANGE_HANDLER.get(binding.identifier);
7038
- if (!handlerByModifier) BINDING_CHANGE_HANDLER.set(binding.identifier, handlerByModifier = /* @__PURE__ */ new Map());
7039
- const existingChangedAttr = handlerByModifier.get(modifierKey);
7336
+ if (!binding) return _marko_compiler.types.markoAttribute(changeAttrName, buildChangeHandlerFunction(attr.value, refiningFn));
7337
+ const refiningFnKey = refiningFn?.name ?? "";
7338
+ let handlerByRefiningFn = BINDING_CHANGE_HANDLER.get(binding.identifier);
7339
+ if (!handlerByRefiningFn) BINDING_CHANGE_HANDLER.set(binding.identifier, handlerByRefiningFn = /* @__PURE__ */ new Map());
7340
+ const existingChangedAttr = handlerByRefiningFn.get(refiningFnKey);
7040
7341
  if (!existingChangedAttr) {
7041
7342
  const bindingIdentifierPath = binding.path.getOuterBindingIdentifierPaths()[binding.identifier.name];
7042
- let changeAttrExpr = bindingIdentifierPath ? bindingIdentifierPath.parentPath === binding.path ? buildChangeHandlerFunction(attr.value, modifier) : bindingIdentifierPath.parentPath.isObjectProperty() ? ensureDestructuredChangeHandler(bindingIdentifierPath.parentPath) : void 0 : void 0;
7343
+ let changeAttrExpr = bindingIdentifierPath ? bindingIdentifierPath.parentPath === binding.path ? buildChangeHandlerFunction(attr.value, refiningFn) : bindingIdentifierPath.parentPath.isObjectProperty() ? ensureDestructuredChangeHandler(bindingIdentifierPath.parentPath) : void 0 : void 0;
7043
7344
  if (!changeAttrExpr) throw tag.hub.buildError(attr.value, bindingIdentifierPath?.parentPath?.isArrayPattern() ? `Cannot two-way bind to \`${attr.value.name}\` because it comes from array destructuring, which has no change handler. Use object destructuring or pass an explicit \`${changeAttrName}\` attribute.` : bindingIdentifierPath?.parentPath?.isObjectProperty({ computed: true }) ? `Cannot two-way bind to \`${attr.value.name}\` because it is destructured with a dynamically computed key, so its change handler cannot be derived. Use a static key or pass an explicit \`${changeAttrName}\` attribute.` : "Unable to bind to value.");
7044
- if (modifier && _marko_compiler.types.isIdentifier(changeAttrExpr)) changeAttrExpr = _marko_compiler.types.logicalExpression("&&", changeAttrExpr, buildModifierForwarder(_marko_compiler.types.cloneNode(changeAttrExpr), modifier));
7345
+ if (refiningFn && _marko_compiler.types.isIdentifier(changeAttrExpr)) changeAttrExpr = _marko_compiler.types.logicalExpression("&&", changeAttrExpr, buildRefiningFnForwarder(_marko_compiler.types.cloneNode(changeAttrExpr), refiningFn));
7045
7346
  const changeHandlerAttr = _marko_compiler.types.markoAttribute(changeAttrName, changeAttrExpr);
7046
- handlerByModifier.set(modifierKey, changeHandlerAttr);
7347
+ handlerByRefiningFn.set(refiningFnKey, changeHandlerAttr);
7047
7348
  return changeHandlerAttr;
7048
7349
  }
7049
7350
  if (existingChangedAttr.type === "Identifier") return _marko_compiler.types.markoAttribute(changeAttrName, withPreviousLocation(_marko_compiler.types.identifier(existingChangedAttr.name), attr.value));
@@ -7051,7 +7352,7 @@ function buildChangeHandlerAttr(tag, attr) {
7051
7352
  if (!(markoRoot?.isMarkoTag() || markoRoot?.isMarkoTagBody())) throw tag.hub.buildError(attr.value, "Unable to bind to value.");
7052
7353
  const changeHandlerId = generateUid(changeAttrName);
7053
7354
  const changeHandlerConst = toConstTag(_marko_compiler.types.identifier(changeHandlerId), existingChangedAttr.value);
7054
- handlerByModifier.set(modifierKey, existingChangedAttr.value = _marko_compiler.types.identifier(changeHandlerId));
7355
+ handlerByRefiningFn.set(refiningFnKey, existingChangedAttr.value = _marko_compiler.types.identifier(changeHandlerId));
7055
7356
  if (markoRoot.isMarkoTag()) markoRoot.insertAfter(changeHandlerConst);
7056
7357
  else markoRoot.unshiftContainer("body", changeHandlerConst);
7057
7358
  return _marko_compiler.types.markoAttribute(changeAttrName, withPreviousLocation(_marko_compiler.types.identifier(changeHandlerId), attr.value));
@@ -7062,20 +7363,20 @@ function buildChangeHandlerAttr(tag, attr) {
7062
7363
  const memberProp = !attr.value.computed && prop.type === "Identifier" ? withPreviousLocation(_marko_compiler.types.identifier(prop.name + "Change"), prop) : _marko_compiler.types.binaryExpression("+", _marko_compiler.types.cloneNode(prop), _marko_compiler.types.stringLiteral("Change"));
7063
7364
  const computed = memberProp.type !== "Identifier";
7064
7365
  let changeAttrExpr = attr.value.optional ? _marko_compiler.types.optionalMemberExpression(memberObj, memberProp, computed, true) : _marko_compiler.types.memberExpression(memberObj, memberProp, computed);
7065
- if (modifier) changeAttrExpr = _marko_compiler.types.logicalExpression("&&", changeAttrExpr, buildModifierForwarder(_marko_compiler.types.memberExpression(memberObj, memberProp, computed), modifier));
7366
+ if (refiningFn) changeAttrExpr = _marko_compiler.types.logicalExpression("&&", changeAttrExpr, buildRefiningFnForwarder(_marko_compiler.types.memberExpression(memberObj, memberProp, computed), refiningFn));
7066
7367
  return _marko_compiler.types.markoAttribute(changeAttrName, changeAttrExpr);
7067
7368
  }
7068
7369
  }
7069
7370
  throw tag.hub.buildError(attr.value, "Attributes may only be bound to identifiers or member expressions");
7070
7371
  }
7071
- function buildModifierForwarder(changeHandler, modifier) {
7372
+ function buildRefiningFnForwarder(changeHandler, refiningFn) {
7072
7373
  const newValueId = generateUid("next");
7073
- return _marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier(newValueId)], _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(changeHandler, [_marko_compiler.types.callExpression(_marko_compiler.types.cloneNode(modifier), [_marko_compiler.types.identifier(newValueId)])]))]));
7374
+ return _marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier(newValueId)], _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(changeHandler, [_marko_compiler.types.callExpression(_marko_compiler.types.cloneNode(refiningFn), [_marko_compiler.types.identifier(newValueId)])]))]));
7074
7375
  }
7075
- function buildChangeHandlerFunction(id, modifier) {
7376
+ function buildChangeHandlerFunction(id, refiningFn) {
7076
7377
  const newId = "_new_" + id.name;
7077
7378
  let newValue = withPreviousLocation(_marko_compiler.types.identifier(newId), id);
7078
- if (modifier) newValue = _marko_compiler.types.callExpression(modifier, [newValue]);
7379
+ if (refiningFn) newValue = _marko_compiler.types.callExpression(refiningFn, [newValue]);
7079
7380
  return _marko_compiler.types.arrowFunctionExpression([withPreviousLocation(_marko_compiler.types.identifier(newId), id)], _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", withPreviousLocation(_marko_compiler.types.identifier(id.name), id), newValue))]));
7080
7381
  }
7081
7382
  function ensureDestructuredChangeHandler(parent) {
@@ -7185,10 +7486,10 @@ var await_default = {
7185
7486
  valueExtra.pure = false;
7186
7487
  setDerivedFrom(paramsBinding, valueExtra);
7187
7488
  }
7489
+ tagExtra.textBefore = mayMergeWithText(tag, true);
7188
7490
  initBranchSection(bodySection, valueExtra, {
7189
- nodeBinding,
7190
- optional: false,
7191
- await: true
7491
+ kind: "await",
7492
+ tag: tagExtra
7192
7493
  });
7193
7494
  addSetupWork(section);
7194
7495
  marker(tag, nodeBinding);
@@ -7208,7 +7509,7 @@ var await_default = {
7208
7509
  const bodySection = getSectionForBody(tagBody);
7209
7510
  setSectionOwnerResumedByMarker(bodySection);
7210
7511
  writeHTMLResumeStatements(tag);
7211
- tag.replaceWith(_marko_compiler.types.expressionStatement(callRuntime("_await", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), valueAttr.value, _marko_compiler.types.arrowFunctionExpression(node.body.params, toOnlyExpressionOrBlock(node.body.body)), getWriteGuard(section, bodySection.reason, true))))[0].skip();
7512
+ replaceWithStatements(tag, [_marko_compiler.types.expressionStatement(callRuntime("_await", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), valueAttr.value, _marko_compiler.types.arrowFunctionExpression(node.body.params, toOnlyExpressionOrBlock(node.body.body)), getWriteGuard(section, bodySection.reason, true)))]);
7212
7513
  }
7213
7514
  },
7214
7515
  dom: { exit(tag) {
@@ -7227,7 +7528,7 @@ var await_default = {
7227
7528
  };
7228
7529
  addStatement("render", section, void 0, _marko_compiler.types.callExpression(_marko_compiler.types.identifier(bodySection.name), [scopeIdentifier]));
7229
7530
  addValue(section, valueExpr.extra, signal, valueExpr);
7230
- tag.remove();
7531
+ replaceWithStatements(tag);
7231
7532
  } }
7232
7533
  }),
7233
7534
  attributes: {},
@@ -7287,95 +7588,6 @@ function createStatementTag(keyword) {
7287
7588
  //#region src/translator/core/client.ts
7288
7589
  var client_default = createStatementTag("client");
7289
7590
  //#endregion
7290
- //#region src/translator/util/evaluate.ts
7291
- const kEvaluated = Symbol("evaluated");
7292
- function evaluate(value) {
7293
- return (value.extra ??= {})[kEvaluated] ??= computeEvaluated(value);
7294
- }
7295
- function computeEvaluated(value) {
7296
- const computed = (0, _marko_compiler_babel_utils.computeNode)(value);
7297
- return computed ? {
7298
- confident: true,
7299
- computed: computed.value,
7300
- nullable: computed.value == null,
7301
- pure: true
7302
- } : {
7303
- confident: false,
7304
- computed: void 0,
7305
- nullable: isNullableExpr(value),
7306
- pure: !traverseContains(value, isImpure)
7307
- };
7308
- }
7309
- function isImpure(node) {
7310
- switch (node.type) {
7311
- case "ArrowFunctionExpression":
7312
- case "ClassPrivateMethod":
7313
- case "ClassPrivateProperty":
7314
- case "FunctionExpression": return skip;
7315
- case "ClassMethod":
7316
- case "ObjectMethod": return node.computed && traverseContains(node.key, isImpure) || skip;
7317
- case "ClassAccessorProperty":
7318
- case "ClassProperty": return node.static ? void 0 : node.computed && traverseContains(node.key, isImpure) || skip;
7319
- case "CallExpression": return node.callee.type === "ArrowFunctionExpression" || node.callee.type === "FunctionExpression" ? traverseContains(node.arguments, isImpure) || traverseContains(node.callee.params, isImpure) || traverseContains(node.callee.body, isImpure) || skip : true;
7320
- case "AssignmentExpression":
7321
- case "NewExpression":
7322
- case "OptionalCallExpression":
7323
- case "TaggedTemplateExpression":
7324
- case "ThrowStatement":
7325
- case "UpdateExpression": return true;
7326
- case "UnaryExpression": return node.operator === "delete";
7327
- }
7328
- }
7329
- function isNullableExpr(expr) {
7330
- switch (expr.type) {
7331
- case "ArrayExpression":
7332
- case "ArrowFunctionExpression":
7333
- case "BigIntLiteral":
7334
- case "BinaryExpression":
7335
- case "BooleanLiteral":
7336
- case "ClassExpression":
7337
- case "FunctionExpression":
7338
- case "NewExpression":
7339
- case "NumericLiteral":
7340
- case "ObjectExpression":
7341
- case "RegExpLiteral":
7342
- case "StringLiteral":
7343
- case "TemplateLiteral":
7344
- case "UpdateExpression": return false;
7345
- case "AssignmentExpression": switch (expr.operator) {
7346
- case "=": return isNullableExpr(expr.right);
7347
- case "*=":
7348
- case "/=":
7349
- case "%=":
7350
- case "+=":
7351
- case "-=":
7352
- case "<<=":
7353
- case ">>=":
7354
- case ">>>=":
7355
- case "&=":
7356
- case "^=":
7357
- case "|=":
7358
- case "**=": return false;
7359
- case "||=":
7360
- case "??=": return isNullableExpr(expr.right);
7361
- case "&&=": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
7362
- default: return true;
7363
- }
7364
- case "AwaitExpression": return isNullableExpr(expr.argument);
7365
- case "ConditionalExpression": return isNullableExpr(expr.consequent) || isNullableExpr(expr.alternate);
7366
- case "LogicalExpression": switch (expr.operator) {
7367
- case "||":
7368
- case "??": return isNullableExpr(expr.right);
7369
- case "&&": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
7370
- default: return true;
7371
- }
7372
- case "ParenthesizedExpression": return isNullableExpr(expr.expression);
7373
- case "SequenceExpression": return isNullableExpr(expr.expressions[expr.expressions.length - 1]);
7374
- case "UnaryExpression": return expr.operator === "void";
7375
- default: return true;
7376
- }
7377
- }
7378
- //#endregion
7379
7591
  //#region src/translator/core/const.ts
7380
7592
  var const_default = {
7381
7593
  analyze(tag) {
@@ -7413,7 +7625,7 @@ var const_default = {
7413
7625
  addValue(section, value.extra, signal, value);
7414
7626
  }
7415
7627
  } else if (!varBinding?.pruned || !value.extra?.dropped) translateVar(tag, value);
7416
- tag.remove();
7628
+ replaceWithStatements(tag);
7417
7629
  } },
7418
7630
  parseOptions: { openTagOnly: true },
7419
7631
  attributes: {},
@@ -7503,7 +7715,7 @@ var define_default = {
7503
7715
  translate: {
7504
7716
  enter(tag) {
7505
7717
  if (!tag.node.var || tag.node.body.extra?.dropped) {
7506
- tag.remove();
7718
+ replaceWithStatements(tag);
7507
7719
  return;
7508
7720
  }
7509
7721
  if (isOutputHTML()) flushBefore(tag);
@@ -7514,7 +7726,7 @@ var define_default = {
7514
7726
  if (isOutputHTML()) {
7515
7727
  writeHTMLResumeStatements(tag);
7516
7728
  translateVar(tag, propsToExpression(translatedAttrs.properties), "const", translatedAttrs.statements);
7517
- tag.insertBefore(translatedAttrs.statements);
7729
+ replaceWithStatements(tag, translatedAttrs.statements);
7518
7730
  } else {
7519
7731
  if (_marko_compiler.types.isIdentifier(node.var)) {
7520
7732
  const babelBinding = tag.scope.getBinding(node.var.name);
@@ -7532,15 +7744,15 @@ var define_default = {
7532
7744
  };
7533
7745
  }
7534
7746
  if (bodySection && allDirectReferences) {
7535
- tag.remove();
7747
+ replaceWithStatements(tag);
7536
7748
  return;
7537
7749
  }
7538
7750
  }
7539
7751
  const section = getSection(tag);
7540
7752
  if (translatedAttrs.statements.length) addStatement("render", section, node.extra, translatedAttrs.statements);
7541
7753
  addValue(section, node.extra, initValue(tag.get("var").node.extra.binding), propsToExpression(translatedAttrs.properties));
7754
+ replaceWithStatements(tag);
7542
7755
  }
7543
- tag.remove();
7544
7756
  }
7545
7757
  },
7546
7758
  attributes: {},
@@ -7640,9 +7852,10 @@ var for_default = {
7640
7852
  onFinalizeReferences(() => detectForSelector(bodySection, keyBinding));
7641
7853
  }
7642
7854
  }
7855
+ tagExtra.textBefore = mayMergeWithText(tag, true);
7643
7856
  initBranchSection(bodySection, tagExtra, {
7644
- nodeBinding,
7645
- optional: true
7857
+ kind: "for",
7858
+ tag: tagExtra
7646
7859
  });
7647
7860
  },
7648
7861
  translate: translateByTarget({
@@ -7650,7 +7863,7 @@ var for_default = {
7650
7863
  enter(tag) {
7651
7864
  if (tag.node.body.attributeTags) return;
7652
7865
  if (!getSectionForBody(tag.get("body"))) {
7653
- tag.remove();
7866
+ replaceWithStatements(tag);
7654
7867
  return;
7655
7868
  }
7656
7869
  flushBefore(tag);
@@ -7671,15 +7884,15 @@ var for_default = {
7671
7884
  const forTagArgs = getBaseArgsInForTag(forType, forAttrs);
7672
7885
  const forTagHTMLRuntime = branchReason ? forTypeToBranchRuntime(forType) : forTypeToRuntime(forType);
7673
7886
  forTagArgs.push(_marko_compiler.types.arrowFunctionExpression(params, _marko_compiler.types.blockStatement(bodyStatements)));
7674
- if (branchReason) forTagArgs.push(forAttrs.by || _marko_compiler.types.numericLiteral(0), ...getBranchResumeArgs(tag, branchReason, isSingleNodeBranch(bodySection)));
7887
+ if (branchReason) forTagArgs.push(forAttrs.by || _marko_compiler.types.numericLiteral(0), ...getBranchResumeArgs(tag, branchReason, isSingleNodeContent(bodySection?.content)));
7675
7888
  statements.push(_marko_compiler.types.expressionStatement(callRuntime(forTagHTMLRuntime, ...forTagArgs)));
7676
- for (const replacement of tag.replaceWithMultiple(statements)) replacement.skip();
7889
+ replaceWithStatements(tag, statements);
7677
7890
  }
7678
7891
  },
7679
7892
  dom: {
7680
7893
  enter(tag) {
7681
7894
  if (tag.node.body.attributeTags) return;
7682
- if (!getSectionForBody(tag.get("body"))) tag.remove();
7895
+ if (!getSectionForBody(tag.get("body"))) replaceWithStatements(tag);
7683
7896
  },
7684
7897
  exit(tag) {
7685
7898
  if (tag.node.body.attributeTags) return;
@@ -7689,12 +7902,8 @@ var for_default = {
7689
7902
  const { node } = tag;
7690
7903
  const tagExtra = node.extra;
7691
7904
  const nodeBinding = tagExtra.nodeBinding;
7692
- const hop = {
7693
- kind: "for",
7694
- nodeBinding
7695
- };
7696
- setClosureSignalBuilder(tag, hop, (closure, render) => {
7697
- if (!isForSelectorClosure(bodySection, closure)) return buildClosureHop(hop, render);
7905
+ setClosureSignalBuilder(tag, (closure, render) => {
7906
+ if (!isForSelectorClosure(bodySection, closure)) return buildClosureHop(bodySection, render);
7698
7907
  return callRuntime("_for_selector", getScopeAccessorLiteral(nodeBinding, true), getScopeAccessorLiteral(closure, true), render);
7699
7908
  });
7700
7909
  const forType = getForType(node);
@@ -7706,7 +7915,7 @@ var for_default = {
7706
7915
  const loopArgs = getBaseArgsInForTag(forType, forAttrs);
7707
7916
  if (forAttrs.by) loopArgs.push(forAttrs.by);
7708
7917
  addValue(tagSection, tagExtra, signal, _marko_compiler.types.arrayExpression(loopArgs));
7709
- tag.remove();
7918
+ replaceWithStatements(tag);
7710
7919
  }
7711
7920
  }
7712
7921
  }),
@@ -7852,7 +8061,7 @@ var html_comment_default = {
7852
8061
  if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", tagSection, tagExtra, callRuntime("_text", createScopeReadExpression(nodeBinding), textLiteral));
7853
8062
  }
7854
8063
  if (nodeBinding) markNode(tag, nodeBinding, getWriteReason(nodeBinding));
7855
- tag.remove();
8064
+ replaceWithStatements(tag);
7856
8065
  } },
7857
8066
  parseOptions: { text: true },
7858
8067
  types: runtime_info_default.name + "/tags/html-comment.d.marko",
@@ -7929,11 +8138,11 @@ var id_default = {
7929
8138
  const { node } = tag;
7930
8139
  const [valueAttr] = node.attributes;
7931
8140
  if ((valueAttr ? valueAttr.value : node).extra?.dropped) {
7932
- tag.remove();
8141
+ replaceWithStatements(tag);
7933
8142
  return;
7934
8143
  }
7935
8144
  const id = isOutputHTML() ? callRuntime("_id") : callRuntime("_id", scopeIdentifier);
7936
- if (isOutputHTML()) tag.replaceWith(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(node.var, valueAttr ? _marko_compiler.types.logicalExpression("||", valueAttr.value, id) : id)]));
8145
+ if (isOutputHTML()) replaceWithStatements(tag, [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(node.var, valueAttr ? _marko_compiler.types.logicalExpression("||", valueAttr.value, id) : id)])]);
7937
8146
  else {
7938
8147
  const section = getSection(tag);
7939
8148
  const signal = initValue(node.var.extra.binding);
@@ -7941,7 +8150,7 @@ var id_default = {
7941
8150
  const { value } = valueAttr;
7942
8151
  addValue(section, value.extra, signal, _marko_compiler.types.logicalExpression("||", value, evaluate(value).confident ? id : callRuntime("_id", scopeIdentifier, _marko_compiler.types.stringLiteral(getPrefixedScopeAccessor(node.var.extra.binding, getAccessorPrefix().IdFallback)))));
7943
8152
  } else addValue(section, void 0, signal, id);
7944
- tag.remove();
8153
+ replaceWithStatements(tag);
7945
8154
  }
7946
8155
  } },
7947
8156
  parseOptions: { openTagOnly: true },
@@ -8010,7 +8219,7 @@ function excludeAssignedChangeHandlers() {
8010
8219
  const excluded = /* @__PURE__ */ new Set();
8011
8220
  for (const { assignment: binding } of getAssignments()) if (binding.assignments && binding.aliasOf && binding.property !== void 0 && !excluded.has(binding)) {
8012
8221
  excluded.add(binding);
8013
- for (const alias of binding.aliasOf.aliases) if (propsUtil.has(alias.excludeProperties, binding.property)) alias.excludeProperties = propsUtil.add(alias.excludeProperties, binding.property + "Change");
8222
+ for (const alias of binding.aliasOf.aliases) if (propertiesUtil.has(alias.excludeProperties, binding.property)) alias.excludeProperties = propertiesUtil.add(alias.excludeProperties, binding.property + "Change");
8014
8223
  }
8015
8224
  }
8016
8225
  function resolveReads(intersectionsBySection) {
@@ -8079,14 +8288,14 @@ function resolveBindings() {
8079
8288
  }
8080
8289
  }
8081
8290
  const canonicalBinding = getCanonicalBinding(binding);
8082
- section.bindings = bindingUtil.add(section.bindings, canonicalBinding);
8291
+ if (canonicalBinding === binding) section.bindings = bindingUtil.add(section.bindings, binding);
8083
8292
  bindingNamesBySection.get(section)?.add(canonicalBinding.name);
8084
8293
  if (binding.localOf) section.localClosures = bindingUtil.add(section.localClosures, binding);
8085
8294
  }
8086
8295
  }
8087
8296
  function addSectionReasons(section) {
8088
- if (section.readsOwner) forEach(section.callSections, (callSection) => {
8089
- setReadsOwner(callSection, section.parent);
8297
+ if (section.readsOwner) forEach(section.renderedBy, (call) => {
8298
+ setReadsOwner(call.childScopeBinding.section, section.parent);
8090
8299
  });
8091
8300
  if (section.isHoistThrough) addReason(ensureSectionSlot(section, 6), ALWAYS);
8092
8301
  forEach(section.referencedClosures, (closure) => {
@@ -8094,11 +8303,11 @@ function addSectionReasons(section) {
8094
8303
  addOwnerReason(section, closure.section, closure.sources);
8095
8304
  });
8096
8305
  if (isOptionalBranch(section)) {
8097
- const closureSources = getSourcesForRef(getDirectClosures(section));
8306
+ const closureSources = getSourcesForReferencedBindings(getDirectClosures(section));
8098
8307
  const branchSlot = ensureSectionSlot(section, 9);
8099
8308
  addReason(branchSlot, section.isHoistThrough || section.hoisted ? mergeSources(ALWAYS, closureSources) : closureSources);
8100
8309
  addReasonExprs(branchSlot, section.branchExpr);
8101
- addReasonExprs(ensureSlot(section.branch.nodeBinding), section.branchExpr);
8310
+ addReasonExprs(ensureSlot(section.branch.tag.nodeBinding), section.branchExpr);
8102
8311
  }
8103
8312
  }
8104
8313
  function allocateIds(intersectionsBySection) {
@@ -8276,7 +8485,7 @@ function readsValuesOnResume(expr) {
8276
8485
  return !!expr.isEffect && !expr.retained;
8277
8486
  }
8278
8487
  function isEmitted(exprExtra) {
8279
- return !getCanonicalExtra(exprExtra).dropped;
8488
+ return !getCanonicalExpr(exprExtra).dropped;
8280
8489
  }
8281
8490
  function inEmittedExpr({ exprRoot, section }) {
8282
8491
  return !section.dropped && isEmitted(exprRoot);
@@ -8285,7 +8494,7 @@ function isDroppableValue(expr) {
8285
8494
  return (!!expr.pure || !!expr.callSiteExprs) && !expr.merged && !expr.dropped;
8286
8495
  }
8287
8496
  function dropUnreadValue(expr) {
8288
- if (isDroppableValue(expr) && every(expr.derives, isPrunedBinding)) dropExtra(expr);
8497
+ if (isDroppableValue(expr) && every(expr.derives, isPrunedBinding)) dropExpr(expr);
8289
8498
  }
8290
8499
  function isPrunedBinding(binding) {
8291
8500
  return !!binding.pruned;
@@ -8343,7 +8552,7 @@ function getNearestReadBy(binding, expr) {
8343
8552
  for (let cur = binding; cur; cur = cur.aliasOf) if (cur.reads.has(expr)) return cur;
8344
8553
  }
8345
8554
  function markLazyRead(binding) {
8346
- binding.hasLazyReads = true;
8555
+ getCanonicalBinding(binding).hasLazyReads = true;
8347
8556
  }
8348
8557
  function addBindingGetter(binding, { invoked, hoisted }) {
8349
8558
  if (!invoked || !binding.getters.has(hoisted)) {
@@ -8352,11 +8561,7 @@ function addBindingGetter(binding, { invoked, hoisted }) {
8352
8561
  }
8353
8562
  }
8354
8563
  function isLazyRead(expr, read, binding, isChangeHandlerRead) {
8355
- return !!(expr.invokeOnly && read.deferred && !isChangeHandlerRead && (!binding.aliasOf || isParamBinding(binding)) && binding.type !== 5);
8356
- }
8357
- function isParamBinding(binding) {
8358
- const root = getAliasRoot(binding);
8359
- return root === root.section.params;
8564
+ return !!(expr.invokeOnly && read.deferred && !isChangeHandlerRead && binding.type !== 5);
8360
8565
  }
8361
8566
  function resolveReferencedBindings(expr, reads, intersectionsBySection) {
8362
8567
  let referencedBindings;
@@ -8417,10 +8622,13 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
8417
8622
  };
8418
8623
  }
8419
8624
  function getCanonicalIntersection(intersectionsBySection, section, intersection) {
8420
- const intersections = intersectionsBySection.get(section) || [];
8421
- const canonical = findSorted(compareIntersections, intersections, intersection);
8422
- if (canonical) return canonical;
8423
- intersectionsBySection.set(section, addSorted(compareIntersections, intersections, intersection));
8625
+ const intersections = intersectionsBySection.get(section);
8626
+ if (!intersections) intersectionsBySection.set(section, [intersection]);
8627
+ else {
8628
+ const index = searchSorted(compareIntersections, intersections, intersection);
8629
+ if (index >= 0) return intersections[index];
8630
+ intersections.splice(~index, 0, intersection);
8631
+ }
8424
8632
  return intersection;
8425
8633
  }
8426
8634
  function resolveConstantReference(binding) {
@@ -8484,7 +8692,7 @@ var let_default = {
8484
8692
  translate: { exit(tag) {
8485
8693
  const { node } = tag;
8486
8694
  if (node.extra?.dropped) {
8487
- tag.remove();
8695
+ replaceWithStatements(tag);
8488
8696
  return;
8489
8697
  }
8490
8698
  const tagVar = node.var;
@@ -8497,7 +8705,7 @@ var let_default = {
8497
8705
  const tagExtra = tag.node.extra;
8498
8706
  if (unused) {
8499
8707
  for (const attr of [valueAttr, valueChangeAttr]) if (attr && !evaluate(attr.value).pure) addValue(section, tagExtra, initValue(binding), attr.value);
8500
- tag.remove();
8708
+ replaceWithStatements(tag);
8501
8709
  return;
8502
8710
  }
8503
8711
  const signal = initValue(binding, true);
@@ -8509,7 +8717,7 @@ var let_default = {
8509
8717
  } else {
8510
8718
  translateVar(tag, valueAttr.value, "let");
8511
8719
  if (unused) {
8512
- if (valueChangeAttr && !evaluate(valueChangeAttr.value).pure) tag.insertBefore(_marko_compiler.types.expressionStatement(valueChangeAttr.value));
8720
+ if (valueChangeAttr && !evaluate(valueChangeAttr.value).pure) replaceWithStatements(tag, [_marko_compiler.types.expressionStatement(valueChangeAttr.value)]);
8513
8721
  } else if (valueChangeAttr) {
8514
8722
  const accessor = writeSlot(findSlot(binding, 1), _marko_compiler.types.logicalExpression("||", valueChangeAttr.value, _marko_compiler.types.buildUndefinedNode()));
8515
8723
  if (accessor && !isOptimize()) {
@@ -8518,7 +8726,7 @@ var let_default = {
8518
8726
  }
8519
8727
  }
8520
8728
  }
8521
- tag.remove();
8729
+ replaceWithStatements(tag);
8522
8730
  } },
8523
8731
  parseOptions: { openTagOnly: true },
8524
8732
  attributes: {},
@@ -8561,7 +8769,7 @@ var lifecycle_default = {
8561
8769
  translatedAttrs.statements.push(_marko_compiler.types.expressionStatement(callRuntime("_lifecycle", scopeIdentifier, propsToExpression(translatedAttrs.properties), index > 0 ? _marko_compiler.types.numericLiteral(index) : void 0)));
8562
8770
  addStatement("effect", section, tagExtra, translatedAttrs.statements);
8563
8771
  } else addHTMLEffectCall(section, tagExtra);
8564
- tag.remove();
8772
+ replaceWithStatements(tag);
8565
8773
  } },
8566
8774
  parseOptions: { openTagOnly: true },
8567
8775
  attributes: {},
@@ -8639,7 +8847,7 @@ var return_default = {
8639
8847
  if (attrs.value) {
8640
8848
  const returnId = generateUidIdentifier("return");
8641
8849
  setReturnValueIdentifier(section, returnId);
8642
- tag.replaceWith(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(returnId, attrs.value)]))[0].skip();
8850
+ replaceWithStatements(tag, [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(returnId, attrs.value)])]);
8643
8851
  }
8644
8852
  } },
8645
8853
  dom: { exit(tag) {
@@ -8647,7 +8855,7 @@ var return_default = {
8647
8855
  const attrs = getKnownAttrValues(tag.node);
8648
8856
  if (attrs.value) addStatement("render", section, attrs.value.extra, callRuntime("_return", scopeIdentifier, attrs.value));
8649
8857
  if (attrs.valueChange) addStatement("render", section, attrs.valueChange.extra, callRuntime("_return_change", scopeIdentifier, attrs.valueChange));
8650
- tag.remove();
8858
+ replaceWithStatements(tag);
8651
8859
  } }
8652
8860
  }),
8653
8861
  parseOptions: { openTagOnly: true },
@@ -8706,7 +8914,7 @@ var script_default = {
8706
8914
  const { node } = tag;
8707
8915
  const [valueAttr] = node.attributes;
8708
8916
  if (!valueAttr?.value.extra?.isEffect) {
8709
- tag.remove();
8917
+ replaceWithStatements(tag);
8710
8918
  return;
8711
8919
  }
8712
8920
  const section = getSection(tag);
@@ -8729,7 +8937,7 @@ var script_default = {
8729
8937
  }
8730
8938
  addStatement("effect", section, value.extra, inlineBody || _marko_compiler.types.callExpression(value, []));
8731
8939
  } else addHTMLEffectCall(section, value.extra);
8732
- tag.remove();
8940
+ replaceWithStatements(tag);
8733
8941
  } },
8734
8942
  parseOptions: {
8735
8943
  text: true,
@@ -8774,9 +8982,8 @@ var server_default = createStatementTag("server");
8774
8982
  //#endregion
8775
8983
  //#region src/translator/core/show.ts
8776
8984
  const kStartBinding = Symbol("<show> range start binding");
8777
- const kEndBinding = Symbol("<show> range end binding");
8778
8985
  const kStaticDisplay = Symbol("<show> static display");
8779
- const kSingleNodeBody = Symbol("<show> single node body");
8986
+ const kBodyContent = Symbol("<show> body content");
8780
8987
  const htmlDisplayRefs = /* @__PURE__ */ new WeakMap();
8781
8988
  var show_default = {
8782
8989
  analyze: {
@@ -8785,13 +8992,13 @@ var show_default = {
8785
8992
  const tagExtra = tag.node.extra ??= {};
8786
8993
  const display = tag.node.attributes[0].value;
8787
8994
  const displayEval = evaluate(display);
8788
- tagExtra[kSingleNodeBody] = isSingleNodeBody(tag);
8789
8995
  if (displayEval.confident) tagExtra[kStaticDisplay] = !!displayEval.computed;
8790
8996
  if (tagExtra[kStaticDisplay] === true) return;
8791
8997
  assertLegalHiddenContext(tag);
8792
8998
  const tagSection = ensureSection(tag);
8999
+ const content = tagExtra[kBodyContent] = getContentInfo(tag.get("body"));
8793
9000
  if (getOnlyChildParentTagName(tag)) controlFlowNode(tag, tagSection);
8794
- else {
9001
+ else if (!isSingleNodeContent(content)) {
8795
9002
  tagExtra[kStartBinding] = createBinding("#text", 0, tagSection);
8796
9003
  marker(tag, tagExtra[kStartBinding]);
8797
9004
  enterShallow(tag);
@@ -8803,14 +9010,7 @@ var show_default = {
8803
9010
  const tagExtra = tag.node.extra;
8804
9011
  if (tagExtra[kStaticDisplay] === true) return;
8805
9012
  const tagSection = getSection(tag);
8806
- if (tagExtra[kStartBinding]) {
8807
- if (!tagExtra[kSingleNodeBody]) {
8808
- tagExtra[kEndBinding] = createBinding("#text", 0, tagSection);
8809
- marker(tag, tagExtra[kEndBinding]);
8810
- enterShallow(tag);
8811
- }
8812
- controlFlowNode(tag, tagSection);
8813
- }
9013
+ if (!getOnlyChildParentTagName(tag)) controlFlowNode(tag, tagSection);
8814
9014
  const nodeBinding = tagExtra.nodeBinding;
8815
9015
  if (tagExtra[kStaticDisplay] === void 0) {
8816
9016
  addReasonExprs(ensureSlot(nodeBinding), tagExtra);
@@ -8839,41 +9039,39 @@ var show_default = {
8839
9039
  flushInto(tag);
8840
9040
  const bodyStatements = tag.node.body.body;
8841
9041
  if (staticDisplay !== void 0) {
8842
- for (const replacement of tag.replaceWithMultiple(bodyStatements)) replacement.skip();
9042
+ replaceWithStatements(tag, bodyStatements);
8843
9043
  return;
8844
9044
  }
8845
9045
  const tagSection = getSection(tag);
8846
9046
  const display = htmlDisplayRefs.get(tag.node) || tag.node.attributes[0].value;
8847
9047
  const nodeBinding = tagExtra.nodeBinding;
8848
9048
  const onlyChildParentTagName = getOnlyChildParentTagName(tag);
8849
- const singleNode = tagExtra[kSingleNodeBody];
9049
+ const singleNode = isSingleNodeContent(tagExtra[kBodyContent]);
8850
9050
  const endArgs = buildBranchEndArgs(tagSection, nodeBinding, onlyChildParentTagName, singleNode);
8851
9051
  const showStart = singleNode ? callRuntime("_show_start", _marko_compiler.types.cloneNode(display, true), _marko_compiler.types.numericLiteral(0)) : callRuntime("_show_start", _marko_compiler.types.cloneNode(display, true), ...buildBranchEndArgs(tagSection, nodeBinding, onlyChildParentTagName, singleNode));
8852
- const statements = [
9052
+ replaceWithStatements(tag, [
8853
9053
  _marko_compiler.types.expressionStatement(showStart),
8854
9054
  ...bodyStatements,
8855
9055
  _marko_compiler.types.expressionStatement(callRuntime("_show_end", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), display, ...endArgs))
8856
- ];
8857
- for (const replacement of tag.replaceWithMultiple(statements)) replacement.skip();
9056
+ ]);
8858
9057
  }
8859
9058
  },
8860
9059
  dom: { exit(tag) {
8861
9060
  const tagExtra = tag.node.extra;
8862
9061
  if (tagExtra[kStaticDisplay] === true) {
8863
- tag.remove();
9062
+ replaceWithStatements(tag);
8864
9063
  return;
8865
9064
  }
8866
9065
  const tagSection = getSection(tag);
8867
- const endBinding = tagExtra[kEndBinding];
8868
9066
  const nodeBinding = tagExtra.nodeBinding;
8869
9067
  const startBinding = tagExtra[kStartBinding];
8870
9068
  const display = tagExtra[kStaticDisplay] === false ? _marko_compiler.types.booleanLiteral(false) : tag.node.attributes[0].value;
8871
9069
  const signal = getSignal(tagSection, nodeBinding, "show");
8872
9070
  signal.build = () => {
8873
- return callRuntime("_show", getScopeAccessorLiteral(nodeBinding, true), startBinding ? getScopeAccessorLiteral(startBinding, true) : void 0, endBinding ? getScopeAccessorLiteral(endBinding, true) : void 0);
9071
+ return callRuntime("_show", getScopeAccessorLiteral(nodeBinding, true), startBinding && getScopeAccessorLiteral(startBinding, true));
8874
9072
  };
8875
9073
  addValue(tagSection, tagExtra, signal, display);
8876
- tag.remove();
9074
+ replaceWithStatements(tag);
8877
9075
  } }
8878
9076
  }),
8879
9077
  parseOptions: { controlFlow: true },
@@ -8884,15 +9082,6 @@ var show_default = {
8884
9082
  }],
8885
9083
  types: runtime_info_default.name + "/tags/show.d.marko"
8886
9084
  };
8887
- function isSingleNodeBody(tag) {
8888
- let elements = 0;
8889
- for (const child of tag.get("body").get("body")) {
8890
- if (child.isMarkoComment()) continue;
8891
- if (child.isMarkoTag() && analyzeTagNameType(child) === 0 && _marko_compiler.types.isStringLiteral(child.node.name)) elements++;
8892
- else return false;
8893
- }
8894
- return elements === 1;
8895
- }
8896
9085
  function assertValidShow(tag) {
8897
9086
  (0, _marko_compiler_babel_utils.assertNoVar)(tag);
8898
9087
  (0, _marko_compiler_babel_utils.assertNoArgs)(tag, "Write the condition as a value attribute instead: `<show=condition>`.");
@@ -9025,15 +9214,15 @@ var style_default = {
9025
9214
  (0, _marko_compiler_babel_utils.assertNoArgs)(tag);
9026
9215
  (0, _marko_compiler_babel_utils.assertNoParams)(tag);
9027
9216
  (0, _marko_compiler_babel_utils.assertNoAttributeTags)(tag);
9028
- const { node: node$3 } = tag;
9217
+ const { node: node$2 } = tag;
9029
9218
  assertNoStyleAttributes(tag);
9030
9219
  const names = createCustomPropertyNames(tag);
9031
9220
  if (names) {
9032
9221
  checkStyleInterpolations(tag);
9033
9222
  checkDynamicStylePlacement(tag);
9034
9223
  }
9035
- const importPath = createStyleDependency((0, _marko_compiler_babel_utils.getFile)(), node$3, names);
9036
- (node$3.extra ??= {})[kStyleImportPath] = importPath;
9224
+ const importPath = createStyleDependency((0, _marko_compiler_babel_utils.getFile)(), node$2, names);
9225
+ (node$2.extra ??= {})[kStyleImportPath] = importPath;
9037
9226
  if (importPath) addAssetImport(importPath);
9038
9227
  if (names) {
9039
9228
  analyzeDynamicStyle(tag, names);
@@ -9105,7 +9294,7 @@ function translateHTML$1(tag) {
9105
9294
  markNode(tag, binding, getWriteReason(binding));
9106
9295
  }
9107
9296
  emitStyleImport(tag);
9108
- tag.remove();
9297
+ replaceWithStatements(tag);
9109
9298
  }
9110
9299
  function translateDOM$1(tag) {
9111
9300
  const { node } = tag;
@@ -9120,7 +9309,7 @@ function translateDOM$1(tag) {
9120
9309
  });
9121
9310
  }
9122
9311
  emitStyleImport(tag);
9123
- tag.remove();
9312
+ replaceWithStatements(tag);
9124
9313
  }
9125
9314
  function dynamicStyleValues(node) {
9126
9315
  const values = [];
@@ -9223,9 +9412,10 @@ var try_default = {
9223
9412
  const nodeBinding = tagExtra.nodeBinding = createBinding("#text", 0, section);
9224
9413
  assertHasBody(tag);
9225
9414
  if (!attrTags) throw tag.get("name").buildCodeFrameError("The [`<try>` tag](https://markojs.com/docs/reference/core-tag#try) needs a `<@catch>` to handle errors or a `<@placeholder>` to show while its content is pending. Without either it has no effect, so render its content directly.");
9415
+ tagExtra.textBefore = mayMergeWithText(tag, true);
9226
9416
  initBranchSection(ensureBodySection(tag.get("body")), tagExtra, {
9227
- nodeBinding,
9228
- optional: false
9417
+ kind: "try",
9418
+ tag: tagExtra
9229
9419
  });
9230
9420
  marker(tag, nodeBinding);
9231
9421
  enterShallow(tag);
@@ -9247,10 +9437,10 @@ var try_default = {
9247
9437
  buildContent(tagBody),
9248
9438
  placeholderSection && buildContent(placeholderTag.get("body")),
9249
9439
  catchTag && (catchSection ? buildContent(catchTag.get("body")) : _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([]))),
9250
- placeholderSection && _marko_compiler.types.stringLiteral(getResumeRegisterId(placeholderSection, "content")),
9251
- catchTag && _marko_compiler.types.stringLiteral(catchSection ? getResumeRegisterId(catchSection, "content") : getResumeRegisterId(section, nodeBinding, "catch"))
9440
+ placeholderSection && _marko_compiler.types.stringLiteral(getResumeRegistryId(placeholderSection, "content")) || absentArg(0),
9441
+ catchTag && _marko_compiler.types.stringLiteral(catchSection ? getResumeRegistryId(catchSection, "content") : getResumeRegistryId(section, nodeBinding, "catch"))
9252
9442
  ];
9253
- tag.replaceWith(_marko_compiler.types.expressionStatement(callRuntime("_try", ...tryArgs)))[0].skip();
9443
+ replaceWithStatements(tag, [_marko_compiler.types.expressionStatement(callRuntime("_try", ...tryArgs))]);
9254
9444
  }
9255
9445
  },
9256
9446
  dom: { exit(tag) {
@@ -9258,7 +9448,7 @@ var try_default = {
9258
9448
  const section = getSection(tag);
9259
9449
  const bodySection = getSectionForBody(tag.get("body"));
9260
9450
  const { catchTag, catchSection, placeholderSection } = getTryParts(tag);
9261
- const emptyCatchId = catchTag && !catchSection && getResumeRegisterId(section, nodeBinding, "catch");
9451
+ const emptyCatchId = catchTag && !catchSection && getResumeRegistryId(section, nodeBinding, "catch");
9262
9452
  const signal = getSignal(section, nodeBinding, "try");
9263
9453
  signal.build = () => {
9264
9454
  importRuntimeFeature("catch");
@@ -9278,7 +9468,7 @@ var try_default = {
9278
9468
  ]));
9279
9469
  };
9280
9470
  addValue(section, void 0, signal);
9281
- tag.remove();
9471
+ replaceWithStatements(tag);
9282
9472
  } }
9283
9473
  }),
9284
9474
  attributes: {},
@@ -9345,7 +9535,7 @@ var cdata_default = { translate: { enter(cdata) {
9345
9535
  //#endregion
9346
9536
  //#region src/translator/visitors/comment.ts
9347
9537
  var comment_default = { translate: { exit(comment) {
9348
- comment.remove();
9538
+ replaceWithStatements(comment);
9349
9539
  } } };
9350
9540
  //#endregion
9351
9541
  //#region src/translator/visitors/declaration.ts
@@ -9359,7 +9549,7 @@ var document_type_default = { translate: { exit(documentType) {
9359
9549
  writeTo$1(documentType)`<!${documentType.node.value}>`;
9360
9550
  if (getMarkoOpts().linkAssets && !isBeforeHtmlOrHead(documentType)) writeTo$1(documentType)`${callRuntime("_flush_head")}`;
9361
9551
  }
9362
- documentType.remove();
9552
+ replaceWithStatements(documentType);
9363
9553
  } } };
9364
9554
  function isBeforeHtmlOrHead(documentType) {
9365
9555
  let next = documentType.getNextSibling();
@@ -9508,33 +9698,15 @@ function trackRegisteredImports(importDecl) {
9508
9698
  }
9509
9699
  }
9510
9700
  //#endregion
9511
- //#region src/translator/util/static-text.ts
9512
- function isStaticText(node) {
9513
- switch (node?.type) {
9514
- case "MarkoText": return true;
9515
- case "MarkoPlaceholder": return node.escape && !!getStaticPlaceholderText(node);
9516
- }
9517
- }
9518
- function followsStaticText(path) {
9519
- let prev = path.getPrevSibling();
9520
- while (prev.node && (getNodeContentType(prev, "endType") === null || prev.isMarkoPlaceholder() && getStaticPlaceholderText(prev.node) === "")) prev = prev.getPrevSibling();
9521
- return isStaticText(prev.node);
9522
- }
9523
- function getStaticPlaceholderText(placeholder) {
9524
- const { confident, computed } = evaluate(placeholder.value);
9525
- if (confident) return placeholder.escape ? _escape(computed) : _unescaped(computed);
9526
- }
9527
- //#endregion
9528
9701
  //#region src/translator/visitors/placeholder.ts
9529
- const kSiblingText = Symbol("placeholder has sibling text");
9702
+ const kTextAfter = Symbol("text may merge after the placeholder");
9530
9703
  var placeholder_default = {
9531
9704
  analyze: {
9532
9705
  enter(placeholder) {
9533
9706
  if (isInTextBody(placeholder)) return;
9534
9707
  const { node } = placeholder;
9535
9708
  const valueExtra = node.value.extra ??= {};
9536
- if (getStaticPlaceholderText(node) === "") return;
9537
- if (!isStaticText(node)) {
9709
+ if (getPlaceholderContentType(node) === 2) {
9538
9710
  const section = ensureSection(placeholder);
9539
9711
  const nodeBinding = (node.extra ??= {}).nodeBinding = createBinding("#text", 0, section);
9540
9712
  analyzeSiblingText(placeholder);
@@ -9544,22 +9716,18 @@ var placeholder_default = {
9544
9716
  },
9545
9717
  exit(placeholder) {
9546
9718
  if (isInTextBody(placeholder)) return;
9547
- const { node: node$2 } = placeholder;
9548
- const staticText = getStaticPlaceholderText(node$2);
9549
- if (staticText === "") return;
9550
- const extra = node$2.extra || {};
9551
- if (staticText !== void 0 && node$2.escape) writeTextTo(placeholder, staticText);
9719
+ const { node } = placeholder;
9720
+ const contentType = getPlaceholderContentType(node);
9721
+ if (contentType === null) return;
9722
+ const extra = node.extra || {};
9723
+ if (contentType === 4) writeTextTo(placeholder, getStaticPlaceholderText(node));
9552
9724
  else {
9553
- const siblingText = extra[kSiblingText];
9554
- const nodeBinding = extra.nodeBinding;
9725
+ const before = extra.textBefore;
9726
+ const after = extra[kTextAfter];
9555
9727
  const { content } = getSection(placeholder);
9556
- if (siblingText === 1 || siblingText === 2 || !node$2.escape && content.singleChild && content.startType === 2) marker(placeholder, nodeBinding);
9557
- else {
9558
- writeTextTo(placeholder, " ");
9559
- node(placeholder, nodeBinding);
9560
- }
9728
+ text(placeholder, extra.nodeBinding, before || after || !node.escape && content.singleChild && content.startType === 2 || (before === false && after === false ? false : void 0));
9561
9729
  }
9562
- if (!isStaticText(node$2) || !followsStaticText(placeholder)) enterShallow(placeholder);
9730
+ if (contentType !== 4 || !followsStaticText(placeholder)) enterShallow(placeholder);
9563
9731
  }
9564
9732
  },
9565
9733
  translate: { exit: translateExit }
@@ -9569,8 +9737,8 @@ function translateExit(placeholder) {
9569
9737
  const { node } = placeholder;
9570
9738
  const { value } = node;
9571
9739
  if (node.extra?.needsTextCoercion) injectTextCoercion(value);
9572
- if (getStaticPlaceholderText(node) === "") {
9573
- placeholder.remove();
9740
+ if (getPlaceholderContentType(node) === null) {
9741
+ replaceWithStatements(placeholder);
9574
9742
  return;
9575
9743
  }
9576
9744
  const { confident, computed } = evaluate(value);
@@ -9584,16 +9752,15 @@ function translateExit(placeholder) {
9584
9752
  if (isHTML) write`${node.escape ? _escape(computed) : _unescaped(computed)}`;
9585
9753
  } else {
9586
9754
  const section = getSection(placeholder);
9587
- const siblingText = extra[kSiblingText];
9588
9755
  const markerReason = nodeBinding && getWriteReason(nodeBinding);
9589
9756
  if (isHTML) {
9590
9757
  if (markerReason) {
9591
9758
  const guard = getWriteGuard(section, markerReason, true);
9592
- write`${callRuntime(node.escape ? "_text_resume" : "_html_resume", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), value, siblingText === 1 ? guard ? _marko_compiler.types.binaryExpression("*", guard, _marko_compiler.types.numericLiteral(2)) : _marko_compiler.types.numericLiteral(2) : guard)}`;
9759
+ write`${callRuntime(node.escape ? "_text_mark" : "_html_mark", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), value, extra.textBefore ?? getSectionTextBefore(section) ?? true ? guard ? _marko_compiler.types.binaryExpression("*", guard, _marko_compiler.types.numericLiteral(2)) : _marko_compiler.types.numericLiteral(2) : guard)}`;
9593
9760
  } else write`${method === "_escape" ? buildEscapedTextExpression(value) : callRuntime(method, value)}`;
9594
9761
  } else addStatement("render", section, value.extra, method === "_text" ? callRuntime("_text", createScopeReadExpression(nodeBinding), value) : callRuntime("_html", scopeIdentifier, value, getScopeAccessorLiteral(nodeBinding)), true);
9595
9762
  }
9596
- placeholder.remove();
9763
+ replaceWithStatements(placeholder);
9597
9764
  }
9598
9765
  function buildEscapedTextExpression(value) {
9599
9766
  switch (value.type) {
@@ -9615,31 +9782,9 @@ function buildEscapedTextExpression(value) {
9615
9782
  }
9616
9783
  }
9617
9784
  function analyzeSiblingText(placeholder) {
9618
- placeholder.node.extra[kSiblingText] = mayMergeWithText(placeholder, true) ? 1 : mayMergeWithText(placeholder, false) ? 2 : 0;
9619
- }
9620
- function mayMergeWithText(placeholder, before) {
9621
- let sibling = getSibling(placeholder, before);
9622
- let parent = placeholder.parentPath;
9623
- for (;;) if (!sibling.node) {
9624
- const inlinedTag = getInlinedBodyTag(parent);
9625
- if (!inlinedTag) return parent.isProgram();
9626
- sibling = getSibling(inlinedTag, before);
9627
- parent = inlinedTag.parentPath;
9628
- } else {
9629
- const contentType = getNodeContentType(sibling, before ? "endType" : "startType");
9630
- if (contentType !== null) return contentType === 4 || contentType === 1 || contentType === 2;
9631
- sibling = getSibling(sibling, before);
9632
- }
9633
- }
9634
- function getSibling(path, before) {
9635
- return before ? path.getPrevSibling() : path.getNextSibling();
9636
- }
9637
- function getInlinedBodyTag(parent) {
9638
- if (parent.isMarkoTagBody()) {
9639
- const tag = parent.parentPath;
9640
- const facts = getTagFacts(tag);
9641
- if (facts.controlFlow && facts.inlineBody) return tag;
9642
- }
9785
+ const extra = placeholder.node.extra;
9786
+ extra.textBefore = mayMergeWithText(placeholder, true);
9787
+ extra[kTextAfter] = mayMergeWithText(placeholder, false);
9643
9788
  }
9644
9789
  //#endregion
9645
9790
  //#region src/translator/util/analyze-errors.ts
@@ -9731,7 +9876,7 @@ const builder = {
9731
9876
  }
9732
9877
  };
9733
9878
  function assertVisited(entryFile, state) {
9734
- if (!state) throw entryFile.path.buildCodeFrameError("Unable to build hydrate code, no files were visited before finalizing the build");
9879
+ if (!state) throw entryFile.path.buildCodeFrameError("Unable to build resume code, no files were visited before finalizing the build");
9735
9880
  }
9736
9881
  function createVisited(entryFile) {
9737
9882
  return /* @__PURE__ */ new Map([[(0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, entryFile.opts.filename), 0]]);
@@ -9816,7 +9961,9 @@ var dynamic_tag_default = {
9816
9961
  analyzeAttributeTags(tag);
9817
9962
  const tagSection = ensureSection(tag);
9818
9963
  const inputNodes = getAllTagReferenceNodes(node);
9964
+ (node.name.extra ??= {}).tagName = node.extra ??= {};
9819
9965
  const tagExtra = mergeReferences(tagSection, node, [node.name, ...inputNodes]);
9966
+ tagExtra.textBefore = mayMergeWithText(tag, true);
9820
9967
  if (inputNodes.length) tagExtra.retained = true;
9821
9968
  const tagBody = tag.get("body");
9822
9969
  const hasVar = !!tag.node.var;
@@ -9841,7 +9988,7 @@ var dynamic_tag_default = {
9841
9988
  trackParamsReferences(tagBody, 2);
9842
9989
  if (usesVar) addAlwaysReason(nodeBinding);
9843
9990
  addReasonExprs(ensureSlot(nodeBinding), tagExtra);
9844
- if (!hasVar && !node.arguments && !node.attributes.length && !node.body.body.length) tagExtra.nameOnly = true;
9991
+ if (!hasVar && !node.arguments && !node.attributes.length && !node.body.body.length && !tagExtra.attrTagLookup) tagExtra.nameOnly = true;
9845
9992
  marker(tag, nodeBinding);
9846
9993
  enterShallow(tag);
9847
9994
  if (bodySection && tagExtra.featureType === "class" && !(0, _marko_compiler_babel_utils.getTagTemplate)(tag)) bodySection.structure = null;
@@ -9849,7 +9996,7 @@ var dynamic_tag_default = {
9849
9996
  translate: {
9850
9997
  enter(tag) {
9851
9998
  if (tag.node.extra?.featureType === "class" && !isOutputHTML() && !(0, _marko_compiler_babel_utils.getTagTemplate)(tag)) {
9852
- tag.remove();
9999
+ replaceWithStatements(tag);
9853
10000
  return;
9854
10001
  }
9855
10002
  removeDroppedContent(tag);
@@ -9870,7 +10017,7 @@ var dynamic_tag_default = {
9870
10017
  if (definedBodySection.readsOwner) addStatement("render", section, void 0, _marko_compiler.types.assignmentExpression("=", toMemberExpression(createScopeReadExpression(childBinding, section), getAccessorProp().Owner), getScopeExpression(section, definedBodySection.parent)));
9871
10018
  if (definedBodySection.hasSetupWork) addStatement("render", section, void 0, _marko_compiler.types.callExpression(getSignal(definedBodySection, void 0).identifier, [createScopeReadExpression(childBinding, section)]));
9872
10019
  });
9873
- tag.remove();
10020
+ replaceWithStatements(tag);
9874
10021
  }
9875
10022
  return;
9876
10023
  }
@@ -9884,7 +10031,7 @@ var dynamic_tag_default = {
9884
10031
  const classFile = classTagTemplate ? (0, _marko_compiler_babel_utils.loadFileForTag)(tag) : void 0;
9885
10032
  const classHydration = classFile?.metadata.marko.classHydration;
9886
10033
  if (!isOutputHTML() && isOptimize() && classTagTemplate && !markerReason && !classHydration) {
9887
- tag.remove();
10034
+ replaceWithStatements(tag);
9888
10035
  return;
9889
10036
  }
9890
10037
  setNeedsCompat(true);
@@ -9925,16 +10072,16 @@ var dynamic_tag_default = {
9925
10072
  writeHTMLResumeStatements(tag);
9926
10073
  const markerGuard = getWriteGuard(tagSection, markerReason, true);
9927
10074
  const debugTagVar = !isOptimize() && node.var && _marko_compiler.types.numericLiteral(1);
9928
- const dynamicTagExpr = hasTagArgs ? callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, _marko_compiler.types.arrayExpression(args), contentProp ? contentProp.value : _marko_compiler.types.numericLiteral(0), _marko_compiler.types.numericLiteral(1), markerGuard, debugTagVar) : callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, args[0], args[1] || (markerGuard ? _marko_compiler.types.numericLiteral(0) : void 0), markerGuard ? _marko_compiler.types.numericLiteral(0) : void 0, markerGuard, debugTagVar);
10075
+ const dynamicTagExpr = hasTagArgs ? callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, _marko_compiler.types.arrayExpression(args), contentProp ? contentProp.value : _marko_compiler.types.numericLiteral(0), _marko_compiler.types.numericLiteral(1), markerGuard || absentArg(1), debugTagVar) : callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, args[0], args[1] || absentArg(0), absentArg(0), markerGuard || absentArg(1), debugTagVar);
9929
10076
  if (node.var && isTagVarResumed(tag)) {
9930
10077
  const dynamicScopeIdentifier = generateUidIdentifier(tag.get("name").toString() + "_scope");
9931
10078
  const mutatesTagVar = isTagVarAssigned(tag);
9932
10079
  statements.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(dynamicScopeIdentifier, callRuntime("_peek_scope_id"))]));
9933
10080
  translateVar(tag, dynamicTagExpr, "let", statements);
9934
- statements.push(_marko_compiler.types.expressionStatement(callRuntime("_var", getScopeIdIdentifier(tagSection), getScopeOffsetAccessorLiteral(nodeBinding), dynamicScopeIdentifier, _marko_compiler.types.stringLiteral(getResumeRegisterId(tagSection, node.var.extra?.binding, "var")), mutatesTagVar ? getScopeAccessorLiteral(nodeBinding) : void 0)));
10081
+ statements.push(_marko_compiler.types.expressionStatement(callRuntime("_var", getScopeIdIdentifier(tagSection), getScopeOffsetAccessorLiteral(nodeBinding), dynamicScopeIdentifier, _marko_compiler.types.stringLiteral(getResumeRegistryId(tagSection, node.var.extra?.binding, "var")), mutatesTagVar ? getScopeAccessorLiteral(nodeBinding) : void 0)));
9935
10082
  } else if (node.var) translateVar(tag, dynamicTagExpr, "let", statements);
9936
10083
  else statements.push(_marko_compiler.types.expressionStatement(dynamicTagExpr));
9937
- for (const replacement of tag.replaceWithMultiple(statements)) replacement.skip();
10084
+ replaceWithStatements(tag, statements);
9938
10085
  } else {
9939
10086
  const section = getSection(tag);
9940
10087
  const bodySection = getSectionForBody(tag.get("body"));
@@ -9963,7 +10110,7 @@ var dynamic_tag_default = {
9963
10110
  if (mayHaveNativeAttr(tag, isControllableAttr)) importRuntimeFeature("controllable");
9964
10111
  }
9965
10112
  addValue(section, tagExtra, signal, tagExpression);
9966
- tag.remove();
10113
+ replaceWithStatements(tag);
9967
10114
  }
9968
10115
  }
9969
10116
  }
@@ -9985,7 +10132,7 @@ function getDynamicTagInputBindings(tagExtra) {
9985
10132
  let inputBindings;
9986
10133
  for (const childExtra of tagExtra.tagNameTemplates || []) {
9987
10134
  if (childExtra.featureType === "class") return;
9988
- const inputBinding = childExtra.paramsTree?.props?.[0]?.binding;
10135
+ const inputBinding = childExtra.paramsTree?.properties?.[0]?.binding;
9989
10136
  if (inputBinding) inputBindings = concat(inputBindings, inputBinding);
9990
10137
  }
9991
10138
  return inputBindings;
@@ -10040,7 +10187,7 @@ var dom_default = { translate: {
10040
10187
  ]);
10041
10188
  else {
10042
10189
  const registerReason = getRendererReason(childSection);
10043
- const registerId = getResumeRegisterId(childSection, "content");
10190
+ const registryId = getResumeRegistryId(childSection, "content");
10044
10191
  const objProps = [];
10045
10192
  forEach(childSection.localClosures, (closure) => {
10046
10193
  const closureSignal = getSignal(childSection, closure);
@@ -10053,17 +10200,17 @@ var dom_default = { translate: {
10053
10200
  }
10054
10201
  });
10055
10202
  const registerWrapper = !!(registerReason && objProps.length);
10056
- let renderer = callRuntime("_content", _marko_compiler.types.stringLiteral(registerId), ...trimEmptyArgs([
10203
+ let renderer = callRuntime("_content", _marko_compiler.types.stringLiteral(registryId), ...trimEmptyArgs([
10057
10204
  writes,
10058
10205
  walks,
10059
10206
  ...markReturn(childSection, setupIdentifier, tagParamsIdentifier),
10060
- childSection.hoisted || childSection.isHoistThrough ? getSectionInstancesAccessorLiteral(childSection) : void 0
10207
+ childSection.hoisted || childSection.isHoistThrough ? getSectionScopesAccessorLiteral(childSection) : void 0
10061
10208
  ]));
10062
10209
  if (!registerReason || registerWrapper) renderer = _marko_compiler.types.addComment(renderer, "leading", "@__PURE__");
10063
10210
  if (objProps.length) renderer = callRuntime("_content_closures", renderer, _marko_compiler.types.objectExpression(objProps));
10064
10211
  program.node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(childSection.name), renderer)]));
10065
10212
  if (registerReason && getDynamicTagContentClosures(childSection)) program.node.body.push(_marko_compiler.types.expressionStatement(callRuntime("_content_resume", _marko_compiler.types.identifier(childSection.name), registerWrapper && _marko_compiler.types.numericLiteral(1))));
10066
- else if (registerWrapper) program.node.body.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registerId, _marko_compiler.types.identifier(childSection.name))));
10213
+ else if (registerWrapper) program.node.body.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registryId, _marko_compiler.types.identifier(childSection.name))));
10067
10214
  }
10068
10215
  }
10069
10216
  }
@@ -10098,7 +10245,7 @@ var html_default = { translate: {
10098
10245
  const sectionDynamicSubscribers = /* @__PURE__ */ new Set();
10099
10246
  forEachSection((section) => {
10100
10247
  forEach(section.bindings, (binding) => {
10101
- for (const [hoistSection, hasReference] of binding.getters) if (hasReference) getHTMLSectionStatements(hoistSection || section).push(_marko_compiler.types.variableDeclaration("const", [hoistSection ? _marko_compiler.types.variableDeclarator(getBindingGetterIdentifier(binding, hoistSection), callRuntime("_hoist", getScopeIdIdentifier(hoistSection), _marko_compiler.types.stringLiteral(getResumeRegisterId(hoistSection, binding, "hoist")))) : _marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(binding.originalName), callRuntime("_el", getScopeIdIdentifier(section), _marko_compiler.types.stringLiteral(getResumeRegisterId(section, binding))))]));
10248
+ for (const [hoistSection, hasReference] of binding.getters) if (hasReference) getHTMLSectionStatements(hoistSection || section).push(_marko_compiler.types.variableDeclaration("const", [hoistSection ? _marko_compiler.types.variableDeclarator(getBindingGetterIdentifier(binding, hoistSection), callRuntime("_hoist", getScopeIdIdentifier(hoistSection), _marko_compiler.types.stringLiteral(getResumeRegistryId(hoistSection, binding, "hoist")))) : _marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(binding.originalName), callRuntime("_el", getScopeIdIdentifier(section), _marko_compiler.types.stringLiteral(getResumeRegistryId(section, binding))))]));
10102
10249
  });
10103
10250
  forEach(section.hoisted, (binding) => {
10104
10251
  const highestHoistSection = first(binding.hoists);
@@ -10121,16 +10268,12 @@ var html_default = { translate: {
10121
10268
  if (program.node.extra.hasGlobalRead) getHTMLSectionStatements(getSection(program)).push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier("$global"), callRuntime("$global"))]));
10122
10269
  writeHTMLResumeStatements(program);
10123
10270
  traverseReplace(program.node, "body", replaceNode);
10124
- const renderContent = [];
10125
- const section = getSection(program);
10126
- renderContent.push(getScopeReasonStatement(section));
10127
- for (const child of program.get("body")) if (!isStatic(child)) {
10128
- renderContent.push(child.node);
10129
- child.remove();
10130
- } else if (child.isMarkoScriptlet()) {
10131
- if (child.node.target && child.node.target !== "server") child.remove();
10132
- else child.replaceWithMultiple(child.node.body);
10133
- }
10271
+ const statics = [];
10272
+ const renderContent = [getScopeReasonStatement(getSection(program))];
10273
+ for (const child of program.get("body")) if (!isStatic(child)) renderContent.push(child.node);
10274
+ else if (child.isMarkoScriptlet()) statics.push(...child.node.body);
10275
+ else statics.push(child.node);
10276
+ program.node.body = statics;
10134
10277
  writeModuleRegistrations(program);
10135
10278
  const contentId = hasSharedUid("content") && ensureSharedUid("content");
10136
10279
  const contentFn = _marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier("input")], _marko_compiler.types.blockStatement(renderContent));
@@ -10173,7 +10316,7 @@ function registerFunctionDeclarations(body) {
10173
10316
  const len = body.length;
10174
10317
  for (let i = 0; i < len; i++) {
10175
10318
  const child = body[i];
10176
- if (child.type === "FunctionDeclaration" && isRegisteredFnExtra(child.extra)) body.push(_marko_compiler.types.expressionStatement(callRuntime("_resume", _marko_compiler.types.identifier(child.id.name), _marko_compiler.types.stringLiteral(child.extra.registerId))));
10319
+ if (child.type === "FunctionDeclaration" && isRegisteredFnExtra(child.extra)) body.push(_marko_compiler.types.expressionStatement(callRuntime("_resume", _marko_compiler.types.identifier(child.id.name), _marko_compiler.types.stringLiteral(child.extra.registryId))));
10177
10320
  }
10178
10321
  }
10179
10322
  function buildResumeCall(node) {
@@ -10185,9 +10328,9 @@ function buildResumeCall(node) {
10185
10328
  forEach(referencedLocals, (binding) => {
10186
10329
  localProperties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
10187
10330
  });
10188
- return callRuntime("_resume_locals", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registerId), _marko_compiler.types.objectExpression(localProperties), (getReferencedBindingsInFunction(extra) || extra.referencesScope) && getScopeIdIdentifier(extra.section));
10331
+ return callRuntime("_resume_locals", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), _marko_compiler.types.objectExpression(localProperties), extra.referencesScope && getScopeIdIdentifier(extra.section));
10189
10332
  }
10190
- return callRuntime("_resume", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registerId), (getReferencedBindingsInFunction(extra) || extra.referencesScope) && getScopeIdIdentifier(extra.section));
10333
+ return callRuntime("_resume", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), extra.referencesScope && getScopeIdIdentifier(extra.section));
10191
10334
  }
10192
10335
  }
10193
10336
  //#endregion
@@ -10234,7 +10377,8 @@ var program_default = {
10234
10377
  if (paramsBinding && !paramsBinding.pruned) programExtra.paramsTree = exposeParamsTree(paramsBinding);
10235
10378
  const section = programExtra.section;
10236
10379
  forEachSection((childSection) => {
10237
- programExtra.hasResumes ||= !!(isUnconditionalReason(mapBodyParams(childSection, childSection.reason)) || childSection !== section && !isSectionRendererElided(childSection) && getRendererReason(childSection));
10380
+ const reason = mapBodyParams(childSection, childSection.reason);
10381
+ programExtra.hasResumes ||= !!(reason && !isGuardedReason(reason) || childSection !== section && !isSectionRendererElided(childSection) && getRendererReason(childSection));
10238
10382
  });
10239
10383
  finalizeSetupWork();
10240
10384
  }
@@ -10293,6 +10437,7 @@ var program_default = {
10293
10437
  else dom_default.translate.enter(program);
10294
10438
  },
10295
10439
  exit(program) {
10440
+ writeBodyStatements(program.node);
10296
10441
  if (isOutputHTML()) html_default.translate.exit(program);
10297
10442
  else dom_default.translate.exit(program);
10298
10443
  if (needsCompat()) {
@@ -10322,36 +10467,27 @@ var referenced_identifier_default = {
10322
10467
  analyze(identifier) {
10323
10468
  const { name } = identifier.node;
10324
10469
  if (identifier.scope.hasBinding(name)) return;
10325
- if (name === "$global") {
10470
+ if (name === "$global" || name === "$signal") {
10326
10471
  assertReferencedInRender(identifier, name);
10327
10472
  setReferencesScope(identifier);
10328
- trackGlobalReference(identifier);
10329
- } else if (name === "$signal") {
10330
- assertReferencedInRender(identifier, name);
10331
10473
  const section = ensureSection(identifier);
10332
- section.hasAbortSignal = true;
10333
- setReferencesScope(identifier);
10334
10474
  const rootExtra = getExprRoot(identifier).node.extra ??= { section };
10335
10475
  (identifier.node.extra ??= {}).exprRoot = rootExtra;
10336
- if (rootExtra[kAbortId] === void 0) rootExtra[kAbortId] = section.abortSignalExprs++;
10476
+ if (name === "$global") trackGlobalReference(identifier);
10477
+ else {
10478
+ section.hasAbortSignal = true;
10479
+ if (rootExtra[kAbortId] === void 0) rootExtra[kAbortId] = section.abortSignalExprs++;
10480
+ }
10337
10481
  }
10338
10482
  },
10339
10483
  translate(identifier) {
10340
10484
  const { name } = identifier.node;
10341
10485
  if (identifier.scope.hasBinding(name)) return;
10342
10486
  switch (name) {
10343
- case "$global": {
10344
- if (isOutputHTML()) break;
10345
- const globalRead = _marko_compiler.types.memberExpression(scopeIdentifier, _marko_compiler.types.identifier(getAccessorProp().Global));
10346
- const key = !isOptimize() && getSignalGlobalKey(identifier);
10347
- if (key) identifier.parentPath.replaceWith(callRuntime("_global_read", globalRead, _marko_compiler.types.stringLiteral(key)));
10348
- else replaceWithExtra(identifier, globalRead);
10349
- break;
10350
- }
10351
10487
  case "$signal": if (isOutputHTML()) replaceWithExtra(identifier, callRuntime("_signal_read_error"));
10352
10488
  else {
10353
10489
  const exprRoot = identifier.node.extra.exprRoot;
10354
- const canonicalExtra = getCanonicalExtra(exprRoot);
10490
+ const canonicalExtra = getCanonicalExpr(exprRoot);
10355
10491
  if (canonicalExtra.dropped) break;
10356
10492
  const section = getSection(identifier);
10357
10493
  const exprId = exprRoot[kAbortId];
@@ -10369,13 +10505,6 @@ function replaceWithExtra(path, replacement) {
10369
10505
  replacement.extra = path.node.extra;
10370
10506
  path.replaceWith(replacement);
10371
10507
  }
10372
- function getSignalGlobalKey(identifier) {
10373
- const { parent } = identifier;
10374
- if (!_marko_compiler.types.isMemberExpression(parent) || parent.computed || !_marko_compiler.types.isIdentifier(parent.property) || parent.object !== identifier.node) return;
10375
- const { name } = parent.property;
10376
- if (name === "runtimeId" || name === "renderId") return;
10377
- return getReferencedBindings(getExprRoot(identifier).node.extra) ? name : void 0;
10378
- }
10379
10508
  //#endregion
10380
10509
  //#region src/translator/visitors/scriptlet.ts
10381
10510
  var scriptlet_default = {
@@ -10393,19 +10522,9 @@ var scriptlet_default = {
10393
10522
  const isHTML = isOutputHTML();
10394
10523
  if (node.target && node.target !== (isHTML ? "server" : "client")) {
10395
10524
  const ids = Object.keys(scriptlet.getOuterBindingIdentifiers());
10396
- const decl = ids.length && _marko_compiler.types.variableDeclaration("var", ids.map((key) => _marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(key))));
10397
- if (decl) {
10398
- if (isHTML) {
10399
- scriptlet.node.target = null;
10400
- scriptlet.node.body = [decl];
10401
- } else scriptlet.replaceWith(decl);
10402
- } else scriptlet.remove();
10403
- return;
10404
- }
10405
- if (isHTML) {} else {
10406
- traverseReplace(node, "body", replaceRegisteredFunctionNode$1);
10407
- scriptlet.replaceWithMultiple(node.body);
10408
- }
10525
+ node.body = ids.length ? [_marko_compiler.types.variableDeclaration("var", ids.map((key) => _marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(key))))] : [];
10526
+ } else if (!isHTML) traverseReplace(node, "body", replaceRegisteredFunctionNode$1);
10527
+ if (!isHTML) replaceWithStatements(scriptlet, node.body);
10409
10528
  } }
10410
10529
  };
10411
10530
  //#endregion
@@ -10457,7 +10576,7 @@ var custom_tag_default = {
10457
10576
  if (tag.node.var) throw tag.get("var").buildCodeFrameError(`The \`${getTagNameHint(tag.node)}\` tag is lazily loaded, so it does not support a [tag variable](https://markojs.com/docs/reference/language#tag-variables). Remove the variable, or import the tag without \`load\`.`);
10458
10577
  tagExtra.nodeBinding = createBinding("#text", 0, ensureSection(tag));
10459
10578
  }
10460
- if (!isTemplateImport(tag)) dropNodes(tag.node.name);
10579
+ if (childSection === programExtra.section || !isTemplateImport(tag)) dropNodes(tag.node.name);
10461
10580
  knownTagAnalyze(tag, childSection, childExtra.paramsTree);
10462
10581
  const tagName = getTagNameHint(tag.node);
10463
10582
  if (tagExtra.tagNameLoad) {
@@ -10484,28 +10603,29 @@ var custom_tag_default = {
10484
10603
  };
10485
10604
  function translateHTML(tag) {
10486
10605
  const { node } = tag;
10606
+ const tagExtra = node.extra;
10487
10607
  let tagIdentifier;
10488
10608
  if (node.name.extra?.dropped) {
10489
10609
  const relativePath = getTagRelativePath(tag);
10490
- const loadConfig = node.extra?.tagNameLoad;
10610
+ const loadConfig = tagExtra.tagNameLoad;
10491
10611
  const importTemplate = () => (0, _marko_compiler_babel_utils.importDefault)((0, _marko_compiler_babel_utils.getFile)(), relativePath, getTagNameHint(node));
10492
10612
  if (loadConfig) {
10493
10613
  const childFile = (0, _marko_compiler_babel_utils.loadFileForTag)(tag);
10494
10614
  tagIdentifier = _marko_compiler.types.identifier(ensureHtmlLoadWrapped(childFile, importTemplate, loadConfig.render ? void 0 : loadConfig.triggers));
10495
- } else tagIdentifier = isCircularRequest((0, _marko_compiler_babel_utils.getFile)(), relativePath) ? _marko_compiler.types.identifier(ensureSharedUid("content")) : importTemplate();
10615
+ } else tagIdentifier = tagExtra.childSection === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section ? _marko_compiler.types.identifier(ensureSharedUid("content")) : importTemplate();
10496
10616
  } else tagIdentifier = node.name;
10497
10617
  knownTagTranslateHTML(tag, tagIdentifier);
10498
10618
  }
10499
10619
  function translateDOM(tag) {
10500
10620
  const { node } = tag;
10621
+ const tagExtra = node.extra;
10501
10622
  const file = (0, _marko_compiler_babel_utils.getFile)();
10502
10623
  const relativePath = getTagRelativePath(tag);
10503
10624
  const programSection = (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
10504
10625
  const childFile = (0, _marko_compiler_babel_utils.loadFileForTag)(tag);
10505
- const childExtra = childFile.ast.program.extra;
10506
- const childExports = childExtra.exportNames;
10507
- const childSection = childExtra.section;
10508
- const loadConfig = node.extra?.tagNameLoad;
10626
+ const childExports = childFile.ast.program.extra.exportNames;
10627
+ const { childSection } = tagExtra;
10628
+ const loadConfig = tagExtra.tagNameLoad;
10509
10629
  const isLoad = !!loadConfig;
10510
10630
  const tagName = getTagNameHint(node);
10511
10631
  if (isLoad) {
@@ -10533,20 +10653,20 @@ function translateDOM(tag) {
10533
10653
  addStatement("render", section, void 0, _marko_compiler.types.callExpression(setupIdent, [
10534
10654
  scopeIdentifier,
10535
10655
  createScopeReadExpression(childBinding, section),
10536
- createScopeReadExpression(node.extra.nodeBinding, section)
10656
+ createScopeReadExpression(tagExtra.nodeBinding, section)
10537
10657
  ]));
10538
10658
  });
10539
10659
  } else if (programSection === childSection) knownTagTranslateDOM(tag, (binding, preferredName) => getSignal(programSection, binding, preferredName).identifier, childSection.hasSetupWork ? (section, childBinding) => {
10540
10660
  addStatement("render", section, void 0, _marko_compiler.types.callExpression(_marko_compiler.types.identifier(childExports.setup), [createScopeReadExpression(childBinding, section)]));
10541
10661
  } : void 0);
10542
10662
  else {
10543
- knownTagTranslateDOM(tag, (binding, preferredName, directContent) => importOrSelfReferenceName((0, _marko_compiler_babel_utils.getFile)(), relativePath, directContent && childExports.directContent.get(binding) || childExports.params.get(binding), preferredName), childSection.hasSetupWork ? (section, childBinding) => {
10544
- addStatement("render", section, void 0, _marko_compiler.types.callExpression(importOrSelfReferenceName(file, relativePath, childExports.setup, tagName), [createScopeReadExpression(childBinding, section)]));
10663
+ knownTagTranslateDOM(tag, (binding, preferredName, directContent) => (0, _marko_compiler_babel_utils.importNamed)(file, relativePath, directContent && childExports.directContent.get(binding) || childExports.params.get(binding), preferredName), childSection.hasSetupWork ? (section, childBinding) => {
10664
+ addStatement("render", section, void 0, _marko_compiler.types.callExpression((0, _marko_compiler_babel_utils.importNamed)(file, relativePath, childExports.setup, tagName), [createScopeReadExpression(childBinding, section)]));
10545
10665
  } : void 0);
10546
10666
  (0, _marko_compiler_babel_utils.importNamed)(file, relativePath, childExports.template, `${tagName}_template`);
10547
10667
  (0, _marko_compiler_babel_utils.importNamed)(file, relativePath, childExports.walks, `${tagName}_walks`);
10548
10668
  }
10549
- tag.remove();
10669
+ replaceWithStatements(tag);
10550
10670
  }
10551
10671
  function createLoadIdentifier(cache, key, name, runtime, request, trigger) {
10552
10672
  const id = generateUidIdentifier(name);
@@ -10817,7 +10937,7 @@ var native_tag_default = {
10817
10937
  write`<${tagName}`;
10818
10938
  if (injectsNonce && !spread) write`${callRuntime("_attr_nonce")}`;
10819
10939
  if (controllable) {
10820
- if (tagName !== "select" && tagName !== "textarea") write`${callRuntime(getControllableHelper(tagName, controllable.state), getScopeIdIdentifier(tagSection), nodeAccessor, ...controllable.attrs.map((index) => attrAt(attributes, index)?.value))}`;
10940
+ if (tagName !== "select" && tagName !== "textarea") write`${callRuntime(getControllableHelper(tagName, controllable.state), getScopeIdIdentifier(tagSection), nodeAccessor, ...controllable.attrs.map((index, i) => attrAt(attributes, index)?.value || i === 1 && absentArg(0)))}`;
10821
10941
  if (controllable.attrs[1] !== void 0) addHTMLEffectCall(tagSection, void 0);
10822
10942
  }
10823
10943
  let writeAtStartOfBody;
@@ -10825,7 +10945,7 @@ var native_tag_default = {
10825
10945
  if (tagName === "select") {
10826
10946
  if (controllable) htmlSelectArgs.set(tag.node, {
10827
10947
  helper: "_attr_select_value",
10828
- args: [attrAt(attributes, controllable.attrs[0])?.value || _marko_compiler.types.buildUndefinedNode(), attrAt(attributes, controllable.attrs[1])?.value || _marko_compiler.types.buildUndefinedNode()]
10948
+ args: [attrAt(attributes, controllable.attrs[0])?.value || _marko_compiler.types.buildUndefinedNode(), attrAt(attributes, controllable.attrs[1])?.value || absentArg(0)]
10829
10949
  });
10830
10950
  else if (spreadExpression) {
10831
10951
  const spreadIdentifier = declareConstBefore(tag, "select_input", spreadExpression);
@@ -10889,10 +11009,11 @@ var native_tag_default = {
10889
11009
  const markerReason = !skipEndTag && nodeBinding && getWriteReason(nodeBinding);
10890
11010
  const write = writeTo$1(tag, tagName === "html" || !markerReason && tagName === "body");
10891
11011
  if (htmlContentAttrTags.has(tag.node)) flushBefore(tag);
11012
+ let statements = [];
10892
11013
  if (selectArgs) {
10893
11014
  if (!skipEndTag) write`</${tagName}>`;
10894
11015
  flushInto(tag);
10895
- tag.insertBefore(_marko_compiler.types.expressionStatement(callRuntime(selectArgs.helper, getScopeIdIdentifier(tagSection), nodeBinding && getScopeAccessorLiteral(nodeBinding), ...selectArgs.args, _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement(tag.node.body.body)))));
11016
+ statements = [_marko_compiler.types.expressionStatement(callRuntime(selectArgs.helper, getScopeIdIdentifier(tagSection), nodeBinding && getScopeAccessorLiteral(nodeBinding), ...selectArgs.args, _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement(tag.node.body.body))))];
10896
11017
  } else if (isTextOnly) {
10897
11018
  const rawTextHelper = getRawTextEscapeHelper(tagName);
10898
11019
  if (rawTextHelper) {
@@ -10900,13 +11021,13 @@ var native_tag_default = {
10900
11021
  write`${_marko_compiler.types.isStringLiteral(body) ? content_exports[rawTextHelper](body.value) : callRuntime(rawTextHelper, body)}`;
10901
11022
  } else for (const child of tag.node.body.body) if (_marko_compiler.types.isMarkoText(child)) write`${child.value}`;
10902
11023
  else if (_marko_compiler.types.isMarkoPlaceholder(child)) write`${callRuntime("_escape", child.value)}`;
10903
- } else tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
11024
+ } else statements = tag.node.body.body;
10904
11025
  if (!skipEndTag && !isOpenOnly && !selectArgs) {
10905
11026
  if (tagName === "head" && getMarkoOpts().linkAssets) write`${callRuntime("_flush_head")}`;
10906
11027
  write`</${tagName}>`;
10907
11028
  }
10908
11029
  if (markerReason) markNode(tag, nodeBinding, markerReason, tagName === "html");
10909
- tag.remove();
11030
+ replaceWithStatements(tag, statements);
10910
11031
  }
10911
11032
  },
10912
11033
  dom: {
@@ -10984,15 +11105,12 @@ var native_tag_default = {
10984
11105
  },
10985
11106
  exit(tag) {
10986
11107
  const nodeBinding = tag.node.extra.nodeBinding;
10987
- const openTagOnly = (0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly;
10988
11108
  const tagName = getCanonicalTagName(tag);
10989
- if (!openTagOnly) {
10990
- if (tagName !== "textarea" && getTagFacts(tag).textBody) {
10991
- const textLiteral = bodyToText(tag.node.body, tagName === "title");
10992
- if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", getSection(tag), textLiteral.extra, callRuntime("_text_content", createScopeReadExpression(nodeBinding), textLiteral), true);
10993
- } else tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
11109
+ if (tagName !== "textarea" && getTagFacts(tag).textBody) {
11110
+ const textLiteral = bodyToText(tag.node.body, tagName === "title");
11111
+ if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", getSection(tag), textLiteral.extra, callRuntime("_text_content", createScopeReadExpression(nodeBinding), textLiteral), true);
10994
11112
  }
10995
- tag.remove();
11113
+ replaceWithStatements(tag);
10996
11114
  }
10997
11115
  }
10998
11116
  })
@@ -11498,6 +11616,7 @@ var tag_default = {
11498
11616
  }
11499
11617
  },
11500
11618
  exit(tag) {
11619
+ writeBodyStatements(tag.node.body);
11501
11620
  const translator = (0, _marko_compiler_babel_utils.getTagDef)(tag)?.translator;
11502
11621
  if (translator) {
11503
11622
  exitHook(translator.hook, tag);
@@ -11529,7 +11648,7 @@ var text_default = {
11529
11648
  translate: { exit(text) {
11530
11649
  if (isInTextBody(text)) return;
11531
11650
  if (isOutputHTML()) writeTo$1(text)`${text.node.value}`;
11532
- text.remove();
11651
+ replaceWithStatements(text);
11533
11652
  } }
11534
11653
  };
11535
11654
  //#endregion
@@ -11537,7 +11656,7 @@ var text_default = {
11537
11656
  function buildAggregateError(file, rootMsg, ...paths) {
11538
11657
  const err = /* @__PURE__ */ new SyntaxError();
11539
11658
  const fileName = path.default.relative(_marko_compiler_modules.cwd, file.opts.filename);
11540
- const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$10]) => `\x1b[90m${msg} at ${getFileNameWithLoc(fileName, path$10)}:\x1b[0m\n${getFrame(file, path$10)}`).join("\n\n")}`;
11659
+ const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$9]) => `\x1b[90m${msg} at ${getFileNameWithLoc(fileName, path$9)}:\x1b[0m\n${getFrame(file, path$9)}`).join("\n\n")}`;
11541
11660
  if (!("MARKO_DEBUG" in process.env)) err.stack = finalMsg;
11542
11661
  Object.defineProperty(err, "message", {
11543
11662
  get() {
@@ -11762,8 +11881,8 @@ function mergeVisit(visit5, visit6) {
11762
11881
  } : { exit } : enter;
11763
11882
  }
11764
11883
  function mergeHook(hook5, hook6) {
11765
- return (hook5 || hook6) && function(path$9, state) {
11766
- return (isTagsAPI() ? hook6 : hook5)?.call(this, path$9, state);
11884
+ return (hook5 || hook6) && function(path$8, state) {
11885
+ return (isTagsAPI() ? hook6 : hook5)?.call(this, path$8, state);
11767
11886
  };
11768
11887
  }
11769
11888
  function mergeTaglibs(libs5, libs6) {