marko 6.0.2 → 6.0.4

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.
@@ -1539,7 +1539,7 @@ function forceSectionSerialize(section, prop) {
1539
1539
  forceSerializeKey(section, getSectionPropSerializeReasonKey(section, prop));
1540
1540
  } else if (section.serializeReason !== true) {
1541
1541
  reasonExprs.delete(section);
1542
- section.serializeReason = true;
1542
+ setSectionSerializeReason(section, true);
1543
1543
  }
1544
1544
  }
1545
1545
  function forceBindingSerialize(section, binding, prefix2) {
@@ -1547,7 +1547,7 @@ function forceBindingSerialize(section, binding, prefix2) {
1547
1547
  }
1548
1548
  function forceSerializeKey(section, key) {
1549
1549
  if (section.serializeReasons.get(key) !== true) {
1550
- section.serializeReasons.set(key, true);
1550
+ setSectionKeyedSerializeReason(section, key, true);
1551
1551
  keyedReasonExprs.get(section)?.delete(key);
1552
1552
  }
1553
1553
  }
@@ -1616,9 +1616,9 @@ function addSectionSerializeReasonRef(section, ref, prop) {
1616
1616
  if (reason === true) {
1617
1617
  forceSectionSerialize(section);
1618
1618
  } else {
1619
- section.serializeReason = mergeSerializeReasons(
1620
- existingReason,
1621
- reason
1619
+ setSectionSerializeReason(
1620
+ section,
1621
+ mergeSerializeReasons(existingReason, reason)
1622
1622
  );
1623
1623
  }
1624
1624
  }
@@ -1636,7 +1636,8 @@ function addKeyedSerializeReasonRef(section, key, ref) {
1636
1636
  if (reason === true) {
1637
1637
  forceSerializeKey(section, key);
1638
1638
  } else {
1639
- section.serializeReasons.set(
1639
+ setSectionKeyedSerializeReason(
1640
+ section,
1640
1641
  key,
1641
1642
  mergeSerializeReasons(existingReason, reason)
1642
1643
  );
@@ -1658,9 +1659,9 @@ function addSectionSerializeReason(section, reason, prop) {
1658
1659
  if (reason === true) {
1659
1660
  forceSectionSerialize(section);
1660
1661
  } else {
1661
- section.serializeReason = mergeSerializeReasons(
1662
- existingReason,
1663
- reason
1662
+ setSectionSerializeReason(
1663
+ section,
1664
+ mergeSerializeReasons(existingReason, reason)
1664
1665
  );
1665
1666
  }
1666
1667
  }
@@ -1682,7 +1683,8 @@ function addKeyedSerializeReason(section, key, reason) {
1682
1683
  if (reason === true) {
1683
1684
  forceSerializeKey(section, key);
1684
1685
  } else {
1685
- section.serializeReasons.set(
1686
+ setSectionKeyedSerializeReason(
1687
+ section,
1686
1688
  key,
1687
1689
  mergeSerializeReasons(existingReason, reason)
1688
1690
  );
@@ -1730,19 +1732,23 @@ function applySerializeReasonExprs(section) {
1730
1732
  if (keyedExprs) {
1731
1733
  keyedReasonExprs.delete(section);
1732
1734
  for (const [key, exprs] of keyedExprs) {
1733
- const reason = getSerializeSourcesForExprs(exprs);
1734
- if (reason) {
1735
- section.serializeReasons.set(
1735
+ const reason2 = getSerializeSourcesForExprs(exprs);
1736
+ if (reason2) {
1737
+ setSectionKeyedSerializeReason(
1738
+ section,
1736
1739
  key,
1737
- mergeSerializeReasons(section.serializeReasons.get(key), reason)
1740
+ mergeSerializeReasons(section.serializeReasons.get(key), reason2)
1738
1741
  );
1739
1742
  }
1740
1743
  }
1741
1744
  }
1742
- section.serializeReason = mergeSerializeReasons(
1743
- section.serializeReason,
1744
- getSerializeSourcesForExprs(reasonExprs.get(section))
1745
- );
1745
+ const reason = getSerializeSourcesForExprs(reasonExprs.get(section));
1746
+ if (reason) {
1747
+ setSectionSerializeReason(
1748
+ section,
1749
+ mergeSerializeReasons(section.serializeReason, reason)
1750
+ );
1751
+ }
1746
1752
  reasonExprs.delete(section);
1747
1753
  }
1748
1754
  function finalizeSectionSerializeReasons(section) {
@@ -1755,7 +1761,7 @@ function finalizeSectionSerializeReasons(section) {
1755
1761
  }
1756
1762
  reason = mergeSerializeReasons(reason, keyedReason);
1757
1763
  }
1758
- section.serializeReason = reason;
1764
+ setSectionSerializeReason(section, reason);
1759
1765
  }
1760
1766
  }
1761
1767
  function getSerializeSourcesForExpr(expr) {
@@ -1799,6 +1805,12 @@ function mergeSerializeReasons(a, b) {
1799
1805
  if (a === true || b === true) return true;
1800
1806
  return bindingUtil.union(a, b);
1801
1807
  }
1808
+ function setSectionSerializeReason(section, reason) {
1809
+ section.serializeReason = reason;
1810
+ }
1811
+ function setSectionKeyedSerializeReason(section, key, reason) {
1812
+ section.serializeReasons.set(key, reason);
1813
+ }
1802
1814
 
1803
1815
  // src/translator/util/state.ts
1804
1816
  var import_babel_utils9 = require("@marko/compiler/babel-utils");
@@ -2360,7 +2372,7 @@ function getExprIfSerialized(reason, expr) {
2360
2372
  ) : void 0;
2361
2373
  }
2362
2374
  function getSerializeGuard(reason) {
2363
- return reason ? reason === true ? import_compiler13.types.numericLiteral(1) : callRuntime(
2375
+ return callRuntime(
2364
2376
  "serializeGuard",
2365
2377
  import_compiler13.types.identifier(getSharedUid("serialize")),
2366
2378
  import_compiler13.types.numericLiteral(
@@ -2369,7 +2381,7 @@ function getSerializeGuard(reason) {
2369
2381
  reason
2370
2382
  )
2371
2383
  )
2372
- ) : void 0;
2384
+ );
2373
2385
  }
2374
2386
  var html_default = {
2375
2387
  translate: {
@@ -4316,6 +4328,7 @@ function withPreviousLocation(newNode, originalNode) {
4316
4328
 
4317
4329
  // src/translator/util/references.ts
4318
4330
  var kIsInvoked = Symbol("hoist is invoked");
4331
+ var kBranchSerializeReason = Symbol("branch serialize reason");
4319
4332
  var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
4320
4333
  var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
4321
4334
  function createBinding(name2, type, section, upstreamAlias, property, loc = null, declared = false) {
@@ -4768,8 +4781,16 @@ function finalizeReferences() {
4768
4781
  );
4769
4782
  });
4770
4783
  if (section.parent && section.isBranch && section.sectionAccessor && section.upstreamExpression) {
4771
- addSectionSerializeReasonRef(section, getDirectClosures(section));
4772
- addSectionSerializeReasonExpr(section, section.upstreamExpression);
4784
+ addSectionSerializeReasonRef(
4785
+ section,
4786
+ !!(section.isHoistThrough || section.hoisted) || getDirectClosures(section),
4787
+ kBranchSerializeReason
4788
+ );
4789
+ addSectionSerializeReasonExpr(
4790
+ section,
4791
+ section.upstreamExpression,
4792
+ kBranchSerializeReason
4793
+ );
4773
4794
  addBindingSerializeReasonExpr(
4774
4795
  section.parent,
4775
4796
  section.sectionAccessor.binding,
@@ -5783,6 +5804,9 @@ var native_tag_default = {
5783
5804
  relatedControllable.attrs.map((it) => it?.value)
5784
5805
  );
5785
5806
  }
5807
+ if (hasEventHandlers || spreadReferenceNodes) {
5808
+ forceBindingSerialize(tagSection, nodeBinding);
5809
+ }
5786
5810
  if (node.var) {
5787
5811
  forceBindingSerialize(tagSection, nodeBinding);
5788
5812
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
@@ -5794,8 +5818,8 @@ var native_tag_default = {
5794
5818
  tagSection,
5795
5819
  getAccessorProp().Owner
5796
5820
  );
5797
- if (!isInvokedFunction(ref)) {
5798
- tagExtra[kGetterId] ||= getRegisterUID(
5821
+ if (!tagExtra[kGetterId] && !isInvokedFunction(ref)) {
5822
+ tagExtra[kGetterId] = getRegisterUID(
5799
5823
  tagSection,
5800
5824
  nodeBinding.name
5801
5825
  );
@@ -5807,15 +5831,12 @@ var native_tag_default = {
5807
5831
  );
5808
5832
  }
5809
5833
  }
5810
- } else if (hasEventHandlers || spreadReferenceNodes) {
5811
- forceBindingSerialize(tagSection, nodeBinding);
5812
- } else {
5813
- addBindingSerializeReasonExpr(
5814
- tagSection,
5815
- nodeBinding,
5816
- push(attrExprExtras, tagExtra)
5817
- );
5818
5834
  }
5835
+ addBindingSerializeReasonExpr(
5836
+ tagSection,
5837
+ nodeBinding,
5838
+ push(attrExprExtras, tagExtra)
5839
+ );
5819
5840
  }
5820
5841
  }
5821
5842
  },
@@ -6385,14 +6406,14 @@ var for_default = {
6385
6406
  const statements = [];
6386
6407
  const bodyStatements = node.body.body;
6387
6408
  const singleNodeOptimization = bodySection.content === null || bodySection.content.singleChild && bodySection.content.startType !== 4 /* Text */;
6388
- const branchSerializeReason = getSectionSerializeReason(bodySection);
6409
+ const branchSerializeReason = getSectionSerializeReason(
6410
+ bodySection,
6411
+ kBranchSerializeReason
6412
+ );
6389
6413
  const markerSerializeReason = getBindingSerializeReason(
6390
6414
  tagSection,
6391
6415
  nodeBinding
6392
6416
  );
6393
- if (markerSerializeReason && onlyChildInParentOptimization) {
6394
- getParentTag(tag).node.extra[kSkipMark] = true;
6395
- }
6396
6417
  flushInto(tag);
6397
6418
  writeHTMLResumeStatements(tagBody);
6398
6419
  const forTagArgs = getBaseArgsInForTag(forType, forAttrs);
@@ -6401,18 +6422,15 @@ var for_default = {
6401
6422
  import_compiler33.types.arrowFunctionExpression(params, import_compiler33.types.blockStatement(bodyStatements))
6402
6423
  );
6403
6424
  if (branchSerializeReason) {
6425
+ if (markerSerializeReason && onlyChildInParentOptimization) {
6426
+ getParentTag(tag).node.extra[kSkipMark] = true;
6427
+ }
6404
6428
  forTagArgs.push(
6405
6429
  forAttrs.by || import_compiler33.types.numericLiteral(0),
6406
6430
  getScopeIdIdentifier(tagSection),
6407
6431
  getScopeAccessorLiteral(nodeBinding),
6408
- branchSerializeReason !== true && markerSerializeReason && markerSerializeReason !== true && !bindingUtil.isSuperset(
6409
- branchSerializeReason,
6410
- markerSerializeReason
6411
- ) ? import_compiler33.types.logicalExpression(
6412
- "||",
6413
- getSerializeGuard(branchSerializeReason),
6414
- getSerializeGuard(markerSerializeReason)
6415
- ) : getSerializeGuard(branchSerializeReason)
6432
+ branchSerializeReason === true ? markerSerializeReason === true && !onlyChildInParentOptimization ? void 0 : import_compiler33.types.numericLiteral(1) : getSerializeGuard(branchSerializeReason),
6433
+ !markerSerializeReason ? import_compiler33.types.numericLiteral(0) : markerSerializeReason === true ? onlyChildInParentOptimization ? import_compiler33.types.numericLiteral(1) : void 0 : getSerializeGuard(markerSerializeReason)
6416
6434
  );
6417
6435
  if (onlyChildInParentOptimization) {
6418
6436
  forTagArgs.push(import_compiler33.types.numericLiteral(1));
@@ -7371,6 +7389,9 @@ var html_script_default = {
7371
7389
  bodyPlaceholderNodes.slice(1)
7372
7390
  );
7373
7391
  }
7392
+ if (hasEventHandlers || spreadReferenceNodes) {
7393
+ forceBindingSerialize(tagSection, nodeBinding);
7394
+ }
7374
7395
  if (node.var) {
7375
7396
  forceBindingSerialize(tagSection, nodeBinding);
7376
7397
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
@@ -7389,15 +7410,12 @@ var html_script_default = {
7389
7410
  trackHoistedReference(ref, nodeBinding);
7390
7411
  }
7391
7412
  }
7392
- } else if (hasEventHandlers || spreadReferenceNodes) {
7393
- forceBindingSerialize(tagSection, nodeBinding);
7394
- } else {
7395
- addBindingSerializeReasonExpr(
7396
- tagSection,
7397
- nodeBinding,
7398
- push(attrExprExtras, tagExtra)
7399
- );
7400
7413
  }
7414
+ addBindingSerializeReasonExpr(
7415
+ tagSection,
7416
+ nodeBinding,
7417
+ push(attrExprExtras, tagExtra)
7418
+ );
7401
7419
  }
7402
7420
  },
7403
7421
  translate: {
@@ -7783,6 +7801,9 @@ var html_style_default = {
7783
7801
  bodyPlaceholderNodes.slice(1)
7784
7802
  );
7785
7803
  }
7804
+ if (hasEventHandlers || spreadReferenceNodes) {
7805
+ forceBindingSerialize(tagSection, nodeBinding);
7806
+ }
7786
7807
  if (node.var) {
7787
7808
  forceBindingSerialize(tagSection, nodeBinding);
7788
7809
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
@@ -7801,15 +7822,12 @@ var html_style_default = {
7801
7822
  trackHoistedReference(ref, nodeBinding);
7802
7823
  }
7803
7824
  }
7804
- } else if (hasEventHandlers || spreadReferenceNodes) {
7805
- forceBindingSerialize(tagSection, nodeBinding);
7806
- } else {
7807
- addBindingSerializeReasonExpr(
7808
- tagSection,
7809
- nodeBinding,
7810
- push(attrExprExtras, tagExtra)
7811
- );
7812
7825
  }
7826
+ addBindingSerializeReasonExpr(
7827
+ tagSection,
7828
+ nodeBinding,
7829
+ push(attrExprExtras, tagExtra)
7830
+ );
7813
7831
  }
7814
7832
  },
7815
7833
  translate: {
@@ -8255,14 +8273,14 @@ var IfTag = {
8255
8273
  const nextTag = tag.getNextSibling();
8256
8274
  let branchSerializeReasons;
8257
8275
  let statement;
8258
- if (markerSerializeReason && onlyChildInParentOptimization) {
8259
- getParentTag(ifTag).node.extra[kSkipMark] = true;
8260
- }
8261
8276
  for (let i = branches.length; i--; ) {
8262
8277
  const [branchTag, branchBody] = branches[i];
8263
8278
  const bodyStatements = branchTag.node.body.body;
8264
8279
  if (branchBody) {
8265
- const branchSerializeReason = getSectionSerializeReason(branchBody);
8280
+ const branchSerializeReason = getSectionSerializeReason(
8281
+ branchBody,
8282
+ kBranchSerializeReason
8283
+ );
8266
8284
  if (branchSerializeReason) {
8267
8285
  if (branchSerializeReasons !== true) {
8268
8286
  if (branchSerializeReason === true) {
@@ -8296,7 +8314,9 @@ var IfTag = {
8296
8314
  branchTag.remove();
8297
8315
  }
8298
8316
  if (branchSerializeReasons) {
8299
- const branchSerializeExpr = branchSerializeReasons === true ? !onlyChildInParentOptimization && !markerSerializeReason ? void 0 : getSerializeGuard(branchSerializeReasons) : getSerializeGuardForAny(branchSerializeReasons);
8317
+ if (onlyChildInParentOptimization && markerSerializeReason) {
8318
+ getParentTag(ifTag).node.extra[kSkipMark] = true;
8319
+ }
8300
8320
  const cbNode = import_compiler42.types.arrowFunctionExpression(
8301
8321
  [],
8302
8322
  import_compiler42.types.blockStatement([statement])
@@ -8307,16 +8327,16 @@ var IfTag = {
8307
8327
  cbNode,
8308
8328
  getScopeIdIdentifier(ifTagSection),
8309
8329
  getScopeAccessorLiteral(nodeBinding),
8310
- branchSerializeExpr,
8311
- markerSerializeReason ? getSerializeGuard(markerSerializeReason) : onlyChildInParentOptimization ? import_compiler42.types.numericLiteral(0) : void 0,
8330
+ branchSerializeReasons === true ? markerSerializeReason === true && !onlyChildInParentOptimization ? void 0 : import_compiler42.types.numericLiteral(1) : getSerializeGuardForAny(branchSerializeReasons),
8331
+ !markerSerializeReason ? import_compiler42.types.numericLiteral(0) : markerSerializeReason === true ? onlyChildInParentOptimization ? import_compiler42.types.numericLiteral(1) : void 0 : getSerializeGuard(markerSerializeReason),
8312
8332
  onlyChildInParentOptimization && import_compiler42.types.numericLiteral(1)
8313
8333
  ) : callRuntime(
8314
8334
  "resumeConditional",
8315
8335
  cbNode,
8316
8336
  getScopeIdIdentifier(ifTagSection),
8317
8337
  getScopeAccessorLiteral(nodeBinding),
8318
- branchSerializeExpr,
8319
- getSerializeGuard(markerSerializeReason)
8338
+ branchSerializeReasons === true ? markerSerializeReason === true ? void 0 : import_compiler42.types.numericLiteral(1) : getSerializeGuardForAny(branchSerializeReasons),
8339
+ !markerSerializeReason ? import_compiler42.types.numericLiteral(0) : markerSerializeReason === true ? void 0 : getSerializeGuard(markerSerializeReason)
8320
8340
  )
8321
8341
  );
8322
8342
  }
@@ -9834,13 +9854,12 @@ function translateHTML(tag) {
9834
9854
  let childSerializeReasonExpr;
9835
9855
  if (childSerializeReasonIds) {
9836
9856
  if (childSerializeReasonIds.length === 1) {
9837
- childSerializeReasonExpr = getSerializeGuard(
9838
- getBindingSerializeReason(
9839
- section,
9840
- childScopeBinding,
9841
- childSerializeReasonIds[0]
9842
- )
9857
+ const reason = getBindingSerializeReason(
9858
+ section,
9859
+ childScopeBinding,
9860
+ childSerializeReasonIds[0]
9843
9861
  );
9862
+ childSerializeReasonExpr = !reason ? void 0 : reason == true ? import_compiler56.types.numericLiteral(1) : getSerializeGuard(reason);
9844
9863
  } else {
9845
9864
  const props = [];
9846
9865
  let hasDynamicReasons = false;
@@ -9854,7 +9873,10 @@ function translateHTML(tag) {
9854
9873
  if (reason) {
9855
9874
  hasDynamicReasons ||= reason !== true;
9856
9875
  props.push(
9857
- import_compiler56.types.objectProperty(import_compiler56.types.numericLiteral(i), getSerializeGuard(reason))
9876
+ import_compiler56.types.objectProperty(
9877
+ import_compiler56.types.numericLiteral(i),
9878
+ reason === true ? import_compiler56.types.numericLiteral(1) : getSerializeGuard(reason)
9879
+ )
9858
9880
  );
9859
9881
  } else {
9860
9882
  hasSkippedReasons = true;
@@ -10598,6 +10620,7 @@ var dynamic_tag_default = {
10598
10620
  tagSection,
10599
10621
  nodeBinding
10600
10622
  );
10623
+ const serializeArg = !serializeReason ? import_compiler57.types.numericLiteral(0) : serializeReason === true ? void 0 : getSerializeGuard(serializeReason);
10601
10624
  const dynamicTagExpr = hasTagArgs ? callRuntime(
10602
10625
  "dynamicTag",
10603
10626
  getScopeIdIdentifier(tagSection),
@@ -10606,16 +10629,16 @@ var dynamic_tag_default = {
10606
10629
  import_compiler57.types.arrayExpression(args),
10607
10630
  import_compiler57.types.numericLiteral(0),
10608
10631
  import_compiler57.types.numericLiteral(1),
10609
- getSerializeGuard(serializeReason)
10632
+ serializeArg
10610
10633
  ) : callRuntime(
10611
10634
  "dynamicTag",
10612
10635
  getScopeIdIdentifier(tagSection),
10613
10636
  getScopeAccessorLiteral(nodeBinding),
10614
10637
  tagExpression,
10615
10638
  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)
10639
+ args[1] || (serializeArg ? import_compiler57.types.numericLiteral(0) : void 0),
10640
+ serializeArg ? import_compiler57.types.numericLiteral(0) : void 0,
10641
+ serializeArg
10619
10642
  );
10620
10643
  if (node.var) {
10621
10644
  const dynamicScopeIdentifier = generateUidIdentifier(
@@ -3,6 +3,7 @@ import { type Many, type OneMany, type Opt, Sorted } from "./optional";
3
3
  import { type Section } from "./sections";
4
4
  import { type SerializeReason } from "./serialize-reasons";
5
5
  declare const kIsInvoked: unique symbol;
6
+ export declare const kBranchSerializeReason: unique symbol;
6
7
  export type Aliases = undefined | Binding | {
7
8
  [property: string]: Aliases;
8
9
  };
@@ -2,7 +2,7 @@ import { types as t } from "@marko/compiler";
2
2
  import type { DynamicSerializeReason } from "../../util/serialize-reasons";
3
3
  export declare function getTemplateContentName(): string;
4
4
  export declare function getExprIfSerialized<T extends undefined | boolean | DynamicSerializeReason, U extends t.Expression>(reason: T, expr: U): T extends {} ? U : undefined;
5
- export declare function getSerializeGuard<T extends undefined | boolean | DynamicSerializeReason>(reason: T): T extends {} ? t.Expression : undefined;
5
+ export declare function getSerializeGuard(reason: DynamicSerializeReason): t.CallExpression;
6
6
  declare const _default: {
7
7
  translate: {
8
8
  exit(this: unknown, program: t.NodePath<t.Program>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.2",
3
+ "version": "6.0.4",
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.18",
51
+ "@marko/compiler": "^5.39.19",
52
52
  "csstype": "^3.1.3",
53
53
  "magic-string": "^0.30.17"
54
54
  },