marko 6.0.3 → 6.0.5

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.
@@ -999,48 +999,44 @@ var import_babel_utils8 = require("@marko/compiler/babel-utils");
999
999
  var rest = false ? Symbol("Attribute Tag") : Symbol();
1000
1000
 
1001
1001
  // src/common/helpers.ts
1002
- function classValue(value) {
1003
- return toDelimitedString(value, " ", stringifyClassObject);
1002
+ function classValue(classValue2) {
1003
+ return toDelimitedString(classValue2, " ", stringifyClassObject);
1004
1004
  }
1005
1005
  function stringifyClassObject(name2, value) {
1006
1006
  return value ? name2 : "";
1007
1007
  }
1008
- function styleValue(value) {
1009
- return toDelimitedString(value, ";", stringifyStyleObject);
1008
+ function styleValue(styleValue2) {
1009
+ return toDelimitedString(styleValue2, ";", stringifyStyleObject);
1010
1010
  }
1011
1011
  function stringifyStyleObject(name2, value) {
1012
- return value || value === 0 ? `${name2}:${typeof value === "number" && value && !/^(--|ta|or|li|z)|cou|nk|it|ag|we|do|w$/.test(name2) ? value + "px" : value}` : "";
1012
+ return value || value === 0 ? `${name2}:${value && typeof value === "number" && !/^(--|ta|or|li|z)|cou|nk|it|ag|we|do|w$/.test(name2) ? value + "px" : value}` : "";
1013
1013
  }
1014
1014
  function toDelimitedString(val, delimiter, stringify) {
1015
- switch (typeof val) {
1016
- case "string":
1017
- return val;
1018
- case "object":
1019
- if (val !== null) {
1020
- let result = "";
1021
- let curDelimiter = "";
1022
- if (Array.isArray(val)) {
1023
- for (const v of val) {
1024
- const part = toDelimitedString(v, delimiter, stringify);
1025
- if (part !== "") {
1026
- result += curDelimiter + part;
1027
- curDelimiter = delimiter;
1028
- }
1029
- }
1030
- } else {
1031
- for (const name2 in val) {
1032
- const v = val[name2];
1033
- const part = stringify(name2, v);
1034
- if (part !== "") {
1035
- result += curDelimiter + part;
1036
- curDelimiter = delimiter;
1037
- }
1038
- }
1015
+ let str = "";
1016
+ let sep = "";
1017
+ let part;
1018
+ if (val) {
1019
+ if (typeof val !== "object") {
1020
+ str += val;
1021
+ } else if (Array.isArray(val)) {
1022
+ for (const v of val) {
1023
+ part = toDelimitedString(v, delimiter, stringify);
1024
+ if (part) {
1025
+ str += sep + part;
1026
+ sep = delimiter;
1027
+ }
1028
+ }
1029
+ } else {
1030
+ for (const name2 in val) {
1031
+ part = stringify(name2, val[name2]);
1032
+ if (part) {
1033
+ str += sep + part;
1034
+ sep = delimiter;
1039
1035
  }
1040
- return result;
1041
1036
  }
1037
+ }
1042
1038
  }
1043
- return "";
1039
+ return str;
1044
1040
  }
1045
1041
  function isEventHandler(name2) {
1046
1042
  return /^on[A-Z-]/.test(name2);
@@ -1539,7 +1535,7 @@ function forceSectionSerialize(section, prop) {
1539
1535
  forceSerializeKey(section, getSectionPropSerializeReasonKey(section, prop));
1540
1536
  } else if (section.serializeReason !== true) {
1541
1537
  reasonExprs.delete(section);
1542
- section.serializeReason = true;
1538
+ setSectionSerializeReason(section, true);
1543
1539
  }
1544
1540
  }
1545
1541
  function forceBindingSerialize(section, binding, prefix2) {
@@ -1547,7 +1543,7 @@ function forceBindingSerialize(section, binding, prefix2) {
1547
1543
  }
1548
1544
  function forceSerializeKey(section, key) {
1549
1545
  if (section.serializeReasons.get(key) !== true) {
1550
- section.serializeReasons.set(key, true);
1546
+ setSectionKeyedSerializeReason(section, key, true);
1551
1547
  keyedReasonExprs.get(section)?.delete(key);
1552
1548
  }
1553
1549
  }
@@ -1616,9 +1612,9 @@ function addSectionSerializeReasonRef(section, ref, prop) {
1616
1612
  if (reason === true) {
1617
1613
  forceSectionSerialize(section);
1618
1614
  } else {
1619
- section.serializeReason = mergeSerializeReasons(
1620
- existingReason,
1621
- reason
1615
+ setSectionSerializeReason(
1616
+ section,
1617
+ mergeSerializeReasons(existingReason, reason)
1622
1618
  );
1623
1619
  }
1624
1620
  }
@@ -1636,7 +1632,8 @@ function addKeyedSerializeReasonRef(section, key, ref) {
1636
1632
  if (reason === true) {
1637
1633
  forceSerializeKey(section, key);
1638
1634
  } else {
1639
- section.serializeReasons.set(
1635
+ setSectionKeyedSerializeReason(
1636
+ section,
1640
1637
  key,
1641
1638
  mergeSerializeReasons(existingReason, reason)
1642
1639
  );
@@ -1658,9 +1655,9 @@ function addSectionSerializeReason(section, reason, prop) {
1658
1655
  if (reason === true) {
1659
1656
  forceSectionSerialize(section);
1660
1657
  } else {
1661
- section.serializeReason = mergeSerializeReasons(
1662
- existingReason,
1663
- reason
1658
+ setSectionSerializeReason(
1659
+ section,
1660
+ mergeSerializeReasons(existingReason, reason)
1664
1661
  );
1665
1662
  }
1666
1663
  }
@@ -1682,7 +1679,8 @@ function addKeyedSerializeReason(section, key, reason) {
1682
1679
  if (reason === true) {
1683
1680
  forceSerializeKey(section, key);
1684
1681
  } else {
1685
- section.serializeReasons.set(
1682
+ setSectionKeyedSerializeReason(
1683
+ section,
1686
1684
  key,
1687
1685
  mergeSerializeReasons(existingReason, reason)
1688
1686
  );
@@ -1730,19 +1728,23 @@ function applySerializeReasonExprs(section) {
1730
1728
  if (keyedExprs) {
1731
1729
  keyedReasonExprs.delete(section);
1732
1730
  for (const [key, exprs] of keyedExprs) {
1733
- const reason = getSerializeSourcesForExprs(exprs);
1734
- if (reason) {
1735
- section.serializeReasons.set(
1731
+ const reason2 = getSerializeSourcesForExprs(exprs);
1732
+ if (reason2) {
1733
+ setSectionKeyedSerializeReason(
1734
+ section,
1736
1735
  key,
1737
- mergeSerializeReasons(section.serializeReasons.get(key), reason)
1736
+ mergeSerializeReasons(section.serializeReasons.get(key), reason2)
1738
1737
  );
1739
1738
  }
1740
1739
  }
1741
1740
  }
1742
- section.serializeReason = mergeSerializeReasons(
1743
- section.serializeReason,
1744
- getSerializeSourcesForExprs(reasonExprs.get(section))
1745
- );
1741
+ const reason = getSerializeSourcesForExprs(reasonExprs.get(section));
1742
+ if (reason) {
1743
+ setSectionSerializeReason(
1744
+ section,
1745
+ mergeSerializeReasons(section.serializeReason, reason)
1746
+ );
1747
+ }
1746
1748
  reasonExprs.delete(section);
1747
1749
  }
1748
1750
  function finalizeSectionSerializeReasons(section) {
@@ -1755,7 +1757,7 @@ function finalizeSectionSerializeReasons(section) {
1755
1757
  }
1756
1758
  reason = mergeSerializeReasons(reason, keyedReason);
1757
1759
  }
1758
- section.serializeReason = reason;
1760
+ setSectionSerializeReason(section, reason);
1759
1761
  }
1760
1762
  }
1761
1763
  function getSerializeSourcesForExpr(expr) {
@@ -1799,6 +1801,12 @@ function mergeSerializeReasons(a, b) {
1799
1801
  if (a === true || b === true) return true;
1800
1802
  return bindingUtil.union(a, b);
1801
1803
  }
1804
+ function setSectionSerializeReason(section, reason) {
1805
+ section.serializeReason = reason;
1806
+ }
1807
+ function setSectionKeyedSerializeReason(section, key, reason) {
1808
+ section.serializeReasons.set(key, reason);
1809
+ }
1802
1810
 
1803
1811
  // src/translator/util/state.ts
1804
1812
  var import_babel_utils9 = require("@marko/compiler/babel-utils");
@@ -2360,7 +2368,7 @@ function getExprIfSerialized(reason, expr) {
2360
2368
  ) : void 0;
2361
2369
  }
2362
2370
  function getSerializeGuard(reason) {
2363
- return reason ? reason === true ? import_compiler13.types.numericLiteral(1) : callRuntime(
2371
+ return callRuntime(
2364
2372
  "serializeGuard",
2365
2373
  import_compiler13.types.identifier(getSharedUid("serialize")),
2366
2374
  import_compiler13.types.numericLiteral(
@@ -2369,7 +2377,7 @@ function getSerializeGuard(reason) {
2369
2377
  reason
2370
2378
  )
2371
2379
  )
2372
- ) : void 0;
2380
+ );
2373
2381
  }
2374
2382
  var html_default = {
2375
2383
  translate: {
@@ -4316,6 +4324,7 @@ function withPreviousLocation(newNode, originalNode) {
4316
4324
 
4317
4325
  // src/translator/util/references.ts
4318
4326
  var kIsInvoked = Symbol("hoist is invoked");
4327
+ var kBranchSerializeReason = Symbol("branch serialize reason");
4319
4328
  var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
4320
4329
  var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
4321
4330
  function createBinding(name2, type, section, upstreamAlias, property, loc = null, declared = false) {
@@ -4768,8 +4777,16 @@ function finalizeReferences() {
4768
4777
  );
4769
4778
  });
4770
4779
  if (section.parent && section.isBranch && section.sectionAccessor && section.upstreamExpression) {
4771
- addSectionSerializeReasonRef(section, getDirectClosures(section));
4772
- addSectionSerializeReasonExpr(section, section.upstreamExpression);
4780
+ addSectionSerializeReasonRef(
4781
+ section,
4782
+ !!(section.isHoistThrough || section.hoisted) || getDirectClosures(section),
4783
+ kBranchSerializeReason
4784
+ );
4785
+ addSectionSerializeReasonExpr(
4786
+ section,
4787
+ section.upstreamExpression,
4788
+ kBranchSerializeReason
4789
+ );
4773
4790
  addBindingSerializeReasonExpr(
4774
4791
  section.parent,
4775
4792
  section.sectionAccessor.binding,
@@ -5606,78 +5623,70 @@ var import_babel_utils24 = require("@marko/compiler/babel-utils");
5606
5623
  // src/translator/visitors/tag/native-tag.ts
5607
5624
  var import_compiler31 = require("@marko/compiler");
5608
5625
  var import_babel_utils23 = require("@marko/compiler/babel-utils");
5626
+
5627
+ // src/translator/util/css-px-props.ts
5628
+ var css_px_props_default = /* @__PURE__ */ new Set([
5629
+ "background-size",
5630
+ "baseline-shift",
5631
+ "border-bottom-left-radius",
5632
+ "border-bottom-right-radius",
5633
+ "border-bottom-width",
5634
+ "border-left-width",
5635
+ "border-right-width",
5636
+ "border-top-left-radius",
5637
+ "border-top-right-radius",
5638
+ "border-top-width",
5639
+ "bottom",
5640
+ "column-gap",
5641
+ "column-rule-width",
5642
+ "column-width",
5643
+ "cx",
5644
+ "cy",
5645
+ "flex-basis",
5646
+ "font-size",
5647
+ "grid-auto-columns",
5648
+ "grid-auto-rows",
5649
+ "height",
5650
+ "left",
5651
+ "letter-spacing",
5652
+ "margin-bottom",
5653
+ "margin-left",
5654
+ "margin-right",
5655
+ "margin-top",
5656
+ "max-height",
5657
+ "max-width",
5658
+ "min-height",
5659
+ "min-width",
5660
+ "offset-distance",
5661
+ "outline-offset",
5662
+ "outline-width",
5663
+ "padding-bottom",
5664
+ "padding-left",
5665
+ "padding-right",
5666
+ "padding-top",
5667
+ "perspective",
5668
+ "r",
5669
+ "right",
5670
+ "row-gap",
5671
+ "rx",
5672
+ "ry",
5673
+ "shape-margin",
5674
+ "stroke-dashoffset",
5675
+ "stroke-width",
5676
+ "text-indent",
5677
+ "top",
5678
+ "vertical-align",
5679
+ "width",
5680
+ "word-spacing",
5681
+ "x",
5682
+ "y"
5683
+ ]);
5684
+
5685
+ // src/translator/visitors/tag/native-tag.ts
5609
5686
  var kNativeTagBinding = Symbol("native tag binding");
5610
5687
  var kSkipMark = Symbol("skip native tag mark");
5611
5688
  var kGetterId = Symbol("node getter id");
5612
5689
  var htmlSelectArgs = /* @__PURE__ */ new WeakMap();
5613
- function assertExclusiveControllableGroups(tag, attrs2) {
5614
- const exclusiveGroups = [
5615
- attrs2.open || attrs2.openChange,
5616
- attrs2.checked || attrs2.checkedChange,
5617
- attrs2.checkedValue || attrs2.checkedValueChange,
5618
- attrs2.valueChange
5619
- ].filter(Boolean);
5620
- if (exclusiveGroups.length > 1) {
5621
- throw tag.get("name").buildCodeFrameError(
5622
- `The attributes ${exclusiveGroups.map((attr2) => `"${attr2.name}"`).join(", ")} are mutually exclusive.`
5623
- );
5624
- }
5625
- }
5626
- function getRelatedControllable(tagName, attrs2) {
5627
- switch (tagName) {
5628
- case "input":
5629
- if (attrs2.checked || attrs2.checkedChange) {
5630
- return {
5631
- special: false,
5632
- helper: "controllable_input_checked",
5633
- attrs: [attrs2.checked, attrs2.checkedChange]
5634
- };
5635
- }
5636
- if (attrs2.checkedValue || attrs2.checkedValueChange) {
5637
- return {
5638
- special: true,
5639
- helper: "controllable_input_checkedValue",
5640
- attrs: [attrs2.checkedValue, attrs2.checkedValueChange, attrs2.value]
5641
- };
5642
- }
5643
- if (attrs2.value || attrs2.valueChange) {
5644
- return {
5645
- special: false,
5646
- helper: "controllable_input_value",
5647
- attrs: [attrs2.value, attrs2.valueChange]
5648
- };
5649
- }
5650
- break;
5651
- case "select":
5652
- if (attrs2.value || attrs2.valueChange) {
5653
- return {
5654
- special: true,
5655
- helper: "controllable_select_value",
5656
- attrs: [attrs2.value, attrs2.valueChange]
5657
- };
5658
- }
5659
- break;
5660
- case "textarea":
5661
- if (attrs2.value || attrs2.valueChange) {
5662
- return {
5663
- special: true,
5664
- helper: "controllable_textarea_value",
5665
- attrs: [attrs2.value, attrs2.valueChange]
5666
- };
5667
- }
5668
- break;
5669
- case "details":
5670
- case "dialog":
5671
- if (attrs2.open || attrs2.openChange) {
5672
- return {
5673
- special: false,
5674
- helper: "controllable_detailsOrDialog_open",
5675
- attrs: [attrs2.open, attrs2.openChange]
5676
- };
5677
- }
5678
- break;
5679
- }
5680
- }
5681
5690
  var native_tag_default = {
5682
5691
  transform: {
5683
5692
  enter(tag) {
@@ -5783,6 +5792,9 @@ var native_tag_default = {
5783
5792
  relatedControllable.attrs.map((it) => it?.value)
5784
5793
  );
5785
5794
  }
5795
+ if (hasEventHandlers || spreadReferenceNodes) {
5796
+ forceBindingSerialize(tagSection, nodeBinding);
5797
+ }
5786
5798
  if (node.var) {
5787
5799
  forceBindingSerialize(tagSection, nodeBinding);
5788
5800
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
@@ -5794,8 +5806,8 @@ var native_tag_default = {
5794
5806
  tagSection,
5795
5807
  getAccessorProp().Owner
5796
5808
  );
5797
- if (!isInvokedFunction(ref)) {
5798
- tagExtra[kGetterId] ||= getRegisterUID(
5809
+ if (!tagExtra[kGetterId] && !isInvokedFunction(ref)) {
5810
+ tagExtra[kGetterId] = getRegisterUID(
5799
5811
  tagSection,
5800
5812
  nodeBinding.name
5801
5813
  );
@@ -5807,36 +5819,29 @@ var native_tag_default = {
5807
5819
  );
5808
5820
  }
5809
5821
  }
5810
- } else if (hasEventHandlers || spreadReferenceNodes) {
5811
- forceBindingSerialize(tagSection, nodeBinding);
5812
- } else {
5813
- addBindingSerializeReasonExpr(
5814
- tagSection,
5815
- nodeBinding,
5816
- push(attrExprExtras, tagExtra)
5817
- );
5818
5822
  }
5823
+ addBindingSerializeReasonExpr(
5824
+ tagSection,
5825
+ nodeBinding,
5826
+ push(attrExprExtras, tagExtra)
5827
+ );
5819
5828
  }
5820
5829
  }
5821
5830
  },
5822
- translate: {
5823
- enter(tag) {
5824
- const tagName = getTagName(tag);
5825
- const tagExtra = tag.node.extra;
5826
- const nodeBinding = tagExtra[kNativeTagBinding];
5827
- const isHTML = isOutputHTML();
5828
- const name2 = tag.get("name");
5829
- const tagDef = (0, import_babel_utils23.getTagDef)(tag);
5830
- const write2 = writeTo(tag);
5831
- const tagSection = getSection(tag);
5832
- if (isHTML && tagExtra.tagNameNullable) {
5833
- flushBefore(tag);
5834
- }
5835
- if (tag.has("var")) {
5836
- const varName = tag.node.var.name;
5837
- const varBinding = tag.scope.getBinding(varName);
5838
- const getterId = tagExtra[kGetterId];
5839
- if (isHTML) {
5831
+ translate: translateByTarget({
5832
+ html: {
5833
+ enter(tag) {
5834
+ const tagName = getTagName(tag);
5835
+ const tagExtra = tag.node.extra;
5836
+ const nodeBinding = tagExtra[kNativeTagBinding];
5837
+ const tagDef = (0, import_babel_utils23.getTagDef)(tag);
5838
+ const write2 = writeTo(tag);
5839
+ const tagSection = getSection(tag);
5840
+ if (tagExtra.tagNameNullable) {
5841
+ flushBefore(tag);
5842
+ }
5843
+ if (tag.node.var) {
5844
+ const getterId = tagExtra[kGetterId];
5840
5845
  translateVar(
5841
5846
  tag,
5842
5847
  callRuntime(
@@ -5845,96 +5850,21 @@ var native_tag_default = {
5845
5850
  getterId && import_compiler31.types.stringLiteral(getterId)
5846
5851
  )
5847
5852
  );
5848
- } else {
5849
- let getterFnIdentifier;
5850
- if (getterId) {
5851
- getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
5852
- (0, import_babel_utils23.getProgram)().node.body.push(
5853
- import_compiler31.types.variableDeclaration("const", [
5854
- import_compiler31.types.variableDeclarator(
5855
- getterFnIdentifier,
5856
- callRuntime(
5857
- "nodeRef",
5858
- import_compiler31.types.stringLiteral(getterId),
5859
- import_compiler31.types.stringLiteral(
5860
- getAccessorPrefix().Getter + getScopeAccessorLiteral(nodeBinding).value
5861
- )
5862
- )
5863
- )
5864
- ])
5865
- );
5866
- }
5867
- for (const reference of varBinding.referencePaths) {
5868
- const referenceSection = getSection(reference);
5869
- if (isSameOrChildSection(tagSection, referenceSection)) {
5870
- if (isInvokedFunction(reference)) {
5871
- reference.parentPath.replaceWith(
5872
- import_compiler31.types.expressionStatement(
5873
- createScopeReadExpression(referenceSection, nodeBinding)
5874
- )
5875
- );
5876
- } else if (getterFnIdentifier) {
5877
- reference.replaceWith(
5878
- import_compiler31.types.callExpression(getterFnIdentifier, [
5879
- getScopeExpression(referenceSection, getSection(tag))
5880
- ])
5881
- );
5882
- } else {
5883
- reference.replaceWith(
5884
- import_compiler31.types.expressionStatement(
5885
- import_compiler31.types.memberExpression(
5886
- getScopeExpression(tagSection, referenceSection),
5887
- import_compiler31.types.stringLiteral(
5888
- getAccessorPrefix().Getter + getScopeAccessorLiteral(nodeBinding).value
5889
- ),
5890
- true
5891
- )
5892
- )
5893
- );
5894
- }
5895
- }
5896
- }
5897
5853
  }
5898
- }
5899
- const visitAccessor = nodeBinding && getScopeAccessorLiteral(nodeBinding);
5900
- if (visitAccessor) {
5901
- visit(tag, 32 /* Get */);
5902
- }
5903
- write2`<${name2.node}`;
5904
- const usedAttrs = getUsedAttrs(tagName, tag.node);
5905
- const { staticAttrs, staticControllable, skipExpression } = usedAttrs;
5906
- let { spreadExpression } = usedAttrs;
5907
- if (staticControllable) {
5908
- const { helper, attrs: attrs2 } = staticControllable;
5909
- const firstAttr = attrs2.find(Boolean);
5910
- const referencedBindings = firstAttr.value.extra?.referencedBindings;
5911
- const values = attrs2.map((attr2) => attr2?.value);
5912
- if (isHTML) {
5854
+ const visitAccessor = nodeBinding && getScopeAccessorLiteral(nodeBinding);
5855
+ write2`<${tag.node.name}`;
5856
+ const usedAttrs = getUsedAttrs(tagName, tag.node);
5857
+ const { staticAttrs, staticControllable, skipExpression } = usedAttrs;
5858
+ let { spreadExpression } = usedAttrs;
5859
+ if (staticControllable) {
5860
+ const { helper, attrs: attrs2 } = staticControllable;
5913
5861
  if (tagName !== "select" && tagName !== "textarea") {
5862
+ const values = attrs2.map((attr2) => attr2?.value);
5914
5863
  write2`${callRuntime(helper, getScopeIdIdentifier(tagSection), visitAccessor, ...values)}`;
5915
5864
  }
5916
5865
  addHTMLEffectCall(tagSection, void 0);
5917
- } else {
5918
- addStatement(
5919
- "render",
5920
- tagSection,
5921
- referencedBindings,
5922
- import_compiler31.types.expressionStatement(
5923
- callRuntime(helper, scopeIdentifier, visitAccessor, ...values)
5924
- )
5925
- );
5926
- addStatement(
5927
- "effect",
5928
- tagSection,
5929
- void 0,
5930
- import_compiler31.types.expressionStatement(
5931
- callRuntime(`${helper}_effect`, scopeIdentifier, visitAccessor)
5932
- )
5933
- );
5934
5866
  }
5935
- }
5936
- let writeAtStartOfBody;
5937
- if (isHTML) {
5867
+ let writeAtStartOfBody;
5938
5868
  if (tagName === "select") {
5939
5869
  if (staticControllable) {
5940
5870
  htmlSelectArgs.set(tag.node, {
@@ -5990,89 +5920,313 @@ var native_tag_default = {
5990
5920
  );
5991
5921
  }
5992
5922
  }
5993
- }
5994
- for (const attr2 of staticAttrs) {
5995
- const { name: name3, value } = attr2;
5996
- const { confident, computed } = value.extra || {};
5997
- const valueReferences = value.extra?.referencedBindings;
5998
- if (isHTML && tagName === "option" && name3 === "value") {
5999
- write2`${callRuntime("optionValueAttr", value)}`;
6000
- continue;
6001
- }
6002
- switch (name3) {
6003
- case "class":
6004
- case "style": {
6005
- const helper = `${name3}Attr`;
6006
- if (confident) {
6007
- write2`${getHTMLRuntime()[helper](computed)}`;
6008
- } else if (isHTML) {
6009
- write2`${callRuntime(helper, value)}`;
6010
- } else {
6011
- addStatement(
6012
- "render",
6013
- tagSection,
6014
- valueReferences,
6015
- import_compiler31.types.expressionStatement(
6016
- callRuntime(
6017
- helper,
6018
- import_compiler31.types.memberExpression(scopeIdentifier, visitAccessor, true),
6019
- value
6020
- )
6021
- )
6022
- );
6023
- }
6024
- break;
5923
+ for (const attr2 of staticAttrs) {
5924
+ const { name: name2, value } = attr2;
5925
+ const { confident, computed } = value.extra || {};
5926
+ const valueReferences = value.extra?.referencedBindings;
5927
+ if (tagName === "option" && name2 === "value") {
5928
+ write2`${callRuntime("optionValueAttr", value)}`;
5929
+ continue;
6025
5930
  }
6026
- default:
6027
- if (confident) {
6028
- write2`${getHTMLRuntime().attr(name3, computed)}`;
6029
- } else if (isHTML) {
6030
- if (isEventHandler(name3)) {
6031
- addHTMLEffectCall(tagSection, valueReferences);
5931
+ switch (name2) {
5932
+ case "class":
5933
+ case "style": {
5934
+ const helper = `${name2}Attr`;
5935
+ if (confident) {
5936
+ write2`${getHTMLRuntime()[helper](computed)}`;
6032
5937
  } else {
6033
- write2`${callRuntime("attr", import_compiler31.types.stringLiteral(name3), value)}`;
5938
+ write2`${callRuntime(helper, value)}`;
6034
5939
  }
6035
- } else if (isEventHandler(name3)) {
6036
- addStatement(
6037
- "effect",
6038
- tagSection,
6039
- valueReferences,
6040
- import_compiler31.types.expressionStatement(
6041
- callRuntime(
6042
- "on",
6043
- import_compiler31.types.memberExpression(scopeIdentifier, visitAccessor, true),
6044
- import_compiler31.types.stringLiteral(getEventHandlerName(name3)),
6045
- value
6046
- )
6047
- )
6048
- );
6049
- } else {
6050
- addStatement(
6051
- "render",
6052
- tagSection,
6053
- valueReferences,
6054
- import_compiler31.types.expressionStatement(
6055
- callRuntime(
6056
- "attr",
6057
- import_compiler31.types.memberExpression(scopeIdentifier, visitAccessor, true),
6058
- import_compiler31.types.stringLiteral(name3),
6059
- value
6060
- )
6061
- )
6062
- );
5940
+ break;
6063
5941
  }
6064
- break;
5942
+ default:
5943
+ if (confident) {
5944
+ write2`${getHTMLRuntime().attr(name2, computed)}`;
5945
+ } else if (isEventHandler(name2)) {
5946
+ addHTMLEffectCall(tagSection, valueReferences);
5947
+ } else {
5948
+ write2`${callRuntime("attr", import_compiler31.types.stringLiteral(name2), value)}`;
5949
+ }
5950
+ break;
5951
+ }
6065
5952
  }
6066
- }
6067
- if (spreadExpression) {
6068
- if (isHTML) {
5953
+ if (spreadExpression) {
6069
5954
  addHTMLEffectCall(tagSection, tagExtra.referencedBindings);
6070
5955
  if (skipExpression) {
6071
- write2`${callRuntime("partialAttrs", spreadExpression, skipExpression, visitAccessor, getScopeIdIdentifier(tagSection), name2.node)}`;
5956
+ write2`${callRuntime("partialAttrs", spreadExpression, skipExpression, visitAccessor, getScopeIdIdentifier(tagSection), tag.node.name)}`;
6072
5957
  } else {
6073
- write2`${callRuntime("attrs", spreadExpression, visitAccessor, getScopeIdIdentifier(tagSection), name2.node)}`;
5958
+ write2`${callRuntime("attrs", spreadExpression, visitAccessor, getScopeIdIdentifier(tagSection), tag.node.name)}`;
5959
+ }
5960
+ }
5961
+ if (tagDef && tagDef.parseOptions?.openTagOnly) {
5962
+ switch (tagDef.htmlType) {
5963
+ case "svg":
5964
+ case "math":
5965
+ write2`/>`;
5966
+ break;
5967
+ default:
5968
+ write2`>`;
5969
+ break;
6074
5970
  }
6075
5971
  } else {
5972
+ write2`>`;
5973
+ }
5974
+ if (tagExtra.tagNameNullable) {
5975
+ tag.insertBefore(
5976
+ import_compiler31.types.ifStatement(tag.node.name, consumeHTML(tag))
5977
+ )[0].skip();
5978
+ }
5979
+ if (writeAtStartOfBody) {
5980
+ write2`${writeAtStartOfBody}`;
5981
+ }
5982
+ },
5983
+ exit(tag) {
5984
+ const tagExtra = tag.node.extra;
5985
+ const nodeBinding = tagExtra[kNativeTagBinding];
5986
+ const openTagOnly = (0, import_babel_utils23.getTagDef)(tag)?.parseOptions?.openTagOnly;
5987
+ const selectArgs = htmlSelectArgs.get(tag.node);
5988
+ const tagName = getTagName(tag);
5989
+ const tagSection = getSection(tag);
5990
+ if (tagExtra.tagNameNullable) {
5991
+ flushInto(tag);
5992
+ }
5993
+ if (selectArgs) {
5994
+ writeTo(tag)`</${tag.node.name}>`;
5995
+ flushInto(tag);
5996
+ tag.insertBefore(
5997
+ import_compiler31.types.expressionStatement(
5998
+ callRuntime(
5999
+ "controllable_select_value",
6000
+ getScopeIdIdentifier(getSection(tag)),
6001
+ getScopeAccessorLiteral(nodeBinding),
6002
+ selectArgs.value,
6003
+ selectArgs.valueChange,
6004
+ import_compiler31.types.arrowFunctionExpression(
6005
+ [],
6006
+ import_compiler31.types.blockStatement(tag.node.body.body)
6007
+ )
6008
+ )
6009
+ )
6010
+ );
6011
+ } else {
6012
+ tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
6013
+ }
6014
+ const markerSerializeReason = nodeBinding && !tagExtra[kSkipMark] && getBindingSerializeReason(tagSection, nodeBinding);
6015
+ if (!openTagOnly && !selectArgs) {
6016
+ writeTo(
6017
+ tag,
6018
+ !markerSerializeReason && (tagName === "html" || tagName === "body")
6019
+ )`</${tag.node.name}>`;
6020
+ }
6021
+ if (tagExtra.tagNameNullable) {
6022
+ tag.insertBefore(
6023
+ import_compiler31.types.ifStatement(tag.node.name, consumeHTML(tag))
6024
+ )[0].skip();
6025
+ }
6026
+ if (markerSerializeReason) {
6027
+ markNode(tag, nodeBinding, markerSerializeReason);
6028
+ }
6029
+ tag.remove();
6030
+ }
6031
+ },
6032
+ dom: {
6033
+ enter(tag) {
6034
+ const tagName = getTagName(tag);
6035
+ const tagExtra = tag.node.extra;
6036
+ const nodeBinding = tagExtra[kNativeTagBinding];
6037
+ const tagDef = (0, import_babel_utils23.getTagDef)(tag);
6038
+ const write2 = writeTo(tag);
6039
+ const tagSection = getSection(tag);
6040
+ if (tag.node.var) {
6041
+ const varName = tag.node.var.name;
6042
+ const varBinding = tag.scope.getBinding(varName);
6043
+ const getterId = tagExtra[kGetterId];
6044
+ let getterFnIdentifier;
6045
+ if (getterId) {
6046
+ getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
6047
+ (0, import_babel_utils23.getProgram)().node.body.push(
6048
+ import_compiler31.types.variableDeclaration("const", [
6049
+ import_compiler31.types.variableDeclarator(
6050
+ getterFnIdentifier,
6051
+ callRuntime(
6052
+ "nodeRef",
6053
+ import_compiler31.types.stringLiteral(getterId),
6054
+ import_compiler31.types.stringLiteral(
6055
+ getAccessorPrefix().Getter + getScopeAccessorLiteral(nodeBinding).value
6056
+ )
6057
+ )
6058
+ )
6059
+ ])
6060
+ );
6061
+ }
6062
+ for (const reference of varBinding.referencePaths) {
6063
+ const referenceSection = getSection(reference);
6064
+ if (isSameOrChildSection(tagSection, referenceSection)) {
6065
+ if (isInvokedFunction(reference)) {
6066
+ reference.parentPath.replaceWith(
6067
+ import_compiler31.types.expressionStatement(
6068
+ createScopeReadExpression(referenceSection, nodeBinding)
6069
+ )
6070
+ );
6071
+ } else if (getterFnIdentifier) {
6072
+ reference.replaceWith(
6073
+ import_compiler31.types.callExpression(getterFnIdentifier, [
6074
+ getScopeExpression(referenceSection, getSection(tag))
6075
+ ])
6076
+ );
6077
+ } else {
6078
+ reference.replaceWith(
6079
+ import_compiler31.types.expressionStatement(
6080
+ import_compiler31.types.memberExpression(
6081
+ getScopeExpression(tagSection, referenceSection),
6082
+ import_compiler31.types.stringLiteral(
6083
+ getAccessorPrefix().Getter + getScopeAccessorLiteral(nodeBinding).value
6084
+ ),
6085
+ true
6086
+ )
6087
+ )
6088
+ );
6089
+ }
6090
+ }
6091
+ }
6092
+ }
6093
+ const visitAccessor = nodeBinding && getScopeAccessorLiteral(nodeBinding);
6094
+ if (visitAccessor) {
6095
+ visit(tag, 32 /* Get */);
6096
+ }
6097
+ write2`<${tag.node.name}`;
6098
+ const usedAttrs = getUsedAttrs(tagName, tag.node);
6099
+ const { staticAttrs, staticControllable, skipExpression } = usedAttrs;
6100
+ const { spreadExpression } = usedAttrs;
6101
+ if (staticControllable) {
6102
+ const { helper, attrs: attrs2 } = staticControllable;
6103
+ const firstAttr = attrs2.find(Boolean);
6104
+ const referencedBindings = firstAttr.value.extra?.referencedBindings;
6105
+ const values = attrs2.map((attr2) => attr2?.value);
6106
+ addStatement(
6107
+ "render",
6108
+ tagSection,
6109
+ referencedBindings,
6110
+ import_compiler31.types.expressionStatement(
6111
+ callRuntime(helper, scopeIdentifier, visitAccessor, ...values)
6112
+ )
6113
+ );
6114
+ addStatement(
6115
+ "effect",
6116
+ tagSection,
6117
+ void 0,
6118
+ import_compiler31.types.expressionStatement(
6119
+ callRuntime(`${helper}_effect`, scopeIdentifier, visitAccessor)
6120
+ )
6121
+ );
6122
+ }
6123
+ for (const attr2 of staticAttrs) {
6124
+ const { name: name2, value } = attr2;
6125
+ const { confident, computed } = value.extra || {};
6126
+ const valueReferences = value.extra?.referencedBindings;
6127
+ switch (name2) {
6128
+ case "class":
6129
+ case "style": {
6130
+ const helper = `${name2}Attr`;
6131
+ if (confident) {
6132
+ write2`${getHTMLRuntime()[helper](computed)}`;
6133
+ } else {
6134
+ const nodeExpr = import_compiler31.types.memberExpression(
6135
+ scopeIdentifier,
6136
+ visitAccessor,
6137
+ true
6138
+ );
6139
+ const meta = {
6140
+ staticItems: void 0,
6141
+ dynamicItems: void 0,
6142
+ dynamicValues: void 0
6143
+ };
6144
+ let stmt;
6145
+ trackDelimitedAttrValue(value, meta);
6146
+ if (meta.dynamicItems) {
6147
+ stmt = import_compiler31.types.expressionStatement(
6148
+ callRuntime(helper, nodeExpr, value)
6149
+ );
6150
+ } else {
6151
+ if (meta.staticItems) {
6152
+ write2`${getHTMLRuntime()[helper](computed)}`;
6153
+ }
6154
+ if (meta.dynamicValues) {
6155
+ const keys = Object.keys(meta.dynamicValues);
6156
+ if (keys.length === 1) {
6157
+ const [key] = keys;
6158
+ const value2 = meta.dynamicValues[key];
6159
+ stmt = import_compiler31.types.expressionStatement(
6160
+ callRuntime(
6161
+ `${name2}Item`,
6162
+ nodeExpr,
6163
+ import_compiler31.types.stringLiteral(key),
6164
+ name2 === "style" && css_px_props_default.has(name2) ? callRuntime("styleItemValue", value2) : value2
6165
+ )
6166
+ );
6167
+ } else {
6168
+ const props = [];
6169
+ for (const key of keys) {
6170
+ const value2 = meta.dynamicValues[key];
6171
+ props.push(
6172
+ import_compiler31.types.objectProperty(
6173
+ toPropertyName(key),
6174
+ name2 === "style" && css_px_props_default.has(name2) ? callRuntime("styleItemValue", value2) : value2
6175
+ )
6176
+ );
6177
+ }
6178
+ stmt = import_compiler31.types.expressionStatement(
6179
+ callRuntime(
6180
+ `${name2}Items`,
6181
+ nodeExpr,
6182
+ import_compiler31.types.objectExpression(props)
6183
+ )
6184
+ );
6185
+ }
6186
+ }
6187
+ }
6188
+ if (stmt) {
6189
+ addStatement("render", tagSection, valueReferences, stmt);
6190
+ }
6191
+ }
6192
+ break;
6193
+ }
6194
+ default:
6195
+ if (confident) {
6196
+ write2`${getHTMLRuntime().attr(name2, computed)}`;
6197
+ } else if (isEventHandler(name2)) {
6198
+ addStatement(
6199
+ "effect",
6200
+ tagSection,
6201
+ valueReferences,
6202
+ import_compiler31.types.expressionStatement(
6203
+ callRuntime(
6204
+ "on",
6205
+ import_compiler31.types.memberExpression(scopeIdentifier, visitAccessor, true),
6206
+ import_compiler31.types.stringLiteral(getEventHandlerName(name2)),
6207
+ value
6208
+ )
6209
+ )
6210
+ );
6211
+ } else {
6212
+ addStatement(
6213
+ "render",
6214
+ tagSection,
6215
+ valueReferences,
6216
+ import_compiler31.types.expressionStatement(
6217
+ callRuntime(
6218
+ "attr",
6219
+ import_compiler31.types.memberExpression(scopeIdentifier, visitAccessor, true),
6220
+ import_compiler31.types.stringLiteral(name2),
6221
+ value
6222
+ )
6223
+ )
6224
+ );
6225
+ }
6226
+ break;
6227
+ }
6228
+ }
6229
+ if (spreadExpression) {
6076
6230
  if (skipExpression) {
6077
6231
  addStatement(
6078
6232
  "render",
@@ -6113,80 +6267,101 @@ var native_tag_default = {
6113
6267
  false
6114
6268
  );
6115
6269
  }
6116
- }
6117
- if (tagDef && tagDef.parseOptions?.openTagOnly) {
6118
- switch (tagDef.htmlType) {
6119
- case "svg":
6120
- case "math":
6121
- write2`/>`;
6122
- break;
6123
- default:
6124
- write2`>`;
6125
- break;
6270
+ if (tagDef && tagDef.parseOptions?.openTagOnly) {
6271
+ switch (tagDef.htmlType) {
6272
+ case "svg":
6273
+ case "math":
6274
+ write2`/>`;
6275
+ break;
6276
+ default:
6277
+ write2`>`;
6278
+ break;
6279
+ }
6280
+ } else {
6281
+ write2`>`;
6126
6282
  }
6127
- } else {
6128
- write2`>`;
6129
- }
6130
- if (isHTML && tagExtra.tagNameNullable) {
6131
- tag.insertBefore(import_compiler31.types.ifStatement(name2.node, consumeHTML(tag)))[0].skip();
6283
+ enter2(tag);
6284
+ },
6285
+ exit(tag) {
6286
+ const openTagOnly = (0, import_babel_utils23.getTagDef)(tag)?.parseOptions?.openTagOnly;
6287
+ tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
6288
+ if (!openTagOnly) {
6289
+ writeTo(tag)`</${tag.node.name}>`;
6290
+ }
6291
+ exit2(tag);
6292
+ tag.remove();
6132
6293
  }
6133
- if (writeAtStartOfBody) {
6134
- write2`${writeAtStartOfBody}`;
6294
+ }
6295
+ })
6296
+ };
6297
+ function assertExclusiveControllableGroups(tag, attrs2) {
6298
+ const exclusiveGroups = [
6299
+ attrs2.open || attrs2.openChange,
6300
+ attrs2.checked || attrs2.checkedChange,
6301
+ attrs2.checkedValue || attrs2.checkedValueChange,
6302
+ attrs2.valueChange
6303
+ ].filter(Boolean);
6304
+ if (exclusiveGroups.length > 1) {
6305
+ throw tag.get("name").buildCodeFrameError(
6306
+ `The attributes ${exclusiveGroups.map((attr2) => `"${attr2.name}"`).join(", ")} are mutually exclusive.`
6307
+ );
6308
+ }
6309
+ }
6310
+ function getRelatedControllable(tagName, attrs2) {
6311
+ switch (tagName) {
6312
+ case "input":
6313
+ if (attrs2.checked || attrs2.checkedChange) {
6314
+ return {
6315
+ special: false,
6316
+ helper: "controllable_input_checked",
6317
+ attrs: [attrs2.checked, attrs2.checkedChange]
6318
+ };
6135
6319
  }
6136
- enter2(tag);
6137
- },
6138
- exit(tag) {
6139
- const tagExtra = tag.node.extra;
6140
- const nodeBinding = tagExtra[kNativeTagBinding];
6141
- const isHTML = isOutputHTML();
6142
- const openTagOnly = (0, import_babel_utils23.getTagDef)(tag)?.parseOptions?.openTagOnly;
6143
- const selectArgs = isHTML && htmlSelectArgs.get(tag.node);
6144
- const tagName = getTagName(tag);
6145
- const tagSection = getSection(tag);
6146
- if (isHTML && tagExtra.tagNameNullable) {
6147
- flushInto(tag);
6320
+ if (attrs2.checkedValue || attrs2.checkedValueChange) {
6321
+ return {
6322
+ special: true,
6323
+ helper: "controllable_input_checkedValue",
6324
+ attrs: [attrs2.checkedValue, attrs2.checkedValueChange, attrs2.value]
6325
+ };
6148
6326
  }
6149
- if (selectArgs) {
6150
- writeTo(tag)`</${tag.node.name}>`;
6151
- flushInto(tag);
6152
- tag.insertBefore(
6153
- import_compiler31.types.expressionStatement(
6154
- callRuntime(
6155
- "controllable_select_value",
6156
- getScopeIdIdentifier(getSection(tag)),
6157
- getScopeAccessorLiteral(nodeBinding),
6158
- selectArgs.value,
6159
- selectArgs.valueChange,
6160
- import_compiler31.types.arrowFunctionExpression(
6161
- [],
6162
- import_compiler31.types.blockStatement(tag.node.body.body)
6163
- )
6164
- )
6165
- )
6166
- );
6167
- } else {
6168
- tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
6327
+ if (attrs2.value || attrs2.valueChange) {
6328
+ return {
6329
+ special: false,
6330
+ helper: "controllable_input_value",
6331
+ attrs: [attrs2.value, attrs2.valueChange]
6332
+ };
6169
6333
  }
6170
- const markerSerializeReason = nodeBinding && !tagExtra[kSkipMark] && getBindingSerializeReason(tagSection, nodeBinding);
6171
- if (!openTagOnly && !selectArgs) {
6172
- writeTo(
6173
- tag,
6174
- isHTML && !markerSerializeReason && (tagName === "html" || tagName === "body")
6175
- )`</${tag.node.name}>`;
6334
+ break;
6335
+ case "select":
6336
+ if (attrs2.value || attrs2.valueChange) {
6337
+ return {
6338
+ special: true,
6339
+ helper: "controllable_select_value",
6340
+ attrs: [attrs2.value, attrs2.valueChange]
6341
+ };
6176
6342
  }
6177
- if (isHTML && tagExtra.tagNameNullable) {
6178
- tag.insertBefore(
6179
- import_compiler31.types.ifStatement(tag.node.name, consumeHTML(tag))
6180
- )[0].skip();
6343
+ break;
6344
+ case "textarea":
6345
+ if (attrs2.value || attrs2.valueChange) {
6346
+ return {
6347
+ special: true,
6348
+ helper: "controllable_textarea_value",
6349
+ attrs: [attrs2.value, attrs2.valueChange]
6350
+ };
6181
6351
  }
6182
- if (markerSerializeReason) {
6183
- markNode(tag, nodeBinding, markerSerializeReason);
6352
+ break;
6353
+ case "details":
6354
+ case "dialog":
6355
+ if (attrs2.open || attrs2.openChange) {
6356
+ return {
6357
+ special: false,
6358
+ helper: "controllable_detailsOrDialog_open",
6359
+ attrs: [attrs2.open, attrs2.openChange]
6360
+ };
6184
6361
  }
6185
- exit2(tag);
6186
- tag.remove();
6187
- }
6362
+ break;
6188
6363
  }
6189
- };
6364
+ }
6190
6365
  function getUsedAttrs(tagName, tag) {
6191
6366
  const seen = {};
6192
6367
  const { attributes } = tag;
@@ -6263,6 +6438,86 @@ function getUsedAttrs(tagName, tag) {
6263
6438
  skipExpression
6264
6439
  };
6265
6440
  }
6441
+ function trackDelimitedAttrValue(expr, meta) {
6442
+ switch (expr.type) {
6443
+ case "ObjectExpression":
6444
+ trackDelimitedAttrObjectProperties(expr, meta);
6445
+ break;
6446
+ case "ArrayExpression":
6447
+ trackDelimitedAttrArrayItems(expr, meta);
6448
+ break;
6449
+ default:
6450
+ (meta.dynamicItems ||= []).push(expr);
6451
+ break;
6452
+ }
6453
+ }
6454
+ function trackDelimitedAttrArrayItems(arr, meta) {
6455
+ for (const item of arr.elements) {
6456
+ if (item) {
6457
+ switch (item.type) {
6458
+ case "ArrayExpression": {
6459
+ trackDelimitedAttrArrayItems(item, meta);
6460
+ break;
6461
+ }
6462
+ case "ObjectExpression": {
6463
+ trackDelimitedAttrObjectProperties(item, meta);
6464
+ break;
6465
+ }
6466
+ case "SpreadElement":
6467
+ if (item.argument.type === "ArrayExpression") {
6468
+ trackDelimitedAttrArrayItems(item.argument, meta);
6469
+ } else {
6470
+ (meta.dynamicItems ||= []).push(item);
6471
+ }
6472
+ break;
6473
+ default: {
6474
+ const evalItem = evaluate(item);
6475
+ if (evalItem.confident) {
6476
+ (meta.staticItems ||= []).push(evalItem.computed);
6477
+ } else {
6478
+ (meta.dynamicItems ||= []).push(item);
6479
+ }
6480
+ break;
6481
+ }
6482
+ }
6483
+ }
6484
+ }
6485
+ }
6486
+ function trackDelimitedAttrObjectProperties(obj, meta) {
6487
+ let staticProps;
6488
+ let dynamicProps;
6489
+ for (const prop of obj.properties) {
6490
+ if (prop.type !== "ObjectProperty" || prop.computed) {
6491
+ (dynamicProps ||= []).push(prop);
6492
+ continue;
6493
+ }
6494
+ let key;
6495
+ if (prop.key.type === "Identifier") {
6496
+ key = prop.key.name;
6497
+ } else {
6498
+ const keyEval = evaluate(prop.key);
6499
+ if (keyEval.confident) {
6500
+ key = keyEval.computed + "";
6501
+ } else {
6502
+ (dynamicProps ||= []).push(prop);
6503
+ continue;
6504
+ }
6505
+ }
6506
+ const value = prop.value;
6507
+ const propEval = evaluate(value);
6508
+ if (propEval.confident) {
6509
+ (staticProps ||= {})[key] = propEval.computed;
6510
+ } else {
6511
+ (meta.dynamicValues ||= {})[key] = value;
6512
+ }
6513
+ }
6514
+ if (staticProps) {
6515
+ (meta.staticItems ||= []).push(staticProps);
6516
+ }
6517
+ if (dynamicProps) {
6518
+ (meta.dynamicItems ||= []).push(import_compiler31.types.objectExpression(dynamicProps));
6519
+ }
6520
+ }
6266
6521
  function isChangeHandler(propName) {
6267
6522
  return /^(?:value|checked(?:Value)?|open)Change/.test(propName);
6268
6523
  }
@@ -6385,14 +6640,14 @@ var for_default = {
6385
6640
  const statements = [];
6386
6641
  const bodyStatements = node.body.body;
6387
6642
  const singleNodeOptimization = bodySection.content === null || bodySection.content.singleChild && bodySection.content.startType !== 4 /* Text */;
6388
- const branchSerializeReason = getSectionSerializeReason(bodySection);
6643
+ const branchSerializeReason = getSectionSerializeReason(
6644
+ bodySection,
6645
+ kBranchSerializeReason
6646
+ );
6389
6647
  const markerSerializeReason = getBindingSerializeReason(
6390
6648
  tagSection,
6391
6649
  nodeBinding
6392
6650
  );
6393
- if (markerSerializeReason && onlyChildInParentOptimization) {
6394
- getParentTag(tag).node.extra[kSkipMark] = true;
6395
- }
6396
6651
  flushInto(tag);
6397
6652
  writeHTMLResumeStatements(tagBody);
6398
6653
  const forTagArgs = getBaseArgsInForTag(forType, forAttrs);
@@ -6401,18 +6656,15 @@ var for_default = {
6401
6656
  import_compiler33.types.arrowFunctionExpression(params, import_compiler33.types.blockStatement(bodyStatements))
6402
6657
  );
6403
6658
  if (branchSerializeReason) {
6659
+ if (markerSerializeReason && onlyChildInParentOptimization) {
6660
+ getParentTag(tag).node.extra[kSkipMark] = true;
6661
+ }
6404
6662
  forTagArgs.push(
6405
6663
  forAttrs.by || import_compiler33.types.numericLiteral(0),
6406
6664
  getScopeIdIdentifier(tagSection),
6407
6665
  getScopeAccessorLiteral(nodeBinding),
6408
- branchSerializeReason === true || markerSerializeReason === true ? import_compiler33.types.numericLiteral(1) : markerSerializeReason && !bindingUtil.isSuperset(
6409
- branchSerializeReason,
6410
- markerSerializeReason
6411
- ) ? import_compiler33.types.logicalExpression(
6412
- "||",
6413
- getSerializeGuard(branchSerializeReason),
6414
- getSerializeGuard(markerSerializeReason)
6415
- ) : getSerializeGuard(branchSerializeReason)
6666
+ branchSerializeReason === true ? markerSerializeReason === true && !onlyChildInParentOptimization ? void 0 : import_compiler33.types.numericLiteral(1) : getSerializeGuard(branchSerializeReason),
6667
+ !markerSerializeReason ? import_compiler33.types.numericLiteral(0) : markerSerializeReason === true ? onlyChildInParentOptimization ? import_compiler33.types.numericLiteral(1) : void 0 : getSerializeGuard(markerSerializeReason)
6416
6668
  );
6417
6669
  if (onlyChildInParentOptimization) {
6418
6670
  forTagArgs.push(import_compiler33.types.numericLiteral(1));
@@ -7371,6 +7623,9 @@ var html_script_default = {
7371
7623
  bodyPlaceholderNodes.slice(1)
7372
7624
  );
7373
7625
  }
7626
+ if (hasEventHandlers || spreadReferenceNodes) {
7627
+ forceBindingSerialize(tagSection, nodeBinding);
7628
+ }
7374
7629
  if (node.var) {
7375
7630
  forceBindingSerialize(tagSection, nodeBinding);
7376
7631
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
@@ -7389,15 +7644,12 @@ var html_script_default = {
7389
7644
  trackHoistedReference(ref, nodeBinding);
7390
7645
  }
7391
7646
  }
7392
- } else if (hasEventHandlers || spreadReferenceNodes) {
7393
- forceBindingSerialize(tagSection, nodeBinding);
7394
- } else {
7395
- addBindingSerializeReasonExpr(
7396
- tagSection,
7397
- nodeBinding,
7398
- push(attrExprExtras, tagExtra)
7399
- );
7400
7647
  }
7648
+ addBindingSerializeReasonExpr(
7649
+ tagSection,
7650
+ nodeBinding,
7651
+ push(attrExprExtras, tagExtra)
7652
+ );
7401
7653
  }
7402
7654
  },
7403
7655
  translate: {
@@ -7783,6 +8035,9 @@ var html_style_default = {
7783
8035
  bodyPlaceholderNodes.slice(1)
7784
8036
  );
7785
8037
  }
8038
+ if (hasEventHandlers || spreadReferenceNodes) {
8039
+ forceBindingSerialize(tagSection, nodeBinding);
8040
+ }
7786
8041
  if (node.var) {
7787
8042
  forceBindingSerialize(tagSection, nodeBinding);
7788
8043
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
@@ -7801,15 +8056,12 @@ var html_style_default = {
7801
8056
  trackHoistedReference(ref, nodeBinding);
7802
8057
  }
7803
8058
  }
7804
- } else if (hasEventHandlers || spreadReferenceNodes) {
7805
- forceBindingSerialize(tagSection, nodeBinding);
7806
- } else {
7807
- addBindingSerializeReasonExpr(
7808
- tagSection,
7809
- nodeBinding,
7810
- push(attrExprExtras, tagExtra)
7811
- );
7812
8059
  }
8060
+ addBindingSerializeReasonExpr(
8061
+ tagSection,
8062
+ nodeBinding,
8063
+ push(attrExprExtras, tagExtra)
8064
+ );
7813
8065
  }
7814
8066
  },
7815
8067
  translate: {
@@ -8255,14 +8507,14 @@ var IfTag = {
8255
8507
  const nextTag = tag.getNextSibling();
8256
8508
  let branchSerializeReasons;
8257
8509
  let statement;
8258
- if (markerSerializeReason && onlyChildInParentOptimization) {
8259
- getParentTag(ifTag).node.extra[kSkipMark] = true;
8260
- }
8261
8510
  for (let i = branches.length; i--; ) {
8262
8511
  const [branchTag, branchBody] = branches[i];
8263
8512
  const bodyStatements = branchTag.node.body.body;
8264
8513
  if (branchBody) {
8265
- const branchSerializeReason = getSectionSerializeReason(branchBody);
8514
+ const branchSerializeReason = getSectionSerializeReason(
8515
+ branchBody,
8516
+ kBranchSerializeReason
8517
+ );
8266
8518
  if (branchSerializeReason) {
8267
8519
  if (branchSerializeReasons !== true) {
8268
8520
  if (branchSerializeReason === true) {
@@ -8296,7 +8548,9 @@ var IfTag = {
8296
8548
  branchTag.remove();
8297
8549
  }
8298
8550
  if (branchSerializeReasons) {
8299
- const branchSerializeExpr = branchSerializeReasons === true ? !onlyChildInParentOptimization && !markerSerializeReason ? void 0 : getSerializeGuard(branchSerializeReasons) : getSerializeGuardForAny(branchSerializeReasons);
8551
+ if (onlyChildInParentOptimization && markerSerializeReason) {
8552
+ getParentTag(ifTag).node.extra[kSkipMark] = true;
8553
+ }
8300
8554
  const cbNode = import_compiler42.types.arrowFunctionExpression(
8301
8555
  [],
8302
8556
  import_compiler42.types.blockStatement([statement])
@@ -8307,16 +8561,16 @@ var IfTag = {
8307
8561
  cbNode,
8308
8562
  getScopeIdIdentifier(ifTagSection),
8309
8563
  getScopeAccessorLiteral(nodeBinding),
8310
- branchSerializeExpr,
8311
- markerSerializeReason ? getSerializeGuard(markerSerializeReason) : onlyChildInParentOptimization ? import_compiler42.types.numericLiteral(0) : void 0,
8564
+ branchSerializeReasons === true ? markerSerializeReason === true && !onlyChildInParentOptimization ? void 0 : import_compiler42.types.numericLiteral(1) : getSerializeGuardForAny(branchSerializeReasons),
8565
+ !markerSerializeReason ? import_compiler42.types.numericLiteral(0) : markerSerializeReason === true ? onlyChildInParentOptimization ? import_compiler42.types.numericLiteral(1) : void 0 : getSerializeGuard(markerSerializeReason),
8312
8566
  onlyChildInParentOptimization && import_compiler42.types.numericLiteral(1)
8313
8567
  ) : callRuntime(
8314
8568
  "resumeConditional",
8315
8569
  cbNode,
8316
8570
  getScopeIdIdentifier(ifTagSection),
8317
8571
  getScopeAccessorLiteral(nodeBinding),
8318
- branchSerializeExpr,
8319
- getSerializeGuard(markerSerializeReason)
8572
+ branchSerializeReasons === true ? markerSerializeReason === true ? void 0 : import_compiler42.types.numericLiteral(1) : getSerializeGuardForAny(branchSerializeReasons),
8573
+ !markerSerializeReason ? import_compiler42.types.numericLiteral(0) : markerSerializeReason === true ? void 0 : getSerializeGuard(markerSerializeReason)
8320
8574
  )
8321
8575
  );
8322
8576
  }
@@ -9834,13 +10088,12 @@ function translateHTML(tag) {
9834
10088
  let childSerializeReasonExpr;
9835
10089
  if (childSerializeReasonIds) {
9836
10090
  if (childSerializeReasonIds.length === 1) {
9837
- childSerializeReasonExpr = getSerializeGuard(
9838
- getBindingSerializeReason(
9839
- section,
9840
- childScopeBinding,
9841
- childSerializeReasonIds[0]
9842
- )
10091
+ const reason = getBindingSerializeReason(
10092
+ section,
10093
+ childScopeBinding,
10094
+ childSerializeReasonIds[0]
9843
10095
  );
10096
+ childSerializeReasonExpr = !reason ? void 0 : reason == true ? import_compiler56.types.numericLiteral(1) : getSerializeGuard(reason);
9844
10097
  } else {
9845
10098
  const props = [];
9846
10099
  let hasDynamicReasons = false;
@@ -9854,7 +10107,10 @@ function translateHTML(tag) {
9854
10107
  if (reason) {
9855
10108
  hasDynamicReasons ||= reason !== true;
9856
10109
  props.push(
9857
- import_compiler56.types.objectProperty(import_compiler56.types.numericLiteral(i), getSerializeGuard(reason))
10110
+ import_compiler56.types.objectProperty(
10111
+ import_compiler56.types.numericLiteral(i),
10112
+ reason === true ? import_compiler56.types.numericLiteral(1) : getSerializeGuard(reason)
10113
+ )
9858
10114
  );
9859
10115
  } else {
9860
10116
  hasSkippedReasons = true;
@@ -10598,6 +10854,7 @@ var dynamic_tag_default = {
10598
10854
  tagSection,
10599
10855
  nodeBinding
10600
10856
  );
10857
+ const serializeArg = !serializeReason ? import_compiler57.types.numericLiteral(0) : serializeReason === true ? void 0 : getSerializeGuard(serializeReason);
10601
10858
  const dynamicTagExpr = hasTagArgs ? callRuntime(
10602
10859
  "dynamicTag",
10603
10860
  getScopeIdIdentifier(tagSection),
@@ -10606,16 +10863,16 @@ var dynamic_tag_default = {
10606
10863
  import_compiler57.types.arrayExpression(args),
10607
10864
  import_compiler57.types.numericLiteral(0),
10608
10865
  import_compiler57.types.numericLiteral(1),
10609
- getSerializeGuard(serializeReason)
10866
+ serializeArg
10610
10867
  ) : callRuntime(
10611
10868
  "dynamicTag",
10612
10869
  getScopeIdIdentifier(tagSection),
10613
10870
  getScopeAccessorLiteral(nodeBinding),
10614
10871
  tagExpression,
10615
10872
  args[0],
10616
- args[1] || (serializeReason ? import_compiler57.types.numericLiteral(0) : void 0),
10617
- serializeReason ? import_compiler57.types.numericLiteral(0) : void 0,
10618
- getSerializeGuard(serializeReason)
10873
+ args[1] || (serializeArg ? import_compiler57.types.numericLiteral(0) : void 0),
10874
+ serializeArg ? import_compiler57.types.numericLiteral(0) : void 0,
10875
+ serializeArg
10619
10876
  );
10620
10877
  if (node.var) {
10621
10878
  const dynamicScopeIdentifier = generateUidIdentifier(