marko 6.0.118 → 6.0.120

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.
@@ -145,11 +145,13 @@ var AccessorProp = /* @__PURE__ */ ((AccessorProp4) => {
145
145
  AccessorProp4["ClosestBranchId"] = "#ClosestBranchId";
146
146
  AccessorProp4["Creating"] = "#Creating";
147
147
  AccessorProp4["Destroyed"] = "#Destroyed";
148
+ AccessorProp4["DetachedAwait"] = "#DetachedAwait";
148
149
  AccessorProp4["EndNode"] = "#EndNode";
149
150
  AccessorProp4["Id"] = "#Id";
150
151
  AccessorProp4["LoopKey"] = "#LoopKey";
151
152
  AccessorProp4["ParentBranch"] = "#ParentBranch";
152
153
  AccessorProp4["PendingEffects"] = "#PendingEffects";
154
+ AccessorProp4["PendingRenders"] = "#PendingRenders";
153
155
  AccessorProp4["PlaceholderBranch"] = "#PlaceholderBranch";
154
156
  AccessorProp4["PlaceholderContent"] = "#PlaceholderContent";
155
157
  AccessorProp4["Renderer"] = "#Renderer";
@@ -1128,6 +1130,9 @@ function find(data, cb) {
1128
1130
  }
1129
1131
  }
1130
1132
  }
1133
+ function some(data, cb) {
1134
+ return data ? Array.isArray(data) ? data.some(cb) : !!cb(data, 0) : false;
1135
+ }
1131
1136
  function toArray(data, cb) {
1132
1137
  return data ? Array.isArray(data) ? data.map(cb) : [cb(data, 0)] : [];
1133
1138
  }
@@ -1297,11 +1302,13 @@ var AccessorProp2 = /* @__PURE__ */ ((AccessorProp4) => {
1297
1302
  AccessorProp4["ClosestBranchId"] = "G";
1298
1303
  AccessorProp4["Creating"] = "H";
1299
1304
  AccessorProp4["Destroyed"] = "I";
1305
+ AccessorProp4["DetachedAwait"] = "V";
1300
1306
  AccessorProp4["EndNode"] = "K";
1301
1307
  AccessorProp4["Id"] = "L";
1302
1308
  AccessorProp4["LoopKey"] = "M";
1303
1309
  AccessorProp4["ParentBranch"] = "N";
1304
1310
  AccessorProp4["PendingEffects"] = "J";
1311
+ AccessorProp4["PendingRenders"] = "W";
1305
1312
  AccessorProp4["PlaceholderBranch"] = "P";
1306
1313
  AccessorProp4["PlaceholderContent"] = "Q";
1307
1314
  AccessorProp4["Renderer"] = "R";
@@ -3336,6 +3343,7 @@ var [getClosureSignalBuilder, _setClosureSignalBuilder] = createSectionState("qu
3336
3343
  function setClosureSignalBuilder(tag, builder) {
3337
3344
  _setClosureSignalBuilder(getSectionForBody(tag.get("body")), builder);
3338
3345
  }
3346
+ var [getTryHasPlaceholder, setTryHasPlaceholder] = createSectionState("tryWithPlaceholder");
3339
3347
  var [getSerializedAccessors] = createSectionState("serializedScopeProperties", () => /* @__PURE__ */ new Map());
3340
3348
  function setSectionSerializedValue(section, prop, expression) {
3341
3349
  const reason = getSerializeReason(section, prop);
@@ -3429,23 +3437,37 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
3429
3437
  };
3430
3438
  } else if (referencedBindings.section !== section && bindingUtil.find(section.referencedClosures, referencedBindings)) {
3431
3439
  signal.build = () => {
3432
- const canonicalClosure = getCanonicalBinding(referencedBindings);
3440
+ const closure = getCanonicalBinding(referencedBindings);
3433
3441
  const render = getSignalFn(signal);
3434
3442
  const closureSignalBuilder = getClosureSignalBuilder(section);
3435
- return !closureSignalBuilder || isDynamicClosure(section, canonicalClosure) ? callRuntime(
3443
+ if (closureSignalBuilder && !isDynamicClosure(section, closure)) {
3444
+ return closureSignalBuilder(closure, render);
3445
+ }
3446
+ return callRuntime(
3436
3447
  "_closure_get",
3437
- getScopeAccessorLiteral(canonicalClosure, true),
3448
+ getScopeAccessorLiteral(closure, true),
3438
3449
  render,
3439
- isImmediateOwner(section, canonicalClosure) ? void 0 : import_compiler22.types.arrowFunctionExpression(
3450
+ isImmediateOwner(section, closure) ? void 0 : import_compiler22.types.arrowFunctionExpression(
3440
3451
  [scopeIdentifier],
3441
- getScopeExpression(section, canonicalClosure.section)
3442
- )
3443
- ) : getClosureSignalBuilder(section)(canonicalClosure, render);
3452
+ getScopeExpression(section, closure.section)
3453
+ ),
3454
+ some(closure.closureSections, underTryPlaceholder) ? import_compiler22.types.stringLiteral(getResumeRegisterId(section, closure)) : void 0
3455
+ );
3444
3456
  };
3445
3457
  }
3446
3458
  }
3447
3459
  return signal;
3448
3460
  }
3461
+ function underTryPlaceholder(section) {
3462
+ let curSection = section.parent;
3463
+ while (curSection) {
3464
+ if (getTryHasPlaceholder(curSection)) {
3465
+ return true;
3466
+ }
3467
+ curSection = curSection.parent;
3468
+ }
3469
+ return false;
3470
+ }
3449
3471
  function initValue(binding, isLet = false) {
3450
3472
  const section = binding.section;
3451
3473
  const signal = getSignal(section, binding);
@@ -4038,10 +4060,29 @@ function writeHTMLResumeStatements(path5) {
4038
4060
  import_compiler22.types.numericLiteral(getDynamicClosureIndex(closure, section)),
4039
4061
  getAccessorPrefix().ClosureSignalIndex
4040
4062
  );
4041
- addWriteScopeBuilder(
4042
- section,
4043
- (expr) => callRuntime("_subscribe", identifier, expr)
4044
- );
4063
+ if (underTryPlaceholder(section)) {
4064
+ const reason = getSerializeReason(section);
4065
+ if (reason) {
4066
+ getHTMLSectionStatements(section).push(
4067
+ import_compiler22.types.expressionStatement(
4068
+ getExprIfSerialized(
4069
+ section,
4070
+ reason,
4071
+ callRuntime(
4072
+ "_script",
4073
+ getScopeIdIdentifier(section),
4074
+ import_compiler22.types.stringLiteral(getResumeRegisterId(section, closure))
4075
+ )
4076
+ )
4077
+ )
4078
+ );
4079
+ }
4080
+ } else {
4081
+ addWriteScopeBuilder(
4082
+ section,
4083
+ (expr) => callRuntime("_subscribe", identifier, expr)
4084
+ );
4085
+ }
4045
4086
  }
4046
4087
  }
4047
4088
  });
@@ -5528,7 +5569,7 @@ var native_tag_default = {
5528
5569
  );
5529
5570
  }
5530
5571
  const tagName = getCanonicalTagName(tag);
5531
- const textOnly = isTextOnlyNativeTag(tag);
5572
+ const isTextOnly = isTextOnlyNativeTag(tag);
5532
5573
  const seen = {};
5533
5574
  const { attributes } = tag.node;
5534
5575
  let injectNonce = isInjectNonceTag(tagName);
@@ -5573,7 +5614,7 @@ var native_tag_default = {
5573
5614
  throw tag.get("name").buildCodeFrameError(msg);
5574
5615
  });
5575
5616
  let textPlaceholders;
5576
- if (textOnly) {
5617
+ if (isTextOnly) {
5577
5618
  for (const child of tag.node.body.body) {
5578
5619
  if (import_compiler33.types.isMarkoPlaceholder(child)) {
5579
5620
  (textPlaceholders ||= []).push(child.value);
@@ -5762,10 +5803,11 @@ var native_tag_default = {
5762
5803
  }
5763
5804
  }
5764
5805
  const isOpenOnly = !!(tagDef && tagDef.parseOptions?.openTagOnly);
5806
+ const isTextOnly = isTextOnlyNativeTag(tag);
5765
5807
  const hasChildren = !!tag.node.body.body.length;
5766
5808
  if (spreadExpression) {
5767
5809
  addHTMLEffectCall(tagSection, tagExtra.referencedBindings);
5768
- if (isOpenOnly || hasChildren || staticContentAttr) {
5810
+ if (isTextOnly || isOpenOnly || hasChildren || staticContentAttr) {
5769
5811
  if (skipExpression) {
5770
5812
  write`${callRuntime(
5771
5813
  "_attrs_partial",
@@ -5796,57 +5838,57 @@ var native_tag_default = {
5796
5838
  write`>`;
5797
5839
  break;
5798
5840
  }
5799
- } else {
5800
- if (staticContentAttr) {
5801
- write`>`;
5802
- tagExtra[kTagContentAttr] = true;
5803
- tag.node.body.body = [
5804
- import_compiler33.types.expressionStatement(
5805
- callRuntime(
5806
- "_attr_content",
5807
- visitAccessor,
5808
- getScopeIdIdentifier(tagSection),
5809
- staticContentAttr.value,
5810
- getSerializeGuard(
5811
- tagSection,
5812
- nodeBinding && getSerializeReason(tagSection, nodeBinding),
5813
- true
5814
- )
5841
+ } else if (isTextOnly) {
5842
+ write`>`;
5843
+ } else if (staticContentAttr) {
5844
+ write`>`;
5845
+ tagExtra[kTagContentAttr] = true;
5846
+ tag.node.body.body = [
5847
+ import_compiler33.types.expressionStatement(
5848
+ callRuntime(
5849
+ "_attr_content",
5850
+ visitAccessor,
5851
+ getScopeIdIdentifier(tagSection),
5852
+ staticContentAttr.value,
5853
+ getSerializeGuard(
5854
+ tagSection,
5855
+ nodeBinding && getSerializeReason(tagSection, nodeBinding),
5856
+ true
5815
5857
  )
5816
5858
  )
5817
- ];
5818
- } else if (spreadExpression && !hasChildren) {
5819
- const serializeReason = getSerializeGuard(
5820
- tagSection,
5821
- nodeBinding && getSerializeReason(tagSection, nodeBinding),
5822
- true
5823
- );
5824
- tagExtra[kTagContentAttr] = true;
5825
- tag.node.body.body = [
5826
- skipExpression ? import_compiler33.types.expressionStatement(
5827
- callRuntime(
5828
- "_attrs_partial_content",
5829
- spreadExpression,
5830
- skipExpression,
5831
- visitAccessor,
5832
- getScopeIdIdentifier(tagSection),
5833
- import_compiler33.types.stringLiteral(tagName),
5834
- serializeReason
5835
- )
5836
- ) : import_compiler33.types.expressionStatement(
5837
- callRuntime(
5838
- "_attrs_content",
5839
- spreadExpression,
5840
- visitAccessor,
5841
- getScopeIdIdentifier(tagSection),
5842
- import_compiler33.types.stringLiteral(tagName),
5843
- serializeReason
5844
- )
5859
+ )
5860
+ ];
5861
+ } else if (spreadExpression && !hasChildren) {
5862
+ const serializeReason = getSerializeGuard(
5863
+ tagSection,
5864
+ nodeBinding && getSerializeReason(tagSection, nodeBinding),
5865
+ true
5866
+ );
5867
+ tagExtra[kTagContentAttr] = true;
5868
+ tag.node.body.body = [
5869
+ skipExpression ? import_compiler33.types.expressionStatement(
5870
+ callRuntime(
5871
+ "_attrs_partial_content",
5872
+ spreadExpression,
5873
+ skipExpression,
5874
+ visitAccessor,
5875
+ getScopeIdIdentifier(tagSection),
5876
+ import_compiler33.types.stringLiteral(tagName),
5877
+ serializeReason
5845
5878
  )
5846
- ];
5847
- } else {
5848
- write`>`;
5849
- }
5879
+ ) : import_compiler33.types.expressionStatement(
5880
+ callRuntime(
5881
+ "_attrs_content",
5882
+ spreadExpression,
5883
+ visitAccessor,
5884
+ getScopeIdIdentifier(tagSection),
5885
+ import_compiler33.types.stringLiteral(tagName),
5886
+ serializeReason
5887
+ )
5888
+ )
5889
+ ];
5890
+ } else {
5891
+ write`>`;
5850
5892
  }
5851
5893
  if (writeAtStartOfBody) {
5852
5894
  write`${writeAtStartOfBody}`;
@@ -5855,8 +5897,8 @@ var native_tag_default = {
5855
5897
  exit(tag) {
5856
5898
  const tagExtra = tag.node.extra;
5857
5899
  const nodeBinding = tagExtra[kNativeTagBinding];
5858
- const openTagOnly = (0, import_babel_utils21.getTagDef)(tag)?.parseOptions?.openTagOnly;
5859
- const textOnly = isTextOnlyNativeTag(tag);
5900
+ const isOpenOnly = (0, import_babel_utils21.getTagDef)(tag)?.parseOptions?.openTagOnly;
5901
+ const isTextOnly = isTextOnlyNativeTag(tag);
5860
5902
  const selectArgs = htmlSelectArgs.get(tag.node);
5861
5903
  const tagName = getCanonicalTagName(tag);
5862
5904
  const tagSection = getSection(tag);
@@ -5888,7 +5930,7 @@ var native_tag_default = {
5888
5930
  )
5889
5931
  )
5890
5932
  );
5891
- } else if (textOnly) {
5933
+ } else if (isTextOnly) {
5892
5934
  for (const child of tag.node.body.body) {
5893
5935
  if (import_compiler33.types.isMarkoText(child)) {
5894
5936
  write`${child.value}`;
@@ -5899,7 +5941,7 @@ var native_tag_default = {
5899
5941
  } else {
5900
5942
  tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
5901
5943
  }
5902
- if (!tagExtra[kSkipEndTag] && !openTagOnly && !selectArgs) {
5944
+ if (!tagExtra[kSkipEndTag] && !isOpenOnly && !selectArgs) {
5903
5945
  write`</${tagName}>`;
5904
5946
  }
5905
5947
  if (markerSerializeReason) {
@@ -5930,6 +5972,7 @@ var native_tag_default = {
5930
5972
  injectNonce
5931
5973
  } = getUsedAttrs(tagName, tag.node);
5932
5974
  const isOpenOnly = !!(tagDef && tagDef.parseOptions?.openTagOnly);
5975
+ const isTextOnly = isTextOnlyNativeTag(tag);
5933
5976
  const hasChildren = !!tag.node.body.body.length;
5934
5977
  if (injectNonce) {
5935
5978
  addStatement(
@@ -6069,7 +6112,7 @@ var native_tag_default = {
6069
6112
  }
6070
6113
  }
6071
6114
  if (spreadExpression) {
6072
- const canHaveAttrContent = !(isOpenOnly || hasChildren || staticContentAttr);
6115
+ const canHaveAttrContent = !(isTextOnly || isOpenOnly || hasChildren || staticContentAttr);
6073
6116
  if (skipExpression) {
6074
6117
  addStatement(
6075
6118
  "render",
@@ -6144,12 +6187,13 @@ var native_tag_default = {
6144
6187
  const tagExtra = tag.node.extra;
6145
6188
  const nodeBinding = tagExtra[kNativeTagBinding];
6146
6189
  const openTagOnly = (0, import_babel_utils21.getTagDef)(tag)?.parseOptions?.openTagOnly;
6147
- const textOnly = isTextOnlyNativeTag(tag);
6190
+ const tagName = getCanonicalTagName(tag);
6148
6191
  if (!openTagOnly) {
6149
- if (textOnly) {
6192
+ const write = writeTo(tag);
6193
+ if (tagName !== "textarea" && isTextOnlyNativeTag(tag)) {
6150
6194
  const textLiteral = bodyToTextLiteral(tag.node.body);
6151
6195
  if (import_compiler33.types.isStringLiteral(textLiteral)) {
6152
- writeTo(tag)`${textLiteral}`;
6196
+ write`${textLiteral}`;
6153
6197
  } else {
6154
6198
  addStatement(
6155
6199
  "render",
@@ -6167,7 +6211,7 @@ var native_tag_default = {
6167
6211
  } else {
6168
6212
  tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
6169
6213
  }
6170
- writeTo(tag)`</${getCanonicalTagName(tag)}>`;
6214
+ write`</${tagName}>`;
6171
6215
  }
6172
6216
  exit2(tag);
6173
6217
  tag.remove();
@@ -11118,6 +11162,9 @@ var try_default = {
11118
11162
  }
11119
11163
  const tagBody = tag.get("body");
11120
11164
  const bodySection = getSectionForBody(tagBody);
11165
+ if (tag.node.extra?.attributeTags?.["@placeholder"]) {
11166
+ setTryHasPlaceholder(bodySection, true);
11167
+ }
11121
11168
  setSectionParentIsOwner(bodySection, true);
11122
11169
  flushBefore(tag);
11123
11170
  },
@@ -11157,6 +11204,9 @@ var try_default = {
11157
11204
  enter(tag) {
11158
11205
  const tagBody = tag.get("body");
11159
11206
  const bodySection = getSectionForBody(tagBody);
11207
+ if (tag.node.extra?.attributeTags?.["@placeholder"]) {
11208
+ setTryHasPlaceholder(bodySection, true);
11209
+ }
11160
11210
  setSectionParentIsOwner(bodySection, true);
11161
11211
  visit(tag, 37 /* Replace */);
11162
11212
  enterShallow(tag);
@@ -21,6 +21,7 @@ export declare function forEach<T>(data: Opt<T>, cb: (item: T, index: number) =>
21
21
  export declare function fromIter<T>(data: Iterable<T>): T | Many<T> | undefined;
22
22
  export declare function toIter<T>(data: Opt<T>): Iterable<T>;
23
23
  export declare function find<T>(data: Opt<T>, cb: (item: T, index: number) => boolean): Opt<T>;
24
+ export declare function some<T>(data: Opt<T>, cb: (item: T, index: number) => boolean): boolean;
24
25
  export declare function toArray<T, R>(data: Opt<T>, cb: (item: T, index: number) => R): R[];
25
26
  export declare function mapToString<T>(data: Opt<T>, sep: string, cb: (item: T, index: number) => string): string;
26
27
  export declare function filterMap<T, R>(data: Opt<T>, cb: (item: T) => undefined | R): Opt<R>;
@@ -26,6 +26,7 @@ export type Signal = {
26
26
  };
27
27
  type closureSignalBuilder = (closure: Binding, render: t.Expression) => t.Expression;
28
28
  export declare function setClosureSignalBuilder(tag: t.NodePath<t.MarkoTag>, builder: closureSignalBuilder): void;
29
+ export declare const getTryHasPlaceholder: (section: Section) => true | undefined, setTryHasPlaceholder: (section: Section, value: true | undefined) => void;
29
30
  export declare function setSectionSerializedValue(section: Section, prop: AccessorProp, expression: t.Expression): void;
30
31
  export declare function setBindingSerializedValue(section: Section, binding: Binding, expression: t.Expression, prefix?: AccessorPrefix): void;
31
32
  export declare function setSerializedValue(section: Section, key: string, expression: t.Expression): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.118",
3
+ "version": "6.0.120",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",