marko 6.0.113 → 6.0.114

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.mjs CHANGED
@@ -122,7 +122,7 @@ function forStepBy(by, index) {
122
122
  }
123
123
 
124
124
  // src/html/inlined-runtimes.ts
125
- var WALKER_RUNTIME_CODE = '(e=>(self[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]))', REORDER_RUNTIME_CODE = '(e=>{if(e.j)return;let i,l,r,t={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),"#"==n?(t[a]=l).i++:"!"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):"T"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l["^"+a]){if(--o.i)return 1;for(;(r=e.l[a].previousSibling||i).remove(),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})';
125
+ var WALKER_RUNTIME_CODE = '(e=>(self[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]))', REORDER_RUNTIME_CODE = '(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),"#"==n?(t[a]=l).i++:"!"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):"T"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l["^"+a]){if(--o.i)return 1;for(;(r=e.l[a].previousSibling||i).remove(),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})';
126
126
 
127
127
  // src/html/serializer.ts
128
128
  var kTouchedIterator = Symbol(), { hasOwnProperty } = {}, Generator = (function* () {
@@ -1061,7 +1061,7 @@ function writeScript(script) {
1061
1061
  $chunk.writeScript(script);
1062
1062
  }
1063
1063
  function _script(scopeId, registryId) {
1064
- $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1064
+ $chunk.context?.[kIsAsync] && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1065
1065
  }
1066
1066
  function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
1067
1067
  let shouldResume = serializeReason !== 0, render2 = normalizeServerRender(content), branchId = _peek_scope_id();
@@ -1076,11 +1076,11 @@ function normalizeServerRender(value) {
1076
1076
  return renderer;
1077
1077
  }
1078
1078
  var kPendingContexts = Symbol("Pending Contexts");
1079
- function withContext(key, value, cb) {
1079
+ function withContext(key, value, cb, cbValue) {
1080
1080
  let ctx = $chunk.context ||= { [kPendingContexts]: 0 }, prev = ctx[key];
1081
1081
  ctx[kPendingContexts]++, ctx[key] = value;
1082
1082
  try {
1083
- return cb();
1083
+ return cb(cbValue);
1084
1084
  } finally {
1085
1085
  ctx[kPendingContexts]--, ctx[key] = prev;
1086
1086
  }
@@ -1142,15 +1142,18 @@ function _hoist(scopeId, id) {
1142
1142
  return getter[Symbol.iterator] = _hoist_read_error, _resume(getter, id, scopeId);
1143
1143
  }
1144
1144
  function _resume_branch(scopeId) {
1145
- let branchId = $chunk.context?.[branchIdKey];
1145
+ let branchId = $chunk.context?.[kBranchId];
1146
1146
  branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { G: branchId });
1147
1147
  }
1148
- var branchIdKey = Symbol();
1148
+ var kBranchId = Symbol("Branch Id"), kIsAsync = Symbol("Is Async");
1149
1149
  function isInResumedBranch() {
1150
- return $chunk?.context?.[branchIdKey] !== void 0;
1150
+ return $chunk?.context?.[kBranchId] !== void 0;
1151
1151
  }
1152
1152
  function withBranchId(branchId, cb) {
1153
- return withContext(branchIdKey, branchId, cb);
1153
+ return withContext(kBranchId, branchId, cb);
1154
+ }
1155
+ function withIsAsync(cb, value) {
1156
+ return withContext(kIsAsync, !0, cb, value);
1154
1157
  }
1155
1158
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1156
1159
  let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
@@ -1350,14 +1353,14 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1350
1353
  let branchId = _peek_scope_id();
1351
1354
  $chunk.writeHTML(
1352
1355
  $chunk.boundary.state.mark("[" /* BranchStart */, "")
1353
- ), content(value), $chunk.writeHTML(
1356
+ ), withIsAsync(content, value), $chunk.writeHTML(
1354
1357
  $chunk.boundary.state.mark(
1355
1358
  "]" /* BranchEnd */,
1356
1359
  scopeId + " " + accessor + " " + branchId
1357
1360
  )
1358
1361
  );
1359
1362
  } else
1360
- content(value);
1363
+ withIsAsync(content, value);
1361
1364
  }), boundary.endAsync(chunk)));
1362
1365
  },
1363
1366
  (err) => {
@@ -1370,9 +1373,9 @@ function _try(scopeId, accessor, content, input) {
1370
1373
  $chunk.writeHTML($chunk.boundary.state.mark("[" /* BranchStart */, ""));
1371
1374
  let catchContent = normalizeDynamicRenderer(input.catch), placeholderContent = normalizeDynamicRenderer(input.placeholder);
1372
1375
  catchContent ? tryCatch(
1373
- placeholderContent ? () => tryPlaceholder(content, placeholderContent) : content,
1376
+ placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId) : content,
1374
1377
  catchContent
1375
- ) : placeholderContent ? tryPlaceholder(content, placeholderContent) : content(), writeScope(branchId, {
1378
+ ) : placeholderContent ? tryPlaceholder(content, placeholderContent, branchId) : content(), writeScope(branchId, {
1376
1379
  C: accessor,
1377
1380
  E: catchContent,
1378
1381
  Q: placeholderContent
@@ -1383,13 +1386,13 @@ function _try(scopeId, accessor, content, input) {
1383
1386
  )
1384
1387
  );
1385
1388
  }
1386
- function tryPlaceholder(content, placeholder) {
1389
+ function tryPlaceholder(content, placeholder, branchId) {
1387
1390
  let chunk = $chunk, { boundary } = chunk, body = new Chunk(boundary, null, chunk.context);
1388
1391
  if (body === body.render(content)) {
1389
1392
  chunk.append(body);
1390
1393
  return;
1391
1394
  }
1392
- chunk.next = $chunk = new Chunk(boundary, chunk.next, body.context), chunk.placeholderBody = body, chunk.placeholderRender = placeholder;
1395
+ chunk.next = $chunk = new Chunk(boundary, chunk.next, chunk.context), chunk.placeholderBody = body, chunk.placeholderRender = placeholder, chunk.placeholderBranchId = branchId;
1393
1396
  }
1394
1397
  function tryCatch(content, catchContent) {
1395
1398
  let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state), body = new Chunk(catchBoundary, null, chunk.context), bodyEnd = body.render(content);
@@ -1499,14 +1502,12 @@ var Boundary = class extends AbortController {
1499
1502
  reorderId = null;
1500
1503
  placeholderBody = null;
1501
1504
  placeholderRender = null;
1505
+ placeholderBranchId = null;
1502
1506
  writeHTML(html) {
1503
1507
  this.html += html;
1504
1508
  }
1505
1509
  writeEffect(scopeId, registryId) {
1506
- this.lastEffect === registryId ? this.effects += "," + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(
1507
- this.effects,
1508
- '"' + registryId + '",' + scopeId
1509
- ));
1510
+ this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1510
1511
  }
1511
1512
  writeScript(script) {
1512
1513
  this.scripts = concatScripts(this.scripts, script);
@@ -1518,8 +1519,8 @@ var Boundary = class extends AbortController {
1518
1519
  if (this.placeholderBody) {
1519
1520
  let body = this.placeholderBody.consume();
1520
1521
  if (body.async) {
1521
- let { state } = this.boundary, reorderId = body.reorderId = state.nextReorderId();
1522
- this.writeHTML(state.mark("!^" /* Placeholder */, reorderId));
1522
+ let { state } = this.boundary, reorderId = body.reorderId = this.placeholderBranchId ? this.placeholderBranchId + "" : state.nextReorderId();
1523
+ this.placeholderBranchId = null, this.writeHTML(state.mark("!^" /* Placeholder */, reorderId));
1523
1524
  let after = this.render(this.placeholderRender);
1524
1525
  after !== this && this.boundary.abort(
1525
1526
  new Error("An @placeholder cannot contain async content.")
@@ -1556,7 +1557,7 @@ var Boundary = class extends AbortController {
1556
1557
  if (needsWalk && (state.walkOnNextFlush = !1), state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(
1557
1558
  scripts,
1558
1559
  WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
1559
- )), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + "," + effects : effects), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(
1560
+ )), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ',"' + effects + '"' : '"' + effects + '"'), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(
1560
1561
  scripts,
1561
1562
  runtimePrefix + ".r.push(" + state.resumes + ")"
1562
1563
  ) : (state.hasWrittenResume = !0, scripts = concatScripts(
@@ -1585,10 +1586,10 @@ var Boundary = class extends AbortController {
1585
1586
  runtimePrefix + ".r=[]"
1586
1587
  )), reorderScripts = concatScripts(
1587
1588
  reorderScripts,
1588
- "_.push(" + reorderEffects + ")"
1589
+ '_.push("' + reorderEffects + '")'
1589
1590
  )), scripts = concatScripts(
1590
1591
  scripts,
1591
- reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
1592
+ reorderScripts && runtimePrefix + ".j" /* Scripts */ + toAccess(reorderId) + "=_=>{" + reorderScripts + "}"
1592
1593
  ), html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1593
1594
  }
1594
1595
  state.writeReorders = null;
@@ -1611,7 +1612,7 @@ function flushSerializer(boundary) {
1611
1612
  let scope = writeScopes[key], scopeId = getScopeId(scope), scopeIdDelta = scopeId - lastSerializedScopeId;
1612
1613
  lastSerializedScopeId = scopeId + 1, scopeIdDelta && serializeData.push(scopeIdDelta), serializeData.push(scope);
1613
1614
  }
1614
- state.resumes = concatEffects(
1615
+ state.resumes = concatSequence(
1615
1616
  state.resumes,
1616
1617
  serializer.stringify(serializeData, boundary)
1617
1618
  ), state.lastSerializedScopeId = lastSerializedScopeId, state.writeScopes = null, flushed && (state.walkOnNextFlush = !0);
@@ -1621,6 +1622,9 @@ function _trailers(html) {
1621
1622
  $chunk.boundary.state.trailerHTML += html;
1622
1623
  }
1623
1624
  function concatEffects(a, b) {
1625
+ return a ? b ? a + " " + b : a : b;
1626
+ }
1627
+ function concatSequence(a, b) {
1624
1628
  return a ? b ? a + "," + b : a : b;
1625
1629
  }
1626
1630
  function concatScripts(a, b) {
@@ -137,6 +137,7 @@ var AccessorProp = /* @__PURE__ */ ((AccessorProp4) => {
137
137
  AccessorProp4["Owner"] = "_";
138
138
  AccessorProp4["AbortControllers"] = "#AbortControllers";
139
139
  AccessorProp4["AbortScopes"] = "#AbortScopes";
140
+ AccessorProp4["AwaitCounter"] = "#AwaitCounter";
140
141
  AccessorProp4["BranchAccessor"] = "#BranchAccessor";
141
142
  AccessorProp4["BranchScopes"] = "#BranchScopes";
142
143
  AccessorProp4["CatchContent"] = "#CatchContent";
@@ -144,12 +145,11 @@ var AccessorProp = /* @__PURE__ */ ((AccessorProp4) => {
144
145
  AccessorProp4["ClosestBranchId"] = "#ClosestBranchId";
145
146
  AccessorProp4["Creating"] = "#Creating";
146
147
  AccessorProp4["Destroyed"] = "#Destroyed";
147
- AccessorProp4["PendingEffects"] = "#PendingEffects";
148
148
  AccessorProp4["EndNode"] = "#EndNode";
149
149
  AccessorProp4["Id"] = "#Id";
150
150
  AccessorProp4["LoopKey"] = "#LoopKey";
151
151
  AccessorProp4["ParentBranch"] = "#ParentBranch";
152
- AccessorProp4["PendingAsyncCount"] = "#PendingAsyncCount";
152
+ AccessorProp4["PendingEffects"] = "#PendingEffects";
153
153
  AccessorProp4["PlaceholderBranch"] = "#PlaceholderBranch";
154
154
  AccessorProp4["PlaceholderContent"] = "#PlaceholderContent";
155
155
  AccessorProp4["Renderer"] = "#Renderer";
@@ -1286,6 +1286,7 @@ var AccessorProp2 = /* @__PURE__ */ ((AccessorProp4) => {
1286
1286
  AccessorProp4["Owner"] = "_";
1287
1287
  AccessorProp4["AbortControllers"] = "A";
1288
1288
  AccessorProp4["AbortScopes"] = "B";
1289
+ AccessorProp4["AwaitCounter"] = "O";
1289
1290
  AccessorProp4["BranchAccessor"] = "C";
1290
1291
  AccessorProp4["BranchScopes"] = "D";
1291
1292
  AccessorProp4["CatchContent"] = "E";
@@ -1293,12 +1294,11 @@ var AccessorProp2 = /* @__PURE__ */ ((AccessorProp4) => {
1293
1294
  AccessorProp4["ClosestBranchId"] = "G";
1294
1295
  AccessorProp4["Creating"] = "H";
1295
1296
  AccessorProp4["Destroyed"] = "I";
1296
- AccessorProp4["PendingEffects"] = "J";
1297
1297
  AccessorProp4["EndNode"] = "K";
1298
1298
  AccessorProp4["Id"] = "L";
1299
1299
  AccessorProp4["LoopKey"] = "M";
1300
1300
  AccessorProp4["ParentBranch"] = "N";
1301
- AccessorProp4["PendingAsyncCount"] = "O";
1301
+ AccessorProp4["PendingEffects"] = "J";
1302
1302
  AccessorProp4["PlaceholderBranch"] = "P";
1303
1303
  AccessorProp4["PlaceholderContent"] = "Q";
1304
1304
  AccessorProp4["Renderer"] = "R";
@@ -1779,7 +1779,7 @@ var [_getScopeIdentifier] = createSectionState(
1779
1779
  "scopeIdentifier",
1780
1780
  () => import_compiler7.types.identifier("undefined")
1781
1781
  );
1782
- var [getBranchRendererArgs, setSectionRendererArgs] = createSectionState("rendererExpression");
1782
+ var [getBranchRendererArgs, setBranchRendererArgs] = createSectionState("rendererExpression");
1783
1783
  function forEachSection(fn) {
1784
1784
  const { sections } = (0, import_babel_utils10.getProgram)().node.extra;
1785
1785
  sections?.forEach(fn);
@@ -2400,7 +2400,8 @@ function _escape_style(val) {
2400
2400
  // src/html/writer.ts
2401
2401
  var K_SCOPE_ID = Symbol("Scope ID");
2402
2402
  var kPendingContexts = Symbol("Pending Contexts");
2403
- var branchIdKey = Symbol();
2403
+ var kBranchId = Symbol("Branch Id");
2404
+ var kIsAsync = Symbol("Is Async");
2404
2405
  if (false) {
2405
2406
  writeScope = /* @__PURE__ */ ((writeScope2) => (scopeId, partialScope, file, loc, vars) => {
2406
2407
  const scope = writeScope2(scopeId, partialScope);
@@ -2500,7 +2501,8 @@ function toMemberExpression(object, key, optional) {
2500
2501
 
2501
2502
  // src/translator/util/runtime.ts
2502
2503
  var pureDOMFunctions = /* @__PURE__ */ new Set([
2503
- "_await",
2504
+ "_await_promise",
2505
+ "_await_content",
2504
2506
  "_child_setup",
2505
2507
  "_if",
2506
2508
  "_if_closure",
@@ -4403,7 +4405,7 @@ var dom_default = {
4403
4405
  writeSignals(childSection);
4404
4406
  if (!childSection.downstreamBinding || bindingHasDownstreamExpressions(childSection.downstreamBinding)) {
4405
4407
  if (getSectionParentIsOwner(childSection)) {
4406
- setSectionRendererArgs(childSection, [
4408
+ setBranchRendererArgs(childSection, [
4407
4409
  writes2,
4408
4410
  walks2,
4409
4411
  setup,
@@ -9211,17 +9213,37 @@ var await_default = {
9211
9213
  const nodeRef = tagExtra[kDOMBinding];
9212
9214
  const section = getSection(tag);
9213
9215
  const bodySection = getSectionForBody(tag.get("body"));
9214
- const signal = getSignal(section, nodeRef, "await");
9216
+ const signal = getSignal(section, nodeRef, "await_promise");
9215
9217
  const valueExpr = node.attributes[0].value;
9216
9218
  signal.build = () => {
9219
+ const branchRenderArgs = getBranchRendererArgs(bodySection);
9220
+ const branchParams = branchRenderArgs.pop();
9221
+ (signal.prependStatements ||= []).push(
9222
+ import_compiler36.types.variableDeclaration("const", [
9223
+ import_compiler36.types.variableDeclarator(
9224
+ import_compiler36.types.identifier(bodySection.name),
9225
+ callRuntime(
9226
+ "_await_content",
9227
+ getScopeAccessorLiteral(nodeRef, true),
9228
+ ...replaceNullishAndEmptyFunctionsWith0(branchRenderArgs)
9229
+ )
9230
+ )
9231
+ ])
9232
+ );
9217
9233
  return callRuntime(
9218
- "_await",
9234
+ "_await_promise",
9219
9235
  getScopeAccessorLiteral(nodeRef, true),
9220
- ...replaceNullishAndEmptyFunctionsWith0(
9221
- getBranchRendererArgs(bodySection)
9222
- )
9236
+ branchParams
9223
9237
  );
9224
9238
  };
9239
+ addStatement(
9240
+ "render",
9241
+ section,
9242
+ void 0,
9243
+ import_compiler36.types.expressionStatement(
9244
+ import_compiler36.types.callExpression(import_compiler36.types.identifier(bodySection.name), [scopeIdentifier])
9245
+ )
9246
+ );
9225
9247
  addValue(
9226
9248
  section,
9227
9249
  valueExpr.extra?.referencedBindings,
@@ -67,7 +67,7 @@ export declare function getSectionForBody(body: t.NodePath<t.MarkoTagBody | t.Pr
67
67
  export declare function getSection(path: t.NodePath): Section;
68
68
  export declare const getScopeIdIdentifier: (section: Section) => t.Identifier;
69
69
  export declare const getSectionParentIsOwner: (section: Section) => boolean, setSectionParentIsOwner: (section: Section, value: boolean) => void;
70
- export declare const getBranchRendererArgs: (section: Section) => [template?: t.Expression | undefined, walks?: t.Expression | undefined, setup?: t.Expression | undefined, params?: t.Expression | undefined], setSectionRendererArgs: (section: Section, value: [template?: t.Expression | undefined, walks?: t.Expression | undefined, setup?: t.Expression | undefined, params?: t.Expression | undefined]) => void;
70
+ export declare const getBranchRendererArgs: (section: Section) => [template?: t.Expression | undefined, walks?: t.Expression | undefined, setup?: t.Expression | undefined, params?: t.Expression | undefined], setBranchRendererArgs: (section: Section, value: [template?: t.Expression | undefined, walks?: t.Expression | undefined, setup?: t.Expression | undefined, params?: t.Expression | undefined]) => void;
71
71
  export declare const getScopeIdentifier: (section: Section, ignoreDefault?: boolean) => t.Identifier;
72
72
  export declare function forEachSection(fn: (section: Section) => void): void;
73
73
  export declare function forEachSectionReverse(fn: (section: Section) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.113",
3
+ "version": "6.0.114",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",