marko 6.0.50 → 6.0.52

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
@@ -1101,6 +1101,9 @@ function resumeClosestBranch(scopeId) {
1101
1101
  branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { g: branchId });
1102
1102
  }
1103
1103
  var branchIdKey = Symbol();
1104
+ function isInResumedBranch() {
1105
+ return $chunk?.context?.[branchIdKey] !== void 0;
1106
+ }
1104
1107
  function withBranchId(branchId, cb) {
1105
1108
  return withContext(branchIdKey, branchId, cb);
1106
1109
  }
@@ -1458,7 +1461,6 @@ var State2 = class {
1458
1461
  }
1459
1462
  }
1460
1463
  flushScript() {
1461
- flushSerializer(this.boundary);
1462
1464
  let { boundary, effects } = this, { state } = boundary, { $global: $global2, runtimePrefix, nonceAttr } = state, { html, scripts } = this, hasWalk = state.walkOnNextFlush;
1463
1465
  if (hasWalk && (state.walkOnNextFlush = !1), state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(
1464
1466
  scripts,
@@ -1877,7 +1879,7 @@ var ServerRendered = class {
1877
1879
  return reject(new Error("Cannot read from a consumed render result"));
1878
1880
  let { boundary } = head;
1879
1881
  (boundary.onNext = () => {
1880
- boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && resolve(head.consume().flushHTML());
1882
+ boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : !boundary.count && boundary.done && resolve(head.consume().flushHTML());
1881
1883
  })();
1882
1884
  });
1883
1885
  }
@@ -1917,37 +1919,46 @@ function NOOP2() {
1917
1919
  var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, dynamicTag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, serializeReason) => {
1918
1920
  let shouldResume = serializeReason !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = peekNextScopeId(), result;
1919
1921
  if (typeof renderer == "string") {
1920
- let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {}, renderContent = content || normalizeDynamicRenderer(input.content);
1921
- if (nextScopeId(), write(`<${renderer}${attrs(input, accessor, scopeId, renderer)}>`), !voidElementsReg.test(renderer)) {
1922
- let renderNativeTag = () => {
1923
- if (renderer === "textarea")
1924
- write(
1925
- controllable_textarea_value(
1926
- scopeId,
1927
- accessor,
1928
- input.value,
1929
- input.valueChange
1930
- )
1931
- );
1932
- else if (renderContent) {
1933
- if (typeof renderContent != "function")
1934
- throw new Error(
1935
- `Body content is not supported for the \`<${renderer}>\` tag.`
1936
- );
1937
- renderer === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
1938
- scopeId,
1939
- accessor,
1922
+ let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
1923
+ if (nextScopeId(), write(
1924
+ `<${renderer}${attrs(input, 0, branchId, renderer)}>`
1925
+ ), !voidElementsReg.test(renderer)) {
1926
+ let renderContent = content || normalizeDynamicRenderer(input.content);
1927
+ if (renderer === "textarea")
1928
+ write(
1929
+ controllable_textarea_value(
1930
+ branchId,
1931
+ 0,
1940
1932
  input.value,
1941
- input.valueChange,
1942
- renderContent
1943
- ) : renderContent();
1944
- }
1945
- };
1946
- shouldResume ? withBranchId(branchId, renderNativeTag) : renderNativeTag(), write(`</${renderer}>`);
1933
+ input.valueChange
1934
+ )
1935
+ );
1936
+ else if (renderContent) {
1937
+ if (typeof renderContent != "function")
1938
+ throw new Error(
1939
+ `Body content is not supported for the \`<${renderer}>\` tag.`
1940
+ );
1941
+ renderer === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
1942
+ branchId,
1943
+ 0,
1944
+ input.value,
1945
+ input.valueChange,
1946
+ renderContent
1947
+ ) : dynamicTag(
1948
+ branchId,
1949
+ 0,
1950
+ renderContent,
1951
+ [],
1952
+ 0,
1953
+ 1,
1954
+ serializeReason
1955
+ );
1956
+ }
1957
+ write(`</${renderer}>`);
1947
1958
  }
1948
1959
  shouldResume && write(
1949
1960
  state.mark(
1950
- "|" /* BranchSingleNode */,
1961
+ "'" /* BranchNativeTag */,
1951
1962
  scopeId + " " + accessor + " " + branchId
1952
1963
  )
1953
1964
  );
@@ -1984,7 +1995,7 @@ function registerContent(id, fn, scopeId) {
1984
1995
  function patchDynamicTag(patch) {
1985
1996
  dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
1986
1997
  let patched = patch(scopeId, accessor, tag);
1987
- return patched.h = tag, originalDynamicTag(
1998
+ return patched !== tag && (patched.h = tag), originalDynamicTag(
1988
1999
  scopeId,
1989
2000
  accessor,
1990
2001
  patched,
@@ -2004,9 +2015,16 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2004
2015
  writeScript,
2005
2016
  nextScopeId,
2006
2017
  peekNextScopeId,
2018
+ isInResumedBranch,
2007
2019
  isTagsAPI(fn) {
2008
2020
  return !!fn.h;
2009
2021
  },
2022
+ onFlush(fn) {
2023
+ let { flushHTML } = Chunk.prototype;
2024
+ Chunk.prototype.flushHTML = function() {
2025
+ return fn(this), flushHTML.call(this);
2026
+ };
2027
+ },
2010
2028
  patchDynamicTag,
2011
2029
  writeSetScopeForComponent(branchId, m5c) {
2012
2030
  writeScope(branchId, { m5c }), writeEffect(branchId, SET_SCOPE_REGISTER_ID);
@@ -2025,7 +2043,7 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2025
2043
  }
2026
2044
  return compatRegistered;
2027
2045
  },
2028
- render(renderer, willRerender, classAPIOut, component, input) {
2046
+ render(renderer, willRerender, classAPIOut, component, input, toStringEvent) {
2029
2047
  let $global2 = classAPIOut.global, state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2030
2048
  state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2));
2031
2049
  let boundary = new Boundary(state), head = new Chunk(
@@ -2044,18 +2062,19 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2044
2062
  writeScope(scopeId, { m5c: component.id }), writeEffect(scopeId, SET_SCOPE_REGISTER_ID);
2045
2063
  }
2046
2064
  isTemplate(renderer) && willRerender ? renderer(normalizedInput, 1) : renderer(normalizedInput);
2065
+ let asyncOut = classAPIOut.beginAsync();
2066
+ (boundary.onNext = () => {
2067
+ boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP3) : boundary.count || (asyncOut.once(toStringEvent, (writer) => {
2068
+ if (boundary.done) {
2069
+ let { html, scripts } = head.flushScript();
2070
+ writer.script(scripts), writer.write(html);
2071
+ } else
2072
+ asyncOut.error(
2073
+ new Error("Cannot serialize promises with class/tags interop.")
2074
+ );
2075
+ }), head = head.consume(), asyncOut.write(head.html), asyncOut.end(), head.html = "");
2076
+ })();
2047
2077
  });
2048
- let asyncOut = classAPIOut.beginAsync();
2049
- queueMicrotask(
2050
- boundary.onNext = () => {
2051
- if (boundary.signal.aborted)
2052
- asyncOut.error(boundary.signal.reason);
2053
- else if (boundary.done) {
2054
- let { scripts, html } = head.consume().flushScript();
2055
- asyncOut.script(scripts), asyncOut.write(html), boundary.done && asyncOut.end();
2056
- }
2057
- }
2058
- );
2059
2078
  },
2060
2079
  registerRenderer(renderer, id) {
2061
2080
  return register(
@@ -2069,6 +2088,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2069
2088
  register(RENDER_BODY_ID, fn);
2070
2089
  }
2071
2090
  };
2091
+ function NOOP3() {
2092
+ }
2072
2093
  export {
2073
2094
  $global,
2074
2095
  attr,
@@ -3211,11 +3211,11 @@ function getSignalFn(signal) {
3211
3211
  const aliasId = import_compiler20.types.identifier(alias.name);
3212
3212
  forEach(alias.excludeProperties, (name2) => {
3213
3213
  const propId = toPropertyName(name2);
3214
- const shorthand = propId.type === "Identifier";
3214
+ const shorthand = propId.type === "Identifier" && import_compiler20.types.isValidIdentifier(name2);
3215
3215
  props.push(
3216
3216
  import_compiler20.types.objectProperty(
3217
3217
  propId,
3218
- propId.type === "Identifier" ? propId : import_compiler20.types.objectPattern([]),
3218
+ shorthand ? propId : generateUidIdentifier(name2),
3219
3219
  false,
3220
3220
  shorthand
3221
3221
  )
@@ -5072,7 +5072,7 @@ function finalizeReferences() {
5072
5072
  let serializeReason;
5073
5073
  let currentSection = section;
5074
5074
  while (currentSection !== sourceSection) {
5075
- const upstreamReason = !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5075
+ const upstreamReason = currentSection.downstreamBinding ? isSerializedSection(currentSection) || void 0 : !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5076
5076
  if (upstreamReason === true) {
5077
5077
  serializeReason = true;
5078
5078
  break;
@@ -5098,7 +5098,7 @@ function finalizeReferences() {
5098
5098
  let serializeReason;
5099
5099
  let currentSection = section;
5100
5100
  while (currentSection !== sourceSection) {
5101
- const upstreamReason = !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5101
+ const upstreamReason = currentSection.downstreamBinding ? isSerializedSection(currentSection) || void 0 : !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5102
5102
  if (upstreamReason === true) {
5103
5103
  serializeReason = true;
5104
5104
  break;
@@ -7375,13 +7375,13 @@ function translateAttrs(tag, templateExports, statements = [], contentKey = "con
7375
7375
  }
7376
7376
  }
7377
7377
  if (!seen.has(contentKey) && usesExport(templateExports, contentKey)) {
7378
- seen.add(contentKey);
7379
7378
  const contentExpression = buildContent(tag.get("body"));
7380
7379
  if (contentExpression) {
7381
7380
  const contentProp = import_compiler34.types.objectProperty(
7382
7381
  import_compiler34.types.identifier(contentKey),
7383
7382
  contentExpression
7384
7383
  );
7384
+ seen.add(contentKey);
7385
7385
  contentProps.add(contentProp);
7386
7386
  properties.push(contentProp);
7387
7387
  }
@@ -10415,7 +10415,9 @@ var custom_tag_default = {
10415
10415
  `Local variables must be in a dynamic tag unless they are PascalCase. Use \`<\${${tagName}}/>\` or rename to \`${tagName.charAt(0).toUpperCase() + tagName.slice(1)}\`.`
10416
10416
  );
10417
10417
  }
10418
- throw tag.get("name").buildCodeFrameError("Unable to find entry point for custom tag.");
10418
+ throw tag.get("name").buildCodeFrameError(
10419
+ `Unable to find entry point for custom tag \`<${tagName}>\`.`
10420
+ );
10419
10421
  }
10420
10422
  const section = getOrCreateSection(tag);
10421
10423
  const tagBody = tag.get("body");
@@ -10757,7 +10759,9 @@ function getTagRelativePath(tag) {
10757
10759
  `Local variables must be in a dynamic tag unless they are PascalCase. Use \`<\${${tagName}}/>\` or rename to \`${tagName.charAt(0).toUpperCase() + tagName.slice(1)}\`.`
10758
10760
  );
10759
10761
  }
10760
- throw tag.get("name").buildCodeFrameError("Unable to find entry point for custom tag.");
10762
+ throw tag.get("name").buildCodeFrameError(
10763
+ `Unable to find entry point for custom tag \`<${tagName}>\`.`
10764
+ );
10761
10765
  }
10762
10766
  return relativePath;
10763
10767
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.50",
3
+ "version": "6.0.52",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",