marko 6.3.39 → 6.3.40

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 (52) hide show
  1. package/dist/common/meta.d.ts +1 -0
  2. package/dist/debug/dom/catch.feat.js +1 -1
  3. package/dist/debug/dom/catch.feat.mjs +1 -1
  4. package/dist/debug/dom/controllable-input.feat.js +1 -1
  5. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  6. package/dist/debug/dom/controllable-open.feat.js +1 -1
  7. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  8. package/dist/debug/dom/controllable-select.feat.js +1 -1
  9. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  10. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  11. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  12. package/dist/debug/dom/controllable.feat.js +1 -1
  13. package/dist/debug/dom/controllable.feat.mjs +1 -1
  14. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  15. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  16. package/dist/debug/dom/placeholder.feat.js +10 -0
  17. package/dist/debug/dom/placeholder.feat.mjs +9 -0
  18. package/dist/debug/{dom-woc_wRhN.mjs → dom-BREcRn0h.mjs} +2 -1
  19. package/dist/debug/{dom-BkYlHM4b.js → dom-Kmuzoe8t.js} +19 -0
  20. package/dist/debug/dom.js +1 -1
  21. package/dist/debug/dom.mjs +1 -1
  22. package/dist/debug/html.js +30 -14
  23. package/dist/debug/html.mjs +30 -14
  24. package/dist/dom/catch.feat.js +3 -3
  25. package/dist/dom/catch.feat.mjs +1 -1
  26. package/dist/dom/controllable-input.feat.js +1 -1
  27. package/dist/dom/controllable-input.feat.mjs +1 -1
  28. package/dist/dom/controllable-open.feat.js +1 -1
  29. package/dist/dom/controllable-open.feat.mjs +1 -1
  30. package/dist/dom/controllable-select.feat.js +1 -1
  31. package/dist/dom/controllable-select.feat.mjs +1 -1
  32. package/dist/dom/controllable-textarea.feat.js +1 -1
  33. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  34. package/dist/dom/controllable.feat.js +1 -1
  35. package/dist/dom/controllable.feat.mjs +1 -1
  36. package/dist/dom/dynamic-tag-var.feat.js +1 -1
  37. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  38. package/dist/dom/placeholder.feat.d.ts +1 -0
  39. package/dist/dom/placeholder.feat.js +6 -0
  40. package/dist/dom/placeholder.feat.mjs +6 -0
  41. package/dist/dom/resume.d.ts +1 -0
  42. package/dist/{dom-B15s3PHD.js → dom-B5PaPvwd.js} +49 -44
  43. package/dist/{dom-CPUybM_C.mjs → dom-BlOP3cfL.mjs} +1 -1
  44. package/dist/dom.js +24 -24
  45. package/dist/dom.mjs +1 -1
  46. package/dist/html/writer.d.ts +2 -0
  47. package/dist/html.js +11 -11
  48. package/dist/html.mjs +11 -11
  49. package/dist/translator/index.js +5 -2
  50. package/dist/translator/util/references.d.ts +4 -0
  51. package/dist/translator/util/runtime.d.ts +1 -1
  52. package/package.json +3 -3
package/dist/html.js CHANGED
@@ -1499,16 +1499,14 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1499
1499
  });
1500
1500
  }
1501
1501
  function _try(scopeId, accessor, content, input) {
1502
- let branchId = _peek_scope_id();
1503
- $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
1504
- let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder);
1505
- catchContent === void 0 ? placeholderContent ? tryPlaceholder(content, placeholderContent, branchId) : content() : tryCatch(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId) : content, catchContent || (() => {})), writeScope(branchId, {
1502
+ let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder), placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id();
1503
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), catchContent === void 0 ? placeholderContent ? tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content() : tryCatch(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent || (() => {})), writeScope(branchId, {
1506
1504
  C: accessor,
1507
1505
  E: catchContent,
1508
1506
  Q: placeholderContent
1509
1507
  }), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1510
1508
  }
1511
- function tryPlaceholder(content, placeholder, branchId) {
1509
+ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1512
1510
  let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
1513
1511
  if (body === body.render(content)) {
1514
1512
  chunk.append(body);
@@ -1517,7 +1515,9 @@ function tryPlaceholder(content, placeholder, branchId) {
1517
1515
  chunk.next = $chunk = chunk.fork(boundary, chunk.next), chunk.placeholder = {
1518
1516
  body,
1519
1517
  render: placeholder,
1520
- branchId
1518
+ branchId,
1519
+ scopeId,
1520
+ placeholderBranchId
1521
1521
  };
1522
1522
  }
1523
1523
  function tryCatch(content, catchContent) {
@@ -1666,10 +1666,10 @@ var State = class {
1666
1666
  if (placeholder) {
1667
1667
  let body = placeholder.body.consume();
1668
1668
  if (body.async) {
1669
- let { state } = this.boundary, reorderId = body.reorderId = placeholder.branchId ? placeholder.branchId + "" : state.nextReorderId();
1669
+ let { state } = this.boundary, { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
1670
1670
  this.writeHTML(state.mark("!^", reorderId));
1671
- let after = this.render(placeholder.render);
1672
- after !== this && this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), after.writeHTML(state.mark("!", reorderId)), state.reorder(body);
1671
+ let { effects } = this, beforeBranch = deferBranchStart(this), after = this.render(() => withBranchId(placeholderBranchId, placeholder.render)), stateful = after === this && this.effects !== effects;
1672
+ applyBranchStart(this, beforeBranch, stateful), after === this ? stateful && (this.render(() => writeScope(branchId, { P: scopeWithId(state, placeholderBranchId) })), this.writeHTML(state.mark("]", scopeId + " " + ("P" + branchId) + " " + placeholderBranchId)), body.writeEffect(branchId, "f")) : this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.writeHTML(state.mark("!", reorderId)), state.reorder(body);
1673
1673
  } else body.next = this.next, this.next = body;
1674
1674
  this.placeholder = null;
1675
1675
  }
@@ -1720,7 +1720,7 @@ var State = class {
1720
1720
  }
1721
1721
  readyResumeScripts && (needsWalk = !0);
1722
1722
  let effects = this.async ? "" : this.effects, { html, scripts } = this;
1723
- if (state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\""), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]"))), state.writeReorders) {
1723
+ if (state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\""), state.writeReorders) {
1724
1724
  let carried = null;
1725
1725
  for (let reorderedChunk of state.writeReorders) {
1726
1726
  if (reorderedChunk.async && reorderedChunk.consumed) {
@@ -1746,7 +1746,7 @@ var State = class {
1746
1746
  }
1747
1747
  state.writeReorders = carried;
1748
1748
  }
1749
- return needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1749
+ return flushSerializer(boundary, state), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]"))), needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1750
1750
  }
1751
1751
  flushHTML() {
1752
1752
  let { boundary } = this, { state } = boundary;
package/dist/html.mjs CHANGED
@@ -1498,16 +1498,14 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1498
1498
  });
1499
1499
  }
1500
1500
  function _try(scopeId, accessor, content, input) {
1501
- let branchId = _peek_scope_id();
1502
- $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
1503
- let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder);
1504
- catchContent === void 0 ? placeholderContent ? tryPlaceholder(content, placeholderContent, branchId) : content() : tryCatch(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId) : content, catchContent || (() => {})), writeScope(branchId, {
1501
+ let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder), placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id();
1502
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), catchContent === void 0 ? placeholderContent ? tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content() : tryCatch(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent || (() => {})), writeScope(branchId, {
1505
1503
  C: accessor,
1506
1504
  E: catchContent,
1507
1505
  Q: placeholderContent
1508
1506
  }), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1509
1507
  }
1510
- function tryPlaceholder(content, placeholder, branchId) {
1508
+ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1511
1509
  let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
1512
1510
  if (body === body.render(content)) {
1513
1511
  chunk.append(body);
@@ -1516,7 +1514,9 @@ function tryPlaceholder(content, placeholder, branchId) {
1516
1514
  chunk.next = $chunk = chunk.fork(boundary, chunk.next), chunk.placeholder = {
1517
1515
  body,
1518
1516
  render: placeholder,
1519
- branchId
1517
+ branchId,
1518
+ scopeId,
1519
+ placeholderBranchId
1520
1520
  };
1521
1521
  }
1522
1522
  function tryCatch(content, catchContent) {
@@ -1665,10 +1665,10 @@ var State = class {
1665
1665
  if (placeholder) {
1666
1666
  let body = placeholder.body.consume();
1667
1667
  if (body.async) {
1668
- let { state } = this.boundary, reorderId = body.reorderId = placeholder.branchId ? placeholder.branchId + "" : state.nextReorderId();
1668
+ let { state } = this.boundary, { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
1669
1669
  this.writeHTML(state.mark("!^", reorderId));
1670
- let after = this.render(placeholder.render);
1671
- after !== this && this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), after.writeHTML(state.mark("!", reorderId)), state.reorder(body);
1670
+ let { effects } = this, beforeBranch = deferBranchStart(this), after = this.render(() => withBranchId(placeholderBranchId, placeholder.render)), stateful = after === this && this.effects !== effects;
1671
+ applyBranchStart(this, beforeBranch, stateful), after === this ? stateful && (this.render(() => writeScope(branchId, { P: scopeWithId(state, placeholderBranchId) })), this.writeHTML(state.mark("]", scopeId + " " + ("P" + branchId) + " " + placeholderBranchId)), body.writeEffect(branchId, "f")) : this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.writeHTML(state.mark("!", reorderId)), state.reorder(body);
1672
1672
  } else body.next = this.next, this.next = body;
1673
1673
  this.placeholder = null;
1674
1674
  }
@@ -1719,7 +1719,7 @@ var State = class {
1719
1719
  }
1720
1720
  readyResumeScripts && (needsWalk = !0);
1721
1721
  let effects = this.async ? "" : this.effects, { html, scripts } = this;
1722
- if (state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\""), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]"))), state.writeReorders) {
1722
+ if (state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\""), state.writeReorders) {
1723
1723
  let carried = null;
1724
1724
  for (let reorderedChunk of state.writeReorders) {
1725
1725
  if (reorderedChunk.async && reorderedChunk.consumed) {
@@ -1745,7 +1745,7 @@ var State = class {
1745
1745
  }
1746
1746
  state.writeReorders = carried;
1747
1747
  }
1748
- return needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1748
+ return flushSerializer(boundary, state), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]"))), needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1749
1749
  }
1750
1750
  flushHTML() {
1751
1751
  let { boundary } = this, { state } = boundary;
@@ -4173,6 +4173,7 @@ var html_default = { translate: {
4173
4173
  });
4174
4174
  },
4175
4175
  exit(program) {
4176
+ 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"))]));
4176
4177
  flushInto(program);
4177
4178
  writeHTMLResumeStatements(program);
4178
4179
  traverseReplace(program.node, "body", replaceNode);
@@ -7292,6 +7293,7 @@ function setReferencesScope(path) {
7292
7293
  }
7293
7294
  const [getGlobalBinding] = createProgramState(() => createBinding("$global", 7, getOrCreateSection((0, _marko_compiler_babel_utils.getProgram)())));
7294
7295
  function trackGlobalReference(path) {
7296
+ (0, _marko_compiler_babel_utils.getProgram)().node.extra.hasGlobalRead = true;
7295
7297
  trackReference(path, getGlobalBinding());
7296
7298
  }
7297
7299
  function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties, restOffset) {
@@ -9638,8 +9640,10 @@ var try_default = {
9638
9640
  const section = getSection(tag);
9639
9641
  const bodySection = getSectionForBody(tag.get("body"));
9640
9642
  const signal = getSignal(section, nodeRef, "try");
9643
+ const hasPlaceholder = !!tag.node.extra?.attributeTags?.["@placeholder"];
9641
9644
  signal.build = () => {
9642
9645
  importRuntimeFeature("catch");
9646
+ if (hasPlaceholder) importRuntimeFeature("placeholder");
9643
9647
  return callRuntime("_try", getScopeAccessorLiteral(nodeRef, true), ...replaceNullishAndEmptyFunctionsWith0(getBranchRendererArgs(bodySection)));
9644
9648
  };
9645
9649
  if (translatedAttrs.statements.length) addStatement("render", section, referencedBindings, translatedAttrs.statements);
@@ -10096,8 +10100,7 @@ var referenced_identifier_default = {
10096
10100
  if (identifier.scope.hasBinding(name)) return;
10097
10101
  switch (name) {
10098
10102
  case "$global":
10099
- if (isOutputHTML()) identifier.replaceWith(_marko_compiler.types.callExpression(importRuntime("$global"), []));
10100
- else identifier.replaceWith(_marko_compiler.types.memberExpression(scopeIdentifier, _marko_compiler.types.identifier(getAccessorProp().Global)));
10103
+ if (!isOutputHTML()) identifier.replaceWith(_marko_compiler.types.memberExpression(scopeIdentifier, _marko_compiler.types.identifier(getAccessorProp().Global)));
10101
10104
  break;
10102
10105
  case "$signal": if (isOutputHTML()) identifier.replaceWith(_marko_compiler.types.callExpression(_marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([_marko_compiler.types.throwStatement(_marko_compiler.types.newExpression(_marko_compiler.types.identifier("Error"), [_marko_compiler.types.stringLiteral("Cannot use $signal in a server render.")]))])), []));
10103
10106
  else {
@@ -82,6 +82,10 @@ interface ExtraRead {
82
82
  localFn?: ReferencedFunctionExtra;
83
83
  }
84
84
  declare module "@marko/compiler/dist/types" {
85
+ interface ProgramExtra {
86
+ /** This template reads `$global`, so HTML output declares a const for it. */
87
+ hasGlobalRead?: true;
88
+ }
85
89
  interface NodeExtra {
86
90
  section?: Section;
87
91
  referencedBindings?: ReferencedBindings;
@@ -5,7 +5,7 @@ export type DOMRuntimeHelpers = keyof typeof import("../../dom");
5
5
  export type HTMLRuntimeHelpers = keyof typeof import("../../html");
6
6
  export declare function importRuntime(name: DOMRuntimeHelpers | HTMLRuntimeHelpers): t.Identifier;
7
7
  export declare function callRuntime(name: DOMRuntimeHelpers | HTMLRuntimeHelpers, ...args: Array<Parameters<typeof t.callExpression>[1][number] | Falsy>): t.CallExpression;
8
- export type DOMRuntimeFeature = "catch" | "controllable" | "controllable-input" | "controllable-open" | "controllable-select" | "controllable-textarea" | "dynamic-tag-var";
8
+ export type DOMRuntimeFeature = "catch" | "controllable" | "controllable-input" | "controllable-open" | "controllable-select" | "controllable-textarea" | "dynamic-tag-var" | "placeholder";
9
9
  export declare function importRuntimeFeature(feature: DOMRuntimeFeature): void;
10
10
  export declare function getHTMLRuntime(): {
11
11
  _escape: typeof _escape;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.3.39",
3
+ "version": "6.3.40",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -54,8 +54,8 @@
54
54
  "magic-string": "^0.30.21"
55
55
  },
56
56
  "devDependencies": {
57
- "marko": "5.39.34",
58
- "@marko/runtime-tags": "npm:marko@6.3.39"
57
+ "@marko/runtime-tags": "npm:marko@6.3.40",
58
+ "marko": "5.39.34"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=22"