marko 6.0.145 → 6.0.147

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.
package/dist/html.js CHANGED
@@ -1775,8 +1775,8 @@ function _attr_style(value) {
1775
1775
  return stringAttr("style", styleValue(value));
1776
1776
  }
1777
1777
  function _attr_option_value(value) {
1778
- let selectedValue = getContext(kSelectedValue);
1779
- return _attr("value", value) + (!isVoid(value) && (Array.isArray(selectedValue) ? selectedValue.includes(value) : selectedValue === value) ? " selected" : "");
1778
+ let valueAttr = _attr("value", value);
1779
+ return normalizedValueMatches(getContext(kSelectedValue), value) ? valueAttr + " selected" : valueAttr;
1780
1780
  }
1781
1781
  var kSelectedValue = /* @__PURE__ */ Symbol("selectedValue");
1782
1782
  function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content) {
@@ -1784,7 +1784,7 @@ function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content)
1784
1784
  3 /* SelectValue */,
1785
1785
  scopeId,
1786
1786
  nodeAccessor,
1787
- value,
1787
+ void 0,
1788
1788
  valueChange
1789
1789
  ), content && withContext(kSelectedValue, value, content);
1790
1790
  }
@@ -1813,26 +1813,34 @@ function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange) {
1813
1813
  nodeAccessor,
1814
1814
  void 0,
1815
1815
  checkedChange
1816
- ), _attr("checked", checked);
1816
+ ), normalizeBoolAttrValue(checked) ? " checked" : "";
1817
1817
  }
1818
1818
  function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value) {
1819
- let multiple = Array.isArray(checkedValue), valueAttr = _attr("value", value);
1819
+ let valueAttr = _attr("value", value);
1820
1820
  return checkedValueChange && writeControlledScope(
1821
1821
  1 /* InputCheckedValue */,
1822
1822
  scopeId,
1823
1823
  nodeAccessor,
1824
- checkedValue,
1824
+ getCheckedValueRef(checkedValue),
1825
1825
  checkedValueChange
1826
- ), (multiple ? checkedValue.includes(value) : checkedValue === value) ? valueAttr + " checked" : valueAttr;
1826
+ ), normalizedValueMatches(checkedValue, value) ? valueAttr + " checked" : valueAttr;
1827
+ }
1828
+ var checkedValuesRefs = /* @__PURE__ */ new WeakMap();
1829
+ function getCheckedValueRef(checkedValue) {
1830
+ if (Array.isArray(checkedValue)) {
1831
+ let ref = checkedValuesRefs.get(checkedValue);
1832
+ return ref || (ref = [], checkedValuesRefs.set(checkedValue, ref)), ref;
1833
+ }
1827
1834
  }
1828
1835
  function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange) {
1836
+ let normalizedOpen = normalizeBoolAttrValue(open);
1829
1837
  return openChange && writeControlledScope(
1830
1838
  4 /* DetailsOrDialogOpen */,
1831
1839
  scopeId,
1832
1840
  nodeAccessor,
1833
- open,
1841
+ normalizedOpen,
1834
1842
  openChange
1835
- ), _attr("open", open);
1843
+ ), normalizedOpen ? " open" : "";
1836
1844
  }
1837
1845
  function _attr_nonce() {
1838
1846
  return getChunk().boundary.state.nonceAttr;
@@ -1966,6 +1974,23 @@ function escapeDoubleQuotedAttrValue(value) {
1966
1974
  function replaceUnsafeDoubleQuoteAttrChar(match) {
1967
1975
  return match === '"' ? """ : "&";
1968
1976
  }
1977
+ function normalizedValueMatches(a, b) {
1978
+ let value = normalizeStrAttrValue(b);
1979
+ if (Array.isArray(a)) {
1980
+ for (let item of a)
1981
+ if (normalizeStrAttrValue(item) === value)
1982
+ return !0;
1983
+ } else if (normalizeStrAttrValue(a) === value)
1984
+ return !0;
1985
+ return !1;
1986
+ }
1987
+ function normalizeStrAttrValue(value) {
1988
+ return value && value !== !0 || value === 0 ? value + "" : "";
1989
+ }
1990
+ function normalizeBoolAttrValue(value) {
1991
+ if (value != null && value !== !1)
1992
+ return !0;
1993
+ }
1969
1994
 
1970
1995
  // src/common/compat-meta.ts
1971
1996
  var RENDERER_REGISTER_ID = "$C_r", SET_SCOPE_REGISTER_ID = "$C_s", RENDER_BODY_ID = "$C_b";
package/dist/html.mjs CHANGED
@@ -1685,8 +1685,8 @@ function _attr_style(value) {
1685
1685
  return stringAttr("style", styleValue(value));
1686
1686
  }
1687
1687
  function _attr_option_value(value) {
1688
- let selectedValue = getContext(kSelectedValue);
1689
- return _attr("value", value) + (!isVoid(value) && (Array.isArray(selectedValue) ? selectedValue.includes(value) : selectedValue === value) ? " selected" : "");
1688
+ let valueAttr = _attr("value", value);
1689
+ return normalizedValueMatches(getContext(kSelectedValue), value) ? valueAttr + " selected" : valueAttr;
1690
1690
  }
1691
1691
  var kSelectedValue = /* @__PURE__ */ Symbol("selectedValue");
1692
1692
  function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content) {
@@ -1694,7 +1694,7 @@ function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content)
1694
1694
  3 /* SelectValue */,
1695
1695
  scopeId,
1696
1696
  nodeAccessor,
1697
- value,
1697
+ void 0,
1698
1698
  valueChange
1699
1699
  ), content && withContext(kSelectedValue, value, content);
1700
1700
  }
@@ -1723,26 +1723,34 @@ function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange) {
1723
1723
  nodeAccessor,
1724
1724
  void 0,
1725
1725
  checkedChange
1726
- ), _attr("checked", checked);
1726
+ ), normalizeBoolAttrValue(checked) ? " checked" : "";
1727
1727
  }
1728
1728
  function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value) {
1729
- let multiple = Array.isArray(checkedValue), valueAttr = _attr("value", value);
1729
+ let valueAttr = _attr("value", value);
1730
1730
  return checkedValueChange && writeControlledScope(
1731
1731
  1 /* InputCheckedValue */,
1732
1732
  scopeId,
1733
1733
  nodeAccessor,
1734
- checkedValue,
1734
+ getCheckedValueRef(checkedValue),
1735
1735
  checkedValueChange
1736
- ), (multiple ? checkedValue.includes(value) : checkedValue === value) ? valueAttr + " checked" : valueAttr;
1736
+ ), normalizedValueMatches(checkedValue, value) ? valueAttr + " checked" : valueAttr;
1737
+ }
1738
+ var checkedValuesRefs = /* @__PURE__ */ new WeakMap();
1739
+ function getCheckedValueRef(checkedValue) {
1740
+ if (Array.isArray(checkedValue)) {
1741
+ let ref = checkedValuesRefs.get(checkedValue);
1742
+ return ref || (ref = [], checkedValuesRefs.set(checkedValue, ref)), ref;
1743
+ }
1737
1744
  }
1738
1745
  function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange) {
1746
+ let normalizedOpen = normalizeBoolAttrValue(open);
1739
1747
  return openChange && writeControlledScope(
1740
1748
  4 /* DetailsOrDialogOpen */,
1741
1749
  scopeId,
1742
1750
  nodeAccessor,
1743
- open,
1751
+ normalizedOpen,
1744
1752
  openChange
1745
- ), _attr("open", open);
1753
+ ), normalizedOpen ? " open" : "";
1746
1754
  }
1747
1755
  function _attr_nonce() {
1748
1756
  return getChunk().boundary.state.nonceAttr;
@@ -1876,6 +1884,23 @@ function escapeDoubleQuotedAttrValue(value) {
1876
1884
  function replaceUnsafeDoubleQuoteAttrChar(match) {
1877
1885
  return match === '"' ? """ : "&";
1878
1886
  }
1887
+ function normalizedValueMatches(a, b) {
1888
+ let value = normalizeStrAttrValue(b);
1889
+ if (Array.isArray(a)) {
1890
+ for (let item of a)
1891
+ if (normalizeStrAttrValue(item) === value)
1892
+ return !0;
1893
+ } else if (normalizeStrAttrValue(a) === value)
1894
+ return !0;
1895
+ return !1;
1896
+ }
1897
+ function normalizeStrAttrValue(value) {
1898
+ return value && value !== !0 || value === 0 ? value + "" : "";
1899
+ }
1900
+ function normalizeBoolAttrValue(value) {
1901
+ if (value != null && value !== !1)
1902
+ return !0;
1903
+ }
1879
1904
 
1880
1905
  // src/common/compat-meta.ts
1881
1906
  var RENDERER_REGISTER_ID = "$C_r", SET_SCOPE_REGISTER_ID = "$C_s", RENDER_BODY_ID = "$C_b";
@@ -5597,7 +5597,7 @@ var native_tag_default = {
5597
5597
  if (injectNonce && attr.name === "nonce") {
5598
5598
  injectNonce = false;
5599
5599
  }
5600
- if (isEventHandler(attr.name) || isNativeTagChangeHandler(attr.name)) {
5600
+ if (isEventHandler(attr.name)) {
5601
5601
  valueExtra.isEffect = true;
5602
5602
  hasEventHandlers = true;
5603
5603
  } else if (!evaluate(attr.value).confident) {
@@ -5633,7 +5633,7 @@ var native_tag_default = {
5633
5633
  }
5634
5634
  }
5635
5635
  }
5636
- if (node.var || hasDynamicAttributes || hasEventHandlers || textPlaceholders || injectNonce || getRelatedControllable(tagName, seen)?.special) {
5636
+ if (node.var || hasDynamicAttributes || hasEventHandlers || textPlaceholders || injectNonce || isDynamicControllable(getRelatedControllable(tagName, seen))) {
5637
5637
  const tagExtra = node.extra ??= {};
5638
5638
  const tagSection = getOrCreateSection(tag);
5639
5639
  const nodeBinding = tagExtra[kNativeTagBinding] = createBinding(
@@ -5713,6 +5713,7 @@ var native_tag_default = {
5713
5713
  write`${callRuntime("_attr_nonce")}`;
5714
5714
  }
5715
5715
  if (staticControllable) {
5716
+ const hasChangeHandler = !!staticControllable.attrs[1];
5716
5717
  if (tagName !== "select" && tagName !== "textarea") {
5717
5718
  write`${callRuntime(
5718
5719
  staticControllable.helper,
@@ -5721,7 +5722,7 @@ var native_tag_default = {
5721
5722
  ...staticControllable.attrs.map((attr) => attr?.value)
5722
5723
  )}`;
5723
5724
  }
5724
- if (!(staticControllable.special && !staticControllable.attrs[1])) {
5725
+ if (hasChangeHandler) {
5725
5726
  addHTMLEffectCall(tagSection, void 0);
5726
5727
  }
5727
5728
  }
@@ -6002,25 +6003,34 @@ var native_tag_default = {
6002
6003
  );
6003
6004
  }
6004
6005
  if (staticControllable) {
6005
- const { helper, attrs } = staticControllable;
6006
- const firstAttr = attrs.find(Boolean);
6006
+ const hasChangeHandler = !!staticControllable.attrs[1];
6007
+ const firstAttr = staticControllable.attrs.find(Boolean);
6007
6008
  const referencedBindings = firstAttr.value.extra?.referencedBindings;
6008
- const values = attrs.map((attr) => attr?.value);
6009
+ const values = (hasChangeHandler ? staticControllable.attrs : staticControllable.attrs.toSpliced(1, 1)).map((attr) => attr?.value);
6009
6010
  addStatement(
6010
6011
  "render",
6011
6012
  tagSection,
6012
6013
  referencedBindings,
6013
6014
  import_compiler32.types.expressionStatement(
6014
- callRuntime(helper, scopeIdentifier, visitAccessor, ...values)
6015
+ callRuntime(
6016
+ hasChangeHandler ? staticControllable.helper : `${staticControllable.helper}_default`,
6017
+ scopeIdentifier,
6018
+ visitAccessor,
6019
+ ...values
6020
+ )
6015
6021
  )
6016
6022
  );
6017
- if (!(staticControllable.special && !attrs[1])) {
6023
+ if (hasChangeHandler) {
6018
6024
  addStatement(
6019
6025
  "effect",
6020
6026
  tagSection,
6021
6027
  void 0,
6022
6028
  import_compiler32.types.expressionStatement(
6023
- callRuntime(`${helper}_script`, scopeIdentifier, visitAccessor)
6029
+ callRuntime(
6030
+ `${staticControllable.helper}_script`,
6031
+ scopeIdentifier,
6032
+ visitAccessor
6033
+ )
6024
6034
  )
6025
6035
  );
6026
6036
  }
@@ -6345,7 +6355,7 @@ function getUsedAttrs(tagName, tag) {
6345
6355
  }
6346
6356
  if (!spreadProps) {
6347
6357
  staticControllable = getRelatedControllable(tagName, seen);
6348
- if (staticControllable?.special === false && !staticControllable.attrs[1]) {
6358
+ if (!isDynamicControllable(staticControllable)) {
6349
6359
  staticControllable = void 0;
6350
6360
  }
6351
6361
  }
@@ -6491,7 +6501,7 @@ function trackDelimitedAttrObjectProperties(obj, meta) {
6491
6501
  key = prop.key.name;
6492
6502
  } else {
6493
6503
  const keyEval = evaluate(prop.key);
6494
- if (keyEval.confident) {
6504
+ if (keyEval.confident && typeof keyEval.computed === "string" && !/\s/.test(keyEval.computed)) {
6495
6505
  key = keyEval.computed + "";
6496
6506
  } else {
6497
6507
  (dynamicProps ||= []).push(prop);
@@ -6513,8 +6523,11 @@ function trackDelimitedAttrObjectProperties(obj, meta) {
6513
6523
  (meta.dynamicItems ||= []).push(import_compiler32.types.objectExpression(dynamicProps));
6514
6524
  }
6515
6525
  }
6516
- function isNativeTagChangeHandler(propName) {
6517
- return /^(?:value|checked(?:Value)?|open)Change$/.test(propName);
6526
+ function isDynamicControllable(controllable) {
6527
+ if (controllable) {
6528
+ return controllable.special || !!(controllable.attrs[1] || controllable.attrs.find(Boolean).value.extra?.referencedBindings);
6529
+ }
6530
+ return false;
6518
6531
  }
6519
6532
  function buildUndefined2() {
6520
6533
  return import_compiler32.types.unaryExpression("void", import_compiler32.types.numericLiteral(0));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.145",
3
+ "version": "6.0.147",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -48,7 +48,7 @@
48
48
  "build": "node -r ~ts ./scripts/bundle.ts"
49
49
  },
50
50
  "dependencies": {
51
- "@marko/compiler": "^5.39.53",
51
+ "@marko/compiler": "^5.39.56",
52
52
  "csstype": "^3.2.3",
53
53
  "magic-string": "^0.30.21"
54
54
  },
package/tags/id.d.marko CHANGED
@@ -1,7 +1,7 @@
1
1
  /** File for types only, not actual implementation **/
2
2
 
3
3
  export interface Input {
4
- value?: string;
4
+ value?: string | null | false;
5
5
  }
6
6
 
7
7
  return="" as string