marko 6.0.131 → 6.0.132

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.
@@ -128,7 +128,7 @@ var AccessorPrefix = /* @__PURE__ */ ((AccessorPrefix4) => {
128
128
  AccessorPrefix4["DynamicHTMLLastChild"] = "DynamicHTMLLastChild:";
129
129
  AccessorPrefix4["EventAttributes"] = "EventAttributes:";
130
130
  AccessorPrefix4["Getter"] = "Getter:";
131
- AccessorPrefix4["LifecycleAbortController"] = "LifecycleAbortController:";
131
+ AccessorPrefix4["Lifecycle"] = "Lifecycle:";
132
132
  AccessorPrefix4["Promise"] = "Promise:";
133
133
  AccessorPrefix4["TagVariableChange"] = "TagVariableChange:";
134
134
  return AccessorPrefix4;
@@ -1118,6 +1118,15 @@ function fromIter(data) {
1118
1118
  }
1119
1119
  return many || one;
1120
1120
  }
1121
+ function* toIter(data) {
1122
+ if (data !== void 0) {
1123
+ if (Array.isArray(data)) {
1124
+ yield* data;
1125
+ } else {
1126
+ yield data;
1127
+ }
1128
+ }
1129
+ }
1121
1130
  function includes(data, item) {
1122
1131
  return data !== void 0 ? Array.isArray(data) ? data.includes(item) : data === item : false;
1123
1132
  }
@@ -1284,7 +1293,7 @@ var AccessorPrefix2 = /* @__PURE__ */ ((AccessorPrefix4) => {
1284
1293
  AccessorPrefix4["DynamicHTMLLastChild"] = "H";
1285
1294
  AccessorPrefix4["EventAttributes"] = "I";
1286
1295
  AccessorPrefix4["Getter"] = "J";
1287
- AccessorPrefix4["LifecycleAbortController"] = "K";
1296
+ AccessorPrefix4["Lifecycle"] = "K";
1288
1297
  AccessorPrefix4["Promise"] = "L";
1289
1298
  AccessorPrefix4["TagVariableChange"] = "M";
1290
1299
  return AccessorPrefix4;
@@ -1886,7 +1895,10 @@ function getSectionRegisterReasons(section) {
1886
1895
  if (section.isBranch) return false;
1887
1896
  const { downstreamBinding } = section;
1888
1897
  if (downstreamBinding) {
1889
- return getAllSerializeReasonsForBinding(downstreamBinding);
1898
+ return getAllSerializeReasonsForBinding(
1899
+ downstreamBinding.binding,
1900
+ downstreamBinding.properties
1901
+ );
1890
1902
  } else if (downstreamBinding === false) {
1891
1903
  return false;
1892
1904
  }
@@ -1963,7 +1975,10 @@ function finalizeParamSerializeReasonGroups(section) {
1963
1975
  }
1964
1976
  function ensureParamReasonGroup(section, reason) {
1965
1977
  const { paramReasonGroups } = section;
1966
- const group = { id: Symbol(), reason };
1978
+ const group = {
1979
+ id: Symbol(getDebugNames(reason)),
1980
+ reason
1981
+ };
1967
1982
  if (paramReasonGroups) {
1968
1983
  const found = findSorted(compareParamGroups, paramReasonGroups, group);
1969
1984
  if (found) return found;
@@ -2240,26 +2255,17 @@ var import_compiler27 = require("@marko/compiler");
2240
2255
  var import_babel_utils17 = require("@marko/compiler/babel-utils");
2241
2256
  var import_path2 = __toESM(require("path"));
2242
2257
 
2243
- // src/translator/util/binding-has-downstream-expressions.ts
2244
- function bindingHasDownstreamExpressions(binding) {
2245
- if (binding.downstreamExpressions.size) return true;
2246
- for (const alias of binding.aliases) {
2247
- if (bindingHasDownstreamExpressions(alias)) return true;
2248
- }
2249
- for (const alias of binding.propertyAliases.values()) {
2250
- if (bindingHasDownstreamExpressions(alias)) return true;
2251
- }
2252
- return false;
2253
- }
2254
-
2255
2258
  // src/translator/util/binding-prop-tree.ts
2256
2259
  function getBindingPropTree(binding) {
2260
+ if (pruneBinding(binding)) {
2261
+ return void 0;
2262
+ }
2257
2263
  const props = {
2258
2264
  binding,
2259
2265
  props: void 0,
2260
2266
  rest: void 0
2261
2267
  };
2262
- if (!binding.downstreamExpressions.size) {
2268
+ if (!binding.reads.size) {
2263
2269
  if (!binding.aliases.size) {
2264
2270
  props.props = {};
2265
2271
  for (const [property, alias] of binding.propertyAliases) {
@@ -2298,12 +2304,20 @@ function hasSupersetExcludeProperties(binding, excludeProperties) {
2298
2304
  }
2299
2305
  return true;
2300
2306
  }
2301
- function getBindingPropTreeProp(propTree, name2) {
2302
- return propTree.props?.[name2] || propTree.rest?.props?.[name2];
2307
+ function getKnownFromPropTree(propTree, name2) {
2308
+ return propTree === true ? true : propTree.props ? propTree.props[name2] || (propTree.rest ? getKnownFromPropTree(propTree.rest, name2) : void 0) : includes(propTree.binding.excludeProperties, name2) ? void 0 : true;
2303
2309
  }
2304
- function getAllBindingPropTreePropKeys(propTree) {
2310
+ function getAllKnownPropNames(propTree) {
2305
2311
  const keys = propTree.props ? Object.keys(propTree.props) : [];
2306
- return propTree.rest?.props ? keys.concat(Object.keys(propTree.rest.props)) : keys;
2312
+ if (propTree.rest?.props) {
2313
+ for (const key of Object.keys(propTree.rest.props)) {
2314
+ keys.push(key);
2315
+ }
2316
+ }
2317
+ return keys;
2318
+ }
2319
+ function hasAllKnownProps(propTree) {
2320
+ return propTree.props && (!propTree.rest || !!propTree.rest.props);
2307
2321
  }
2308
2322
 
2309
2323
  // src/translator/util/entry-builder.ts
@@ -2633,6 +2647,36 @@ function getCompatRuntimeFile() {
2633
2647
  var import_compiler23 = require("@marko/compiler");
2634
2648
  var import_babel_utils16 = require("@marko/compiler/babel-utils");
2635
2649
 
2650
+ // src/translator/util/binding-has-prop.ts
2651
+ function bindingHasProperty(binding, properties) {
2652
+ if (binding.pruned) {
2653
+ return false;
2654
+ } else if (binding.pruned === void 0) {
2655
+ throw new Error("Binding must be pruned before checking properties");
2656
+ }
2657
+ if (binding.reads.size || !properties) {
2658
+ return true;
2659
+ }
2660
+ let property;
2661
+ let rest2;
2662
+ if (Array.isArray(properties)) {
2663
+ property = properties[0];
2664
+ rest2 = properties.length === 2 ? properties[1] : properties.slice(1);
2665
+ } else {
2666
+ property = properties;
2667
+ }
2668
+ const propBinding = binding.propertyAliases.get(property);
2669
+ if (propBinding && bindingHasProperty(propBinding, rest2)) {
2670
+ return true;
2671
+ }
2672
+ for (const alias of binding.aliases) {
2673
+ if (bindingHasProperty(alias, properties)) {
2674
+ return true;
2675
+ }
2676
+ }
2677
+ return false;
2678
+ }
2679
+
2636
2680
  // src/translator/util/get-style-file.ts
2637
2681
  var import_path = __toESM(require("path"));
2638
2682
  function getStyleFile(file) {
@@ -4005,7 +4049,7 @@ function writeHoists(section) {
4005
4049
  import_compiler22.types.variableDeclaration("const", [
4006
4050
  import_compiler22.types.variableDeclarator(
4007
4051
  hoistIdentifier,
4008
- hoistedBinding.downstreamExpressions.size ? callRuntime(
4052
+ hoistedBinding.reads.size ? callRuntime(
4009
4053
  "_resume",
4010
4054
  // TODO: add _hoist_resume runtime
4011
4055
  import_compiler22.types.stringLiteral(
@@ -4020,7 +4064,7 @@ function writeHoists(section) {
4020
4064
  )
4021
4065
  ])
4022
4066
  );
4023
- if (hoistedBinding.downstreamExpressions.size) {
4067
+ if (hoistedBinding.reads.size) {
4024
4068
  addValue(
4025
4069
  hoistedBinding.section,
4026
4070
  void 0,
@@ -4500,7 +4544,7 @@ var dom_default = {
4500
4544
  const walksIdentifier = import_compiler23.types.identifier(domExports.walks);
4501
4545
  const setupIdentifier = import_compiler23.types.identifier(domExports.setup);
4502
4546
  const inputBinding = program.node.params[0].extra?.binding;
4503
- const programInputSignal = inputBinding && bindingHasDownstreamExpressions(inputBinding) ? initValue(inputBinding) : void 0;
4547
+ const programInputSignal = inputBinding && !inputBinding.pruned ? initValue(inputBinding) : void 0;
4504
4548
  let extraDecls = decls;
4505
4549
  const styleFile = getStyleFile(program.hub.file);
4506
4550
  if (styleFile) {
@@ -4534,7 +4578,10 @@ var dom_default = {
4534
4578
  const { walks: walks2, writes: writes2, decls: decls2 } = getSectionMeta(childSection);
4535
4579
  const setup = getSetup(childSection);
4536
4580
  writeSignals(childSection);
4537
- if (!childSection.downstreamBinding || bindingHasDownstreamExpressions(childSection.downstreamBinding)) {
4581
+ if (!childSection.downstreamBinding || bindingHasProperty(
4582
+ childSection.downstreamBinding.binding,
4583
+ childSection.downstreamBinding.properties
4584
+ )) {
4538
4585
  if (getSectionParentIsOwner(childSection)) {
4539
4586
  setBranchRendererArgs(childSection, [
4540
4587
  writes2,
@@ -4660,7 +4707,7 @@ var html_default = {
4660
4707
  const sectionDynamicSubscribers = /* @__PURE__ */ new Set();
4661
4708
  forEach(section.hoisted, (binding) => {
4662
4709
  for (const hoistedBinding of binding.hoists.values()) {
4663
- if (hoistedBinding.downstreamExpressions.size) {
4710
+ if (hoistedBinding.reads.size) {
4664
4711
  getHTMLSectionStatements(hoistedBinding.section).push(
4665
4712
  import_compiler24.types.variableDeclaration("const", [
4666
4713
  import_compiler24.types.variableDeclarator(
@@ -5215,7 +5262,7 @@ var program_default = {
5215
5262
  finalizeReferences();
5216
5263
  const programExtra = program.node.extra;
5217
5264
  const paramsBinding = programExtra.binding;
5218
- if (paramsBinding && bindingHasDownstreamExpressions(paramsBinding)) {
5265
+ if (paramsBinding && !paramsBinding.pruned) {
5219
5266
  programExtra.domExports.params = getBindingPropTree(paramsBinding);
5220
5267
  }
5221
5268
  }
@@ -5408,40 +5455,39 @@ var [getTagDownstreams] = createSectionState(
5408
5455
  () => /* @__PURE__ */ new Map()
5409
5456
  );
5410
5457
  function setTagDownstream(tag, binding) {
5411
- getTagDownstreams(getSection(tag)).set(tag, binding || false);
5458
+ if (binding) {
5459
+ getTagDownstreams(getSection(tag)).set(tag, binding);
5460
+ }
5412
5461
  }
5413
5462
  function finalizeTagDownstreams(section) {
5414
5463
  for (const [tag, binding] of getTagDownstreams(section)) {
5415
- crawlSectionsAndSetBinding(
5416
- tag,
5417
- binding,
5418
- binding ? getBindingPropTree(binding) : void 0
5419
- );
5464
+ crawlSectionsAndSetBinding(tag, binding);
5420
5465
  }
5421
5466
  }
5422
- function crawlSectionsAndSetBinding(tag, binding, tree, skip2) {
5423
- const attrTags2 = tag.node.body.attributeTags ? tag.get("body").get("body") : tag.get("attributeTags");
5467
+ function crawlSectionsAndSetBinding(tag, binding, properties, skip2) {
5424
5468
  if (!skip2) {
5425
5469
  const contentSection = getSectionForBody(tag.get("body"));
5426
5470
  if (contentSection) {
5427
- contentSection.downstreamBinding = tree && (tree.props?.["content"]?.binding || tree.binding) || binding;
5471
+ contentSection.downstreamBinding = {
5472
+ binding,
5473
+ properties: concat(properties, "content")
5474
+ };
5428
5475
  }
5429
5476
  }
5477
+ const attrTagLookup = analyzeAttributeTags(tag);
5478
+ if (!attrTagLookup) return;
5479
+ const attrTags2 = tag.node.body.attributeTags ? tag.get("body").get("body") : tag.get("attributeTags");
5430
5480
  for (const child of attrTags2) {
5431
5481
  if (child.isMarkoTag()) {
5432
5482
  if ((0, import_babel_utils19.isAttributeTag)(child)) {
5433
- if (tree?.props) {
5434
- const attrProp = tree.props[getTagName(child).slice(1)];
5435
- if (attrProp) {
5436
- crawlSectionsAndSetBinding(child, attrProp.binding, attrProp);
5437
- } else {
5438
- crawlSectionsAndSetBinding(child, false, void 0);
5439
- }
5440
- } else {
5441
- crawlSectionsAndSetBinding(child, binding, void 0);
5442
- }
5483
+ const attrTagMeta = attrTagLookup[getTagName(child)];
5484
+ crawlSectionsAndSetBinding(
5485
+ child,
5486
+ binding,
5487
+ concat(properties, attrTagMeta.name)
5488
+ );
5443
5489
  } else {
5444
- crawlSectionsAndSetBinding(child, binding, tree, true);
5490
+ crawlSectionsAndSetBinding(child, binding, properties, true);
5445
5491
  }
5446
5492
  }
5447
5493
  }
@@ -5628,7 +5674,7 @@ var native_tag_default = {
5628
5674
  const valueExtra = attr.value.extra ??= {};
5629
5675
  if (import_compiler33.types.isMarkoAttribute(attr)) {
5630
5676
  if (seen[attr.name]) {
5631
- dropReferences(attr.value);
5677
+ dropNodes(attr.value);
5632
5678
  continue;
5633
5679
  }
5634
5680
  seen[attr.name] = attr;
@@ -6619,7 +6665,7 @@ var for_default = {
6619
6665
  if (isAttrTag) return;
6620
6666
  const bodySection = startSection(tagBody);
6621
6667
  if (!bodySection) {
6622
- dropReferences(getAllTagReferenceNodes(tag.node));
6668
+ dropNodes(getAllTagReferenceNodes(tag.node));
6623
6669
  return;
6624
6670
  }
6625
6671
  const nodeBinding = getOptimizedOnlyChildNodeBinding(tag, tagSection);
@@ -6634,7 +6680,7 @@ var for_default = {
6634
6680
  const keyBinding = paramsBinding.propertyAliases.get(
6635
6681
  forType === "of" ? "1" : "0"
6636
6682
  );
6637
- if (keyBinding) {
6683
+ if (keyBinding && !getKnownAttrValues(tag.node).by) {
6638
6684
  keyBinding.type = 7 /* constant */;
6639
6685
  keyBinding.scopeAccessor = getAccessorProp().LoopKey;
6640
6686
  }
@@ -6944,15 +6990,14 @@ function getBaseArgsInForTag(type, attrs) {
6944
6990
 
6945
6991
  // src/translator/util/translate-attrs.ts
6946
6992
  var contentProps = /* @__PURE__ */ new WeakSet();
6947
- function translateAttrs(tag, propTree, skip2, statements = [], contentKey = "content") {
6948
- const templateExports = propTree && !propTree.rest ? propTree.props : void 0;
6993
+ function translateAttrs(tag, propTree = true, skip2, statements = [], contentKey = "content") {
6949
6994
  const properties = [];
6950
6995
  const attrTagLookup = tag.node.extra?.attributeTags;
6951
6996
  const seen = new Set(skip2);
6952
6997
  if (attrTagLookup) {
6953
6998
  for (const name2 in attrTagLookup) {
6954
6999
  const attrTagMeta = attrTagLookup[name2];
6955
- if (!seen.has(attrTagMeta.name) && usesExport(templateExports, attrTagMeta.name)) {
7000
+ if (!seen.has(attrTagMeta.name) && getKnownFromPropTree(propTree, attrTagMeta.name)) {
6956
7001
  seen.add(attrTagMeta.name);
6957
7002
  if (attrTagMeta.dynamic) {
6958
7003
  statements.push(
@@ -6982,13 +7027,13 @@ function translateAttrs(tag, propTree, skip2, statements = [], contentKey = "con
6982
7027
  i,
6983
7028
  attrTagLookup,
6984
7029
  statements,
6985
- templateExports,
7030
+ propTree,
6986
7031
  contentKey
6987
7032
  );
6988
7033
  } else {
6989
7034
  const translatedAttrTag = translateAttrs(
6990
7035
  child,
6991
- templateExports?.[attrTagMeta.name],
7036
+ getKnownFromPropTree(propTree, attrTagMeta.name),
6992
7037
  void 0,
6993
7038
  statements,
6994
7039
  contentKey
@@ -7030,14 +7075,14 @@ function translateAttrs(tag, propTree, skip2, statements = [], contentKey = "con
7030
7075
  i,
7031
7076
  attrTagLookup,
7032
7077
  statements,
7033
- templateExports,
7078
+ propTree,
7034
7079
  contentKey
7035
7080
  );
7036
7081
  }
7037
7082
  }
7038
7083
  }
7039
7084
  }
7040
- if (!seen.has(contentKey) && usesExport(templateExports, contentKey)) {
7085
+ if (!seen.has(contentKey) && getKnownFromPropTree(propTree, contentKey)) {
7041
7086
  const contentExpression = buildContent(tag.get("body"));
7042
7087
  if (contentExpression) {
7043
7088
  const contentProp = import_compiler36.types.objectProperty(
@@ -7055,7 +7100,7 @@ function translateAttrs(tag, propTree, skip2, statements = [], contentKey = "con
7055
7100
  const { value } = attr;
7056
7101
  if (import_compiler36.types.isMarkoSpreadAttribute(attr)) {
7057
7102
  properties.push(import_compiler36.types.spreadElement(value));
7058
- } else if (!seen.has(attr.name) && usesExport(templateExports, attr.name)) {
7103
+ } else if (!seen.has(attr.name) && getKnownFromPropTree(propTree, attr.name)) {
7059
7104
  seen.add(attr.name);
7060
7105
  properties.push(toObjectProperty(attr.name, value));
7061
7106
  }
@@ -7070,15 +7115,16 @@ function getTranslatedBodyContentProperty(props) {
7070
7115
  }
7071
7116
  }
7072
7117
  }
7073
- function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements, templateExports, contentKey = "content") {
7118
+ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements, propTree, contentKey = "content") {
7074
7119
  const tag = attrTags2[index];
7075
7120
  if (tag.isMarkoTag()) {
7076
7121
  if ((0, import_babel_utils24.isAttributeTag)(tag)) {
7077
7122
  const attrTagMeta = attrTagLookup[getTagName(tag)];
7078
- if (usesExport(templateExports, attrTagMeta.name) && attrTagMeta.dynamic) {
7123
+ const attrTagExport = getKnownFromPropTree(propTree, attrTagMeta.name);
7124
+ if (attrTagExport && attrTagMeta.dynamic) {
7079
7125
  const translatedAttrTag = translateAttrs(
7080
7126
  tag,
7081
- templateExports?.[attrTagMeta.name],
7127
+ attrTagExport,
7082
7128
  void 0,
7083
7129
  statements,
7084
7130
  contentKey
@@ -7120,7 +7166,7 @@ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements
7120
7166
  index,
7121
7167
  attrTagLookup,
7122
7168
  statements,
7123
- templateExports,
7169
+ propTree,
7124
7170
  contentKey
7125
7171
  );
7126
7172
  case "for": {
@@ -7129,7 +7175,7 @@ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements
7129
7175
  index,
7130
7176
  attrTagLookup,
7131
7177
  statements,
7132
- templateExports,
7178
+ propTree,
7133
7179
  contentKey
7134
7180
  );
7135
7181
  }
@@ -7141,14 +7187,14 @@ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements
7141
7187
  function propsToExpression(props) {
7142
7188
  return props.length === 1 && import_compiler36.types.isSpreadElement(props[0]) ? props[0].argument : import_compiler36.types.objectExpression(props);
7143
7189
  }
7144
- function translateForAttrTag(attrTags2, index, attrTagLookup, statements, templateExports, contentKey) {
7190
+ function translateForAttrTag(attrTags2, index, attrTagLookup, statements, propTree, contentKey) {
7145
7191
  const forTag = attrTags2[index];
7146
7192
  const bodyStatements = [];
7147
7193
  addAllAttrTagsAsDynamic(
7148
7194
  forTag,
7149
7195
  attrTagLookup,
7150
7196
  bodyStatements,
7151
- templateExports,
7197
+ propTree,
7152
7198
  contentKey
7153
7199
  );
7154
7200
  statements.push(
@@ -7161,7 +7207,7 @@ function translateForAttrTag(attrTags2, index, attrTagLookup, statements, templa
7161
7207
  );
7162
7208
  return index;
7163
7209
  }
7164
- function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templateExports, contentKey) {
7210
+ function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, propTree, contentKey) {
7165
7211
  const ifTag = attrTags2[index];
7166
7212
  const consequentStatements = [];
7167
7213
  let ifStatement = import_compiler36.types.ifStatement(
@@ -7173,7 +7219,7 @@ function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templat
7173
7219
  ifTag,
7174
7220
  attrTagLookup,
7175
7221
  consequentStatements,
7176
- templateExports,
7222
+ propTree,
7177
7223
  contentKey
7178
7224
  );
7179
7225
  let nextIndex = index + 1;
@@ -7189,7 +7235,7 @@ function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templat
7189
7235
  nextTag,
7190
7236
  attrTagLookup,
7191
7237
  alternateStatements,
7192
- templateExports,
7238
+ propTree,
7193
7239
  contentKey
7194
7240
  );
7195
7241
  if (testValue) {
@@ -7210,7 +7256,7 @@ function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templat
7210
7256
  }
7211
7257
  return nextIndex - 1;
7212
7258
  }
7213
- function addAllAttrTagsAsDynamic(tag, attrTagLookup, statements, templateExports, contentKey) {
7259
+ function addAllAttrTagsAsDynamic(tag, attrTagLookup, statements, propTree, contentKey) {
7214
7260
  const attrTags2 = tag.node.body.attributeTags ? tag.get("body").get("body") : tag.get("attributeTags");
7215
7261
  for (let i = 0; i < attrTags2.length; i++) {
7216
7262
  i = addDynamicAttrTagStatements(
@@ -7218,14 +7264,11 @@ function addAllAttrTagsAsDynamic(tag, attrTagLookup, statements, templateExports
7218
7264
  i,
7219
7265
  attrTagLookup,
7220
7266
  statements,
7221
- templateExports,
7267
+ propTree,
7222
7268
  contentKey
7223
7269
  );
7224
7270
  }
7225
7271
  }
7226
- function usesExport(templateExports, name2) {
7227
- return !templateExports || !!templateExports[name2];
7228
- }
7229
7272
  function findObjectProperty(name2, props) {
7230
7273
  for (const prop of props) {
7231
7274
  if (prop.type === "ObjectProperty") {
@@ -7544,7 +7587,7 @@ function finalizeKnownTags(section) {
7544
7587
  function analyzeParams(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7545
7588
  const inputExpr = {};
7546
7589
  if (!propTree) {
7547
- dropReferences(getAllTagReferenceNodes(tag.node));
7590
+ dropNodes(getAllTagReferenceNodes(tag.node));
7548
7591
  return inputExpr;
7549
7592
  }
7550
7593
  if (!propTree.props || tag.node.arguments?.some((node) => import_compiler37.types.isSpreadElement(node))) {
@@ -7562,7 +7605,7 @@ function analyzeParams(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7562
7605
  for (const arg of tag.node.arguments) {
7563
7606
  const argExport = propTree.props[i];
7564
7607
  if (!argExport) {
7565
- dropReferences(arg);
7608
+ dropNodes(arg);
7566
7609
  continue;
7567
7610
  }
7568
7611
  const argValueExtra = arg.extra ??= {};
@@ -7582,7 +7625,7 @@ function analyzeParams(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7582
7625
  } else {
7583
7626
  const args = tag.node.arguments;
7584
7627
  tag.node.arguments = null;
7585
- dropReferences(getAllTagReferenceNodes(tag.node));
7628
+ dropNodes(getAllTagReferenceNodes(tag.node));
7586
7629
  tag.node.arguments = args;
7587
7630
  }
7588
7631
  return inputExpr;
@@ -7601,10 +7644,12 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7601
7644
  const known = inputExpr.known = {};
7602
7645
  const attrTagLookup = analyzeAttributeTags(tag);
7603
7646
  const seen = /* @__PURE__ */ new Set();
7604
- const unknownReferences = [];
7647
+ const remaining = new Set(getAllKnownPropNames(propTree));
7648
+ const dropReferenceNodes = [];
7649
+ let restReferenceNodes;
7605
7650
  if (attrTagLookup) {
7606
7651
  const nodeReferencesByGroup = /* @__PURE__ */ new Map();
7607
- const analyzeDynamicChildGroup = (group, child) => {
7652
+ const analyzeDynamicAttrTagChildGroup = (group, child) => {
7608
7653
  const referenceNodes = getAllTagReferenceNodes(child.node);
7609
7654
  const groupReferences = nodeReferencesByGroup.get(group);
7610
7655
  if (groupReferences) {
@@ -7624,35 +7669,44 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7624
7669
  if (child.isMarkoTag()) {
7625
7670
  if ((0, import_babel_utils25.isAttributeTag)(child)) {
7626
7671
  const attrTagMeta = attrTagLookup[getTagName(child)];
7627
- const childAttrExports = propTree.props[attrTagMeta.name];
7628
- if (childAttrExports) {
7629
- if (childAttrExports.props && !attrTagMeta.dynamic) {
7630
- known[attrTagMeta.name] = analyzeAttrs(
7631
- rootTagExtra,
7632
- section,
7633
- child,
7634
- childAttrExports,
7635
- rootAttrExprs
7636
- );
7637
- } else {
7638
- analyzeDynamicChildGroup(attrTagMeta.group, child);
7639
- }
7672
+ const childAttrExport = getKnownFromPropTree(
7673
+ propTree,
7674
+ attrTagMeta.name
7675
+ );
7676
+ if (!childAttrExport) {
7677
+ getAllTagReferenceNodes(child.node, dropReferenceNodes);
7678
+ } else if (attrTagMeta.dynamic) {
7679
+ analyzeDynamicAttrTagChildGroup(attrTagMeta.group, child);
7680
+ } else if (childAttrExport === true) {
7681
+ getAllTagReferenceNodes(child.node, restReferenceNodes ||= []);
7682
+ known[attrTagMeta.name] = {
7683
+ value: rootTagExtra
7684
+ };
7685
+ } else if (childAttrExport.props) {
7686
+ remaining.delete(attrTagMeta.name);
7687
+ known[attrTagMeta.name] = analyzeAttrs(
7688
+ rootTagExtra,
7689
+ section,
7690
+ child,
7691
+ childAttrExport,
7692
+ rootAttrExprs
7693
+ );
7640
7694
  } else {
7641
- unknownReferences.push(getAllTagReferenceNodes(child.node));
7695
+ analyzeDynamicAttrTagChildGroup(attrTagMeta.group, child);
7642
7696
  }
7643
7697
  } else {
7644
7698
  const group = child.node.extra.attributeTagGroup;
7645
7699
  let childUsesGroupProp = false;
7646
7700
  for (const name2 of group) {
7647
- if (propTree.props[attrTagLookup[name2].name]) {
7701
+ if (getKnownFromPropTree(propTree, attrTagLookup[name2].name)) {
7648
7702
  childUsesGroupProp = true;
7649
7703
  break;
7650
7704
  }
7651
7705
  }
7652
7706
  if (childUsesGroupProp) {
7653
- analyzeDynamicChildGroup(group, child);
7707
+ analyzeDynamicAttrTagChildGroup(group, child);
7654
7708
  } else {
7655
- unknownReferences.push(getAllTagReferenceNodes(child.node));
7709
+ getAllTagReferenceNodes(child.node, dropReferenceNodes);
7656
7710
  }
7657
7711
  }
7658
7712
  }
@@ -7664,126 +7718,146 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7664
7718
  referenceNodes
7665
7719
  }
7666
7720
  ] of nodeReferencesByGroup) {
7667
- const groupExtra = mergeReferences(section, node, referenceNodes);
7668
- const groupKnownValue = { value: groupExtra };
7669
7721
  let bindings;
7670
- rootAttrExprs.add(groupExtra);
7722
+ let hasRest = false;
7671
7723
  for (const tagName of group) {
7672
7724
  const attrName = tagName.slice(1);
7673
- const templateExportAttr = propTree.props[attrName];
7674
- if (!templateExportAttr) {
7675
- bindings = propTree.binding;
7725
+ const templateExportAttr = getKnownFromPropTree(propTree, attrName);
7726
+ if (templateExportAttr === true) {
7727
+ hasRest = true;
7676
7728
  break;
7729
+ } else {
7730
+ bindings = bindingUtil.add(bindings, templateExportAttr.binding);
7731
+ }
7732
+ }
7733
+ if (hasRest) {
7734
+ const groupKnownValue2 = {
7735
+ value: rootTagExtra
7736
+ };
7737
+ restReferenceNodes ||= [];
7738
+ for (const node2 of referenceNodes) {
7739
+ restReferenceNodes.push(node2);
7677
7740
  }
7678
- bindings = bindingUtil.add(bindings, templateExportAttr.binding);
7741
+ for (const name2 of group) {
7742
+ const attrTagMeta = attrTagLookup[name2];
7743
+ known[attrTagMeta.name] = groupKnownValue2;
7744
+ }
7745
+ continue;
7679
7746
  }
7747
+ const groupExtra = mergeReferences(section, node, referenceNodes);
7748
+ const groupKnownValue = { value: groupExtra };
7749
+ rootAttrExprs.add(groupExtra);
7680
7750
  forEach(bindings, (binding) => {
7681
7751
  setBindingDownstream(binding, groupExtra);
7682
7752
  });
7683
7753
  for (const name2 of group) {
7684
- known[attrTagLookup[name2].name] = groupKnownValue;
7754
+ const attrTagMeta = attrTagLookup[name2];
7755
+ remaining.delete(attrTagMeta.name);
7756
+ known[attrTagMeta.name] = groupKnownValue;
7685
7757
  }
7686
7758
  }
7687
7759
  }
7688
- if (!seen.has("content")) {
7760
+ const contentExport = getKnownFromPropTree(propTree, "content");
7761
+ if (contentExport && !seen.has("content")) {
7689
7762
  const bodySection = getSectionForBody(tag.get("body"));
7690
7763
  if (bodySection) {
7691
7764
  seen.add("content");
7692
- known.content = { value: void 0 };
7765
+ if (contentExport === true) {
7766
+ known.content = { value: rootTagExtra };
7767
+ } else {
7768
+ remaining.delete("content");
7769
+ known.content = { value: void 0 };
7770
+ }
7693
7771
  }
7694
7772
  }
7695
- let knownSpreadBinding;
7773
+ let knownSpread;
7696
7774
  let spreadReferenceNodes;
7697
7775
  const { attributes } = tag.node;
7698
7776
  for (let i = attributes.length; i--; ) {
7699
7777
  const attr = attributes[i];
7700
7778
  if (import_compiler37.types.isMarkoAttribute(attr)) {
7701
- const templateExportAttr = getBindingPropTreeProp(propTree, attr.name);
7779
+ const templateExportAttr = getKnownFromPropTree(propTree, attr.name);
7702
7780
  if (!templateExportAttr || seen.has(attr.name)) {
7703
- unknownReferences.push(attr.value);
7781
+ dropReferenceNodes.push(attr.value);
7704
7782
  continue;
7705
7783
  }
7706
- const attrExtra = attr.value.extra ??= {};
7707
7784
  seen.add(attr.name);
7708
- setBindingDownstream(templateExportAttr.binding, attrExtra);
7709
- if (knownSpreadBinding && !includes(knownSpreadBinding.excludeProperties, attr.name)) {
7710
- const propBinding = getOrCreatePropertyAlias(
7711
- knownSpreadBinding,
7712
- attr.name
7713
- );
7714
- addRead(attrExtra, void 0, propBinding, section);
7785
+ if (spreadReferenceNodes) {
7786
+ spreadReferenceNodes.push(attr.value);
7787
+ } else if (templateExportAttr === true) {
7788
+ (restReferenceNodes ||= []).push(attr.value);
7789
+ known[attr.name] = { value: rootTagExtra };
7790
+ } else {
7791
+ const attrExtra = attr.value.extra ??= {};
7792
+ remaining.delete(attr.name);
7793
+ known[attr.name] = { value: attrExtra };
7794
+ rootAttrExprs.add(attrExtra);
7795
+ setBindingDownstream(templateExportAttr.binding, attrExtra);
7796
+ if (knownSpread && !includes(knownSpread.binding.excludeProperties, attr.name)) {
7797
+ const propBinding = getOrCreatePropertyAlias(
7798
+ knownSpread.binding,
7799
+ attr.name
7800
+ );
7801
+ addRead(attrExtra, void 0, propBinding, section);
7802
+ }
7715
7803
  }
7716
- }
7717
- if (spreadReferenceNodes) {
7804
+ } else if (spreadReferenceNodes) {
7718
7805
  spreadReferenceNodes.push(attr.value);
7719
- } else if (import_compiler37.types.isMarkoSpreadAttribute(attr)) {
7720
- knownSpreadBinding = getSingleKnownSpreadBinding(attributes);
7721
- if (knownSpreadBinding) {
7722
- if (!propTree.rest || propTree.rest.props) {
7723
- dropRead(attr.value.extra);
7724
- }
7806
+ } else {
7807
+ knownSpread = hasAllKnownProps(propTree) ? getSingleKnownSpread(attributes) : void 0;
7808
+ if (knownSpread) {
7809
+ dropNodes(attr.value);
7725
7810
  } else {
7726
- spreadReferenceNodes = [attr.value];
7811
+ (spreadReferenceNodes = restReferenceNodes || []).push(attr.value);
7727
7812
  }
7728
- } else {
7729
- const attrValueExtra = attr.value.extra ??= {};
7730
- known[attr.name] = { value: attrValueExtra };
7731
- rootAttrExprs.add(attrValueExtra);
7732
7813
  }
7733
7814
  }
7734
- if (knownSpreadBinding) {
7735
- for (const prop of getAllBindingPropTreePropKeys(propTree)) {
7736
- if (!seen.has(prop)) {
7737
- const propBinding = getOrCreatePropertyAlias(knownSpreadBinding, prop);
7738
- const propExtra = { section };
7739
- known[prop] = { value: propExtra };
7740
- rootAttrExprs.add(propExtra);
7741
- addRead(propExtra, propExtra, propBinding, section);
7742
- }
7815
+ if (knownSpread) {
7816
+ for (const prop of remaining) {
7817
+ const propBinding = getOrCreatePropertyAlias(knownSpread.binding, prop);
7818
+ const propExtra = { section };
7819
+ const templateExportAttr = getKnownFromPropTree(propTree, prop);
7820
+ known[prop] = { value: propExtra };
7821
+ rootAttrExprs.add(propExtra);
7822
+ addRead(propExtra, propExtra, propBinding, section);
7823
+ setBindingDownstream(
7824
+ templateExportAttr === true ? propTree.rest.binding : templateExportAttr.binding,
7825
+ propExtra
7826
+ );
7743
7827
  }
7744
7828
  } else if (spreadReferenceNodes) {
7745
- setBindingDownstream(
7746
- seen.size ? createBinding(
7747
- generateUid(`${getTagName(tag)}_attrs`),
7748
- propTree.binding.type,
7749
- propTree.binding.section,
7750
- propTree.binding,
7751
- void 0,
7752
- fromIter(seen),
7753
- spreadReferenceNodes[0].loc,
7754
- true
7755
- ) : propTree.binding,
7829
+ if (remaining.size || propTree.rest && !propTree.rest.props) {
7756
7830
  inputExpr.value = mergeReferences(
7757
7831
  section,
7758
7832
  tag.node,
7759
7833
  spreadReferenceNodes
7760
- )
7761
- );
7762
- }
7763
- if (propTree.rest) {
7764
- const restExtra = inputExpr.value = mergeReferences(
7765
- section,
7766
- tag.node,
7767
- unknownReferences.flat()
7768
- );
7769
- setBindingDownstream(propTree.binding, restExtra);
7770
- if (knownSpreadBinding && !propTree.rest.props) {
7771
- addRead(restExtra, void 0, knownSpreadBinding, section);
7834
+ );
7835
+ setBindingDownstream(
7836
+ propTree.rest?.binding || propTree.binding,
7837
+ inputExpr.value
7838
+ );
7839
+ } else {
7840
+ dropNodes(spreadReferenceNodes);
7772
7841
  }
7773
- } else {
7774
- unknownReferences.forEach(dropReferences);
7842
+ } else if (restReferenceNodes) {
7843
+ inputExpr.value = mergeReferences(section, tag.node, restReferenceNodes);
7844
+ setBindingDownstream(propTree.rest.binding, inputExpr.value);
7775
7845
  }
7846
+ dropNodes(dropReferenceNodes);
7776
7847
  return inputExpr;
7777
7848
  }
7778
- function getSingleKnownSpreadBinding(attributes) {
7849
+ function getSingleKnownSpread(attributes) {
7779
7850
  let binding;
7851
+ let extra;
7780
7852
  for (let i = attributes.length; i--; ) {
7781
7853
  const attr = attributes[i];
7782
- if (attr.type === "MarkoSpreadAttribute" ? binding || !(binding = attr.value.extra?.spreadFrom) : binding && !includes(binding.excludeProperties, attr.name)) {
7854
+ if (attr.type === "MarkoSpreadAttribute" ? binding || !(binding = (extra = attr.value.extra)?.spreadFrom) : binding && !includes(binding.excludeProperties, attr.name)) {
7783
7855
  return;
7784
7856
  }
7785
7857
  }
7786
- return binding;
7858
+ if (binding) {
7859
+ return { extra, binding };
7860
+ }
7787
7861
  }
7788
7862
  function writeParamsToSignals(tag, propTree, importAlias, info) {
7789
7863
  if (!propTree.props || tag.node.arguments?.some((node) => import_compiler37.types.isSpreadElement(node))) {
@@ -7855,275 +7929,420 @@ function writeParamsToSignals(tag, propTree, importAlias, info) {
7855
7929
  writeAttrsToSignals(tag, attrPropsTree, `${importAlias}_input`, info);
7856
7930
  }
7857
7931
  }
7858
- function writeAttrsToSignals(tag, propTree, importAlias, info) {
7859
- let translatedAttrs;
7860
- let seen;
7861
- let spreadId;
7862
- if (propTree.props) {
7863
- const attrTagLookup = analyzeAttributeTags(tag);
7864
- seen = /* @__PURE__ */ new Set();
7865
- if (attrTagLookup) {
7866
- const attrTags2 = tag.get("attributeTags");
7867
- const statementsByGroup = /* @__PURE__ */ new Map();
7868
- const translateDynamicAttrTagChildInGroup = (group, index) => {
7869
- const child = attrTags2[index];
7870
- let statements = statementsByGroup.get(group)?.statements;
7871
- if (!statements) {
7872
- statements = [];
7873
- statementsByGroup.set(group, {
7874
- referencedBindings: child.node.extra?.referencedBindings,
7875
- statements
7876
- });
7877
- }
7878
- return addDynamicAttrTagStatements(
7879
- attrTags2,
7880
- index,
7881
- attrTagLookup,
7882
- statements,
7883
- propTree.props
7932
+ function applyAttrObject(tag, propTree, tagInputIdentifier, info) {
7933
+ const referencedBindings = tag.node.extra?.referencedBindings;
7934
+ const translatedAttrs = translateAttrs(
7935
+ tag,
7936
+ true,
7937
+ propTree.rest && new Set(toIter(propTree.rest.binding.excludeProperties))
7938
+ );
7939
+ let translatedProps = propsToExpression(translatedAttrs.properties);
7940
+ if (translatedAttrs.statements.length) {
7941
+ addStatement(
7942
+ "render",
7943
+ info.tagSection,
7944
+ referencedBindings,
7945
+ translatedAttrs.statements
7946
+ );
7947
+ }
7948
+ if ((0, import_babel_utils25.isAttributeTag)(tag)) {
7949
+ const attrTagName = getTagName(tag);
7950
+ const parentTag = tag.parentPath;
7951
+ const repeated = analyzeAttributeTags(parentTag)?.[attrTagName]?.repeated;
7952
+ if (repeated) {
7953
+ let attrTagCallsForTag = (info.attrTagCallsByTag ||= /* @__PURE__ */ new Map()).get(
7954
+ parentTag
7955
+ );
7956
+ if (!attrTagCallsForTag) {
7957
+ info.attrTagCallsByTag.set(parentTag, attrTagCallsForTag = /* @__PURE__ */ new Map());
7958
+ }
7959
+ const attrTagCall = attrTagCallsForTag.get(attrTagName);
7960
+ if (attrTagCall) {
7961
+ attrTagCall.expression = callRuntime(
7962
+ "attrTags",
7963
+ attrTagCall.expression,
7964
+ translatedProps
7884
7965
  );
7885
- };
7886
- for (const attrTagName in attrTagLookup) {
7887
- seen.add(attrTagLookup[attrTagName].name);
7888
- }
7889
- for (let i = 0; i < attrTags2.length; i++) {
7890
- const child = attrTags2[i];
7891
- if (child.isMarkoTag()) {
7892
- if ((0, import_babel_utils25.isAttributeTag)(child)) {
7893
- const attrTagMeta = attrTagLookup[getTagName(child)];
7894
- const childAttrExport = propTree.props[attrTagMeta.name];
7895
- if (childAttrExport) {
7896
- if (attrTagMeta.dynamic) {
7897
- i = translateDynamicAttrTagChildInGroup(attrTagMeta.group, i);
7898
- } else {
7899
- writeAttrsToSignals(
7900
- child,
7901
- childAttrExport,
7902
- `${importAlias}_${attrTagMeta.name}`,
7903
- info
7904
- );
7905
- }
7966
+ return;
7967
+ } else {
7968
+ attrTagCallsForTag.set(
7969
+ attrTagName,
7970
+ translatedProps = import_compiler37.types.parenthesizedExpression(
7971
+ callRuntime("attrTag", translatedProps)
7972
+ )
7973
+ );
7974
+ }
7975
+ } else {
7976
+ translatedProps = callRuntime("attrTag", translatedProps);
7977
+ }
7978
+ }
7979
+ addStatement(
7980
+ "render",
7981
+ info.tagSection,
7982
+ referencedBindings,
7983
+ import_compiler37.types.expressionStatement(
7984
+ import_compiler37.types.callExpression(tagInputIdentifier, [
7985
+ createScopeReadExpression(info.childScopeBinding, info.tagSection),
7986
+ translatedProps
7987
+ ])
7988
+ ),
7989
+ void 0,
7990
+ true
7991
+ );
7992
+ }
7993
+ function translateAttrTag(tag, attrTagMeta, info, statements) {
7994
+ const translatedAttrs = translateAttrs(tag, true, void 0, statements);
7995
+ let translatedProps = propsToExpression(translatedAttrs.properties);
7996
+ const attrTagName = getTagName(tag);
7997
+ const parentTag = tag.parentPath;
7998
+ if (attrTagMeta.repeated) {
7999
+ let attrTagCallsForTag = (info.attrTagCallsByTag ||= /* @__PURE__ */ new Map()).get(
8000
+ parentTag
8001
+ );
8002
+ if (!attrTagCallsForTag) {
8003
+ info.attrTagCallsByTag.set(parentTag, attrTagCallsForTag = /* @__PURE__ */ new Map());
8004
+ }
8005
+ const attrTagCall = attrTagCallsForTag.get(attrTagName);
8006
+ if (attrTagCall) {
8007
+ attrTagCall.expression = callRuntime(
8008
+ "attrTags",
8009
+ attrTagCall.expression,
8010
+ translatedProps
8011
+ );
8012
+ return;
8013
+ } else {
8014
+ attrTagCallsForTag.set(
8015
+ attrTagName,
8016
+ translatedProps = import_compiler37.types.parenthesizedExpression(
8017
+ callRuntime("attrTag", translatedProps)
8018
+ )
8019
+ );
8020
+ }
8021
+ } else {
8022
+ translatedProps = callRuntime("attrTag", translatedProps);
8023
+ }
8024
+ return translatedProps;
8025
+ }
8026
+ function writeAttrsToSignals(tag, propTree, importAlias, info) {
8027
+ if (!propTree.props) {
8028
+ applyAttrObject(
8029
+ tag,
8030
+ propTree,
8031
+ info.getBindingIdentifier(propTree.binding, importAlias),
8032
+ info
8033
+ );
8034
+ return;
8035
+ }
8036
+ const attrTagLookup = analyzeAttributeTags(tag);
8037
+ const seen = /* @__PURE__ */ new Set();
8038
+ const tagReferencedBindings = tag.node.extra?.referencedBindings;
8039
+ const remaining = new Set(getAllKnownPropNames(propTree));
8040
+ let restProps;
8041
+ if (attrTagLookup) {
8042
+ const attrTags2 = tag.get("attributeTags");
8043
+ const statementsByGroup = /* @__PURE__ */ new Map();
8044
+ const translateDynamicAttrTagChildInGroup = (group, index) => {
8045
+ const child = attrTags2[index];
8046
+ let statements = statementsByGroup.get(group)?.statements;
8047
+ if (!statements) {
8048
+ statements = [];
8049
+ statementsByGroup.set(group, {
8050
+ referencedBindings: child.node.extra?.referencedBindings,
8051
+ statements
8052
+ });
8053
+ }
8054
+ return addDynamicAttrTagStatements(
8055
+ attrTags2,
8056
+ index,
8057
+ attrTagLookup,
8058
+ statements,
8059
+ propTree
8060
+ );
8061
+ };
8062
+ for (const attrTagName in attrTagLookup) {
8063
+ seen.add(attrTagLookup[attrTagName].name);
8064
+ }
8065
+ for (let i = 0; i < attrTags2.length; i++) {
8066
+ const child = attrTags2[i];
8067
+ if (child.isMarkoTag()) {
8068
+ if ((0, import_babel_utils25.isAttributeTag)(child)) {
8069
+ const attrTagMeta = attrTagLookup[getTagName(child)];
8070
+ const childAttrExport = getKnownFromPropTree(
8071
+ propTree,
8072
+ attrTagMeta.name
8073
+ );
8074
+ if (!childAttrExport) {
8075
+ } else if (attrTagMeta.dynamic) {
8076
+ i = translateDynamicAttrTagChildInGroup(attrTagMeta.group, i);
8077
+ } else if (childAttrExport === true) {
8078
+ const statements = [];
8079
+ const translatedAttrs = translateAttrTag(
8080
+ child,
8081
+ attrTagMeta,
8082
+ info,
8083
+ statements
8084
+ );
8085
+ addStatement(
8086
+ "render",
8087
+ info.tagSection,
8088
+ tagReferencedBindings,
8089
+ statements
8090
+ );
8091
+ if (translatedAttrs) {
8092
+ (restProps ||= []).push(
8093
+ toObjectProperty(attrTagMeta.name, translatedAttrs)
8094
+ );
7906
8095
  }
7907
- } else if (child.node.extra?.attributeTagGroup) {
7908
- i = translateDynamicAttrTagChildInGroup(
7909
- child.node.extra.attributeTagGroup,
7910
- i
8096
+ } else {
8097
+ remaining.delete(attrTagMeta.name);
8098
+ writeAttrsToSignals(
8099
+ child,
8100
+ childAttrExport,
8101
+ `${importAlias}_${attrTagMeta.name}`,
8102
+ info
7911
8103
  );
7912
8104
  }
8105
+ } else {
8106
+ const group = child.node.extra.attributeTagGroup;
8107
+ let childUsesGroupProp = false;
8108
+ for (const name2 of group) {
8109
+ if (getKnownFromPropTree(propTree, attrTagLookup[name2].name)) {
8110
+ childUsesGroupProp = true;
8111
+ break;
8112
+ }
8113
+ }
8114
+ if (childUsesGroupProp) {
8115
+ i = translateDynamicAttrTagChildInGroup(group, i);
8116
+ } else if (getTagName(child) === "if") {
8117
+ while (++i < attrTags2.length) {
8118
+ const nextTag = attrTags2[i];
8119
+ switch (nextTag.isMarkoTag() && getTagName(nextTag)) {
8120
+ case "else":
8121
+ case "else-if":
8122
+ continue;
8123
+ }
8124
+ i--;
8125
+ break;
8126
+ }
8127
+ }
8128
+ }
8129
+ }
8130
+ }
8131
+ for (const [
8132
+ group,
8133
+ { referencedBindings, statements }
8134
+ ] of statementsByGroup) {
8135
+ const decls = [];
8136
+ let hasRest = false;
8137
+ for (const name2 of group) {
8138
+ const attrTagMeta = attrTagLookup[name2];
8139
+ const childAttrExports = getKnownFromPropTree(
8140
+ propTree,
8141
+ attrTagMeta.name
8142
+ );
8143
+ decls.push(import_compiler37.types.variableDeclarator(getAttrTagIdentifier(attrTagMeta)));
8144
+ if (childAttrExports === true) {
8145
+ hasRest = true;
7913
8146
  }
7914
8147
  }
7915
- for (const [
7916
- group,
7917
- { referencedBindings, statements }
7918
- ] of statementsByGroup) {
7919
- const decls = [];
8148
+ addStatement(
8149
+ "render",
8150
+ info.tagSection,
8151
+ hasRest ? tagReferencedBindings : referencedBindings,
8152
+ [import_compiler37.types.variableDeclaration("let", decls), ...statements]
8153
+ );
8154
+ if (hasRest) {
8155
+ for (const name2 of group) {
8156
+ const attrTagMeta = attrTagLookup[name2];
8157
+ (restProps ||= []).push(
8158
+ toObjectProperty(
8159
+ attrTagMeta.name,
8160
+ getAttrTagIdentifier(attrTagMeta)
8161
+ )
8162
+ );
8163
+ }
8164
+ } else {
7920
8165
  for (const name2 of group) {
7921
8166
  const attrTagMeta = attrTagLookup[name2];
7922
- const childAttrExports = propTree.props[attrTagMeta.name];
7923
- if (!childAttrExports) continue;
7924
- const attrExportIdentifier = info.getBindingIdentifier(
7925
- childAttrExports.binding,
7926
- `${importAlias}_${attrTagMeta.name}`
8167
+ const childAttrExports = getKnownFromPropTree(
8168
+ propTree,
8169
+ attrTagMeta.name
7927
8170
  );
7928
- decls.push(import_compiler37.types.variableDeclarator(getAttrTagIdentifier(attrTagMeta)));
7929
- addStatement("render", info.tagSection, referencedBindings, [
7930
- import_compiler37.types.variableDeclaration("let", decls),
7931
- ...statements
7932
- ]);
8171
+ remaining.delete(attrTagMeta.name);
7933
8172
  addStatement(
7934
8173
  "render",
7935
8174
  info.tagSection,
7936
8175
  referencedBindings,
7937
8176
  import_compiler37.types.expressionStatement(
7938
- import_compiler37.types.callExpression(attrExportIdentifier, [
7939
- createScopeReadExpression(
7940
- info.childScopeBinding,
7941
- info.tagSection
8177
+ import_compiler37.types.callExpression(
8178
+ info.getBindingIdentifier(
8179
+ childAttrExports.binding,
8180
+ `${importAlias}_${attrTagMeta.name}`
7942
8181
  ),
7943
- getAttrTagIdentifier(attrTagMeta)
7944
- ])
8182
+ [
8183
+ createScopeReadExpression(
8184
+ info.childScopeBinding,
8185
+ info.tagSection
8186
+ ),
8187
+ getAttrTagIdentifier(attrTagMeta)
8188
+ ]
8189
+ )
7945
8190
  )
7946
8191
  );
7947
8192
  }
7948
8193
  }
7949
8194
  }
7950
- const bodySection = tag.node.body.extra?.section;
7951
- if (bodySection && !seen.has("content")) {
8195
+ }
8196
+ const contentExport = getKnownFromPropTree(propTree, "content");
8197
+ if (!seen.has("content") && contentExport) {
8198
+ const bodySection = getSectionForBody(tag.get("body"));
8199
+ if (bodySection) {
7952
8200
  seen.add("content");
7953
- if (propTree.props.content) {
7954
- const contentExportIdentifier = info.getBindingIdentifier(
7955
- propTree.props.content.binding,
7956
- `${importAlias}_content`
7957
- );
8201
+ const bodyValue = import_compiler37.types.callExpression(import_compiler37.types.identifier(bodySection.name), [
8202
+ scopeIdentifier
8203
+ ]);
8204
+ if (contentExport === true) {
8205
+ (restProps ||= []).push(toObjectProperty("content", bodyValue));
8206
+ } else {
8207
+ remaining.delete("content");
7958
8208
  addStatement(
7959
8209
  "render",
7960
8210
  info.tagSection,
7961
8211
  void 0,
7962
8212
  // TODO: pretty sure content needs to have the reference group of it's param defaults.
7963
8213
  import_compiler37.types.expressionStatement(
7964
- import_compiler37.types.callExpression(contentExportIdentifier, [
7965
- createScopeReadExpression(
7966
- info.childScopeBinding,
7967
- info.tagSection
8214
+ import_compiler37.types.callExpression(
8215
+ info.getBindingIdentifier(
8216
+ contentExport.binding,
8217
+ `${importAlias}_content`
7968
8218
  ),
7969
- import_compiler37.types.callExpression(import_compiler37.types.identifier(bodySection.name), [
7970
- scopeIdentifier
7971
- ])
7972
- ])
8219
+ [
8220
+ createScopeReadExpression(
8221
+ info.childScopeBinding,
8222
+ info.tagSection
8223
+ ),
8224
+ bodyValue
8225
+ ]
8226
+ )
7973
8227
  ),
7974
8228
  void 0,
7975
8229
  true
7976
8230
  );
7977
8231
  }
7978
8232
  }
7979
- let knownSpreadBinding;
7980
- let spreadProps;
7981
- const staticAttrs = [];
7982
- const { attributes } = tag.node;
7983
- for (let i = attributes.length; i--; ) {
7984
- const attr = attributes[i];
7985
- if (import_compiler37.types.isMarkoAttribute(attr)) {
7986
- if (!getBindingPropTreeProp(propTree, attr.name) || seen.has(attr.name) || spreadProps?.push(toObjectProperty(attr.name, attr.value))) {
7987
- continue;
7988
- }
7989
- seen.add(attr.name);
7990
- staticAttrs.push(attr);
7991
- } else if (spreadProps) {
7992
- spreadProps.push(import_compiler37.types.spreadElement(attr.value));
8233
+ }
8234
+ let knownSpread;
8235
+ let spreadProps;
8236
+ const staticAttrs = [];
8237
+ const { attributes } = tag.node;
8238
+ for (let i = attributes.length; i--; ) {
8239
+ const attr = attributes[i];
8240
+ if (import_compiler37.types.isMarkoAttribute(attr)) {
8241
+ const templateExportAttr = getKnownFromPropTree(propTree, attr.name);
8242
+ if (!templateExportAttr || seen.has(attr.name)) {
8243
+ continue;
8244
+ }
8245
+ seen.add(attr.name);
8246
+ if (spreadProps) {
8247
+ spreadProps.push(toObjectProperty(attr.name, attr.value));
8248
+ } else if (templateExportAttr === true) {
8249
+ (restProps ||= []).push(toObjectProperty(attr.name, attr.value));
7993
8250
  } else {
7994
- knownSpreadBinding = getSingleKnownSpreadBinding(attributes);
7995
- if (!knownSpreadBinding) {
7996
- spreadProps = [import_compiler37.types.spreadElement(attr.value)];
7997
- }
8251
+ staticAttrs.push(attr);
8252
+ }
8253
+ } else if (spreadProps) {
8254
+ spreadProps.push(import_compiler37.types.spreadElement(attr.value));
8255
+ } else {
8256
+ knownSpread = hasAllKnownProps(propTree) ? getSingleKnownSpread(attributes) : void 0;
8257
+ if (!knownSpread) {
8258
+ (spreadProps = restProps || []).push(import_compiler37.types.spreadElement(attr.value));
7998
8259
  }
7999
8260
  }
8000
- for (const attr of staticAttrs.reverse()) {
8001
- const childAttrExports = getBindingPropTreeProp(propTree, attr.name);
8261
+ }
8262
+ for (let i = staticAttrs.length; i--; ) {
8263
+ const attr = staticAttrs[i];
8264
+ const childAttrExports = getKnownFromPropTree(
8265
+ propTree,
8266
+ attr.name
8267
+ );
8268
+ const attrExportIdentifier = info.getBindingIdentifier(
8269
+ childAttrExports.binding,
8270
+ `${importAlias}_${attr.name}`
8271
+ );
8272
+ remaining.delete(attr.name);
8273
+ addStatement(
8274
+ "render",
8275
+ info.tagSection,
8276
+ attr.value.extra?.referencedBindings,
8277
+ import_compiler37.types.expressionStatement(
8278
+ import_compiler37.types.callExpression(attrExportIdentifier, [
8279
+ createScopeReadExpression(info.childScopeBinding, info.tagSection),
8280
+ attr.value
8281
+ // TODO: use spreadBinding property alias after we optimize `in`
8282
+ ])
8283
+ ),
8284
+ void 0,
8285
+ true
8286
+ );
8287
+ }
8288
+ if (knownSpread) {
8289
+ for (const prop of remaining) {
8290
+ const childAttrExports = getKnownFromPropTree(
8291
+ propTree,
8292
+ prop
8293
+ );
8002
8294
  const attrExportIdentifier = info.getBindingIdentifier(
8003
8295
  childAttrExports.binding,
8004
- `${importAlias}_${attr.name}`
8296
+ `${importAlias}_${prop}`
8005
8297
  );
8298
+ const propBinding = knownSpread.binding.propertyAliases.get(prop);
8006
8299
  addStatement(
8007
8300
  "render",
8008
8301
  info.tagSection,
8009
- attr.value.extra?.referencedBindings,
8302
+ propBinding,
8010
8303
  import_compiler37.types.expressionStatement(
8011
8304
  import_compiler37.types.callExpression(attrExportIdentifier, [
8012
8305
  createScopeReadExpression(info.childScopeBinding, info.tagSection),
8013
- // TODO: use spreadBinding property alias after we optimize `in`
8014
- attr.value
8306
+ createScopeReadExpression(propBinding, info.tagSection)
8015
8307
  ])
8016
8308
  ),
8017
8309
  void 0,
8018
8310
  true
8019
8311
  );
8020
8312
  }
8021
- const missing = new Set(getAllBindingPropTreePropKeys(propTree));
8022
- for (const name2 of seen) missing.delete(name2);
8023
- if (missing.size) {
8024
- if (knownSpreadBinding) {
8025
- for (const prop of missing) {
8026
- const childAttrExports = getBindingPropTreeProp(propTree, prop);
8027
- const attrExportIdentifier = info.getBindingIdentifier(
8028
- childAttrExports.binding,
8029
- `${importAlias}_${prop}`
8030
- );
8031
- const propBinding = knownSpreadBinding.propertyAliases.get(prop);
8032
- addStatement(
8033
- "render",
8034
- info.tagSection,
8035
- propBinding,
8036
- import_compiler37.types.expressionStatement(
8037
- import_compiler37.types.callExpression(attrExportIdentifier, [
8038
- createScopeReadExpression(
8039
- info.childScopeBinding,
8040
- info.tagSection
8041
- ),
8042
- createScopeReadExpression(propBinding, info.tagSection)
8043
- ])
8044
- ),
8045
- void 0,
8046
- true
8047
- );
8048
- }
8049
- } else {
8050
- const referencedBindings = tag.node.extra?.referencedBindings;
8051
- if (spreadProps) {
8052
- const spreadExpr = propsToExpression(
8053
- propTree.rest ? (translatedAttrs = translateAttrs(tag, propTree, seen)).properties : spreadProps.reverse()
8054
- );
8055
- if (isSimpleReference(spreadExpr)) {
8056
- spreadId = spreadExpr;
8057
- } else {
8058
- spreadId = generateUidIdentifier(`${importAlias}_spread`);
8059
- if (translatedAttrs) {
8060
- translatedAttrs.properties = [import_compiler37.types.spreadElement(spreadId)];
8061
- }
8062
- addStatement("render", info.tagSection, referencedBindings, [
8063
- import_compiler37.types.variableDeclaration("const", [
8064
- import_compiler37.types.variableDeclarator(spreadId, spreadExpr)
8065
- ])
8066
- ]);
8067
- }
8068
- }
8069
- for (const name2 of missing) {
8070
- const childAttrExports = getBindingPropTreeProp(propTree, name2);
8071
- const attrExportIdentifier = info.getBindingIdentifier(
8072
- childAttrExports.binding,
8073
- `${importAlias}_${name2}`
8074
- );
8075
- addStatement(
8076
- "render",
8077
- info.tagSection,
8078
- spreadProps && referencedBindings,
8079
- import_compiler37.types.expressionStatement(
8080
- import_compiler37.types.callExpression(
8081
- attrExportIdentifier,
8082
- spreadId ? [
8083
- createScopeReadExpression(
8084
- info.childScopeBinding,
8085
- info.tagSection
8086
- ),
8087
- toMemberExpression(import_compiler37.types.cloneNode(spreadId, true), name2)
8088
- ] : [
8089
- createScopeReadExpression(
8090
- info.childScopeBinding,
8091
- info.tagSection
8092
- )
8093
- ]
8094
- )
8095
- )
8096
- );
8097
- }
8098
- }
8099
- }
8100
- }
8101
- if (!propTree.props || propTree.rest && !propTree.rest.props) {
8102
- if (!translatedAttrs) {
8103
- if (propTree.rest) {
8104
- seen ||= /* @__PURE__ */ new Set();
8105
- forEach(
8106
- propTree.rest.binding.excludeProperties,
8107
- (prop) => seen.add(prop)
8108
- );
8109
- }
8110
- translatedAttrs = translateAttrs(tag, propTree.rest, seen);
8313
+ } else if (spreadProps) {
8314
+ const spreadExpr = propsToExpression(spreadProps.reverse());
8315
+ let spreadId = spreadExpr;
8316
+ if (!isSimpleReference(spreadExpr)) {
8317
+ spreadId = generateUidIdentifier(`${importAlias}_spread`);
8318
+ addStatement("render", info.tagSection, tagReferencedBindings, [
8319
+ import_compiler37.types.variableDeclaration("const", [
8320
+ import_compiler37.types.variableDeclarator(spreadId, spreadExpr)
8321
+ ])
8322
+ ]);
8111
8323
  }
8112
- const referencedBindings = tag.node.extra?.referencedBindings;
8113
- const tagInputIdentifier = info.getBindingIdentifier(
8114
- propTree.rest?.binding || propTree.binding,
8115
- propTree.rest ? importAlias + "_$rest" : importAlias
8116
- );
8117
- if (translatedAttrs.statements.length) {
8324
+ for (const name2 of remaining) {
8325
+ const childAttrExports = getKnownFromPropTree(
8326
+ propTree,
8327
+ name2
8328
+ );
8329
+ const attrExportIdentifier = info.getBindingIdentifier(
8330
+ childAttrExports.binding,
8331
+ `${importAlias}_${name2}`
8332
+ );
8118
8333
  addStatement(
8119
8334
  "render",
8120
8335
  info.tagSection,
8121
- referencedBindings,
8122
- translatedAttrs.statements
8336
+ tagReferencedBindings,
8337
+ import_compiler37.types.expressionStatement(
8338
+ import_compiler37.types.callExpression(attrExportIdentifier, [
8339
+ createScopeReadExpression(info.childScopeBinding, info.tagSection),
8340
+ toMemberExpression(import_compiler37.types.cloneNode(spreadId, true), name2)
8341
+ ])
8342
+ )
8123
8343
  );
8124
8344
  }
8125
- let translatedProps = propsToExpression(translatedAttrs.properties);
8126
- if (propTree.rest && spreadId) {
8345
+ if (propTree.rest && !propTree.rest.props) {
8127
8346
  const props = [];
8128
8347
  const restId = import_compiler37.types.identifier(propTree.rest.binding.name);
8129
8348
  forEach(propTree.rest.binding.excludeProperties, (name2) => {
@@ -8139,58 +8358,77 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
8139
8358
  );
8140
8359
  });
8141
8360
  props.push(import_compiler37.types.restElement(restId));
8142
- translatedProps = import_compiler37.types.callExpression(
8143
- import_compiler37.types.arrowFunctionExpression([import_compiler37.types.objectPattern(props)], restId),
8144
- [spreadId]
8361
+ addStatement(
8362
+ "render",
8363
+ info.tagSection,
8364
+ tagReferencedBindings,
8365
+ import_compiler37.types.expressionStatement(
8366
+ import_compiler37.types.callExpression(
8367
+ info.getBindingIdentifier(
8368
+ propTree.rest.binding,
8369
+ importAlias + "_$rest"
8370
+ ),
8371
+ [
8372
+ createScopeReadExpression(
8373
+ info.childScopeBinding,
8374
+ info.tagSection
8375
+ ),
8376
+ import_compiler37.types.callExpression(
8377
+ import_compiler37.types.arrowFunctionExpression([import_compiler37.types.objectPattern(props)], restId),
8378
+ [spreadId]
8379
+ )
8380
+ ]
8381
+ )
8382
+ ),
8383
+ void 0,
8384
+ true
8145
8385
  );
8146
8386
  }
8147
- if ((0, import_babel_utils25.isAttributeTag)(tag)) {
8148
- const attrTagName = getTagName(tag);
8149
- const parentTag = tag.parentPath;
8150
- const repeated = analyzeAttributeTags(parentTag)?.[attrTagName]?.repeated;
8151
- if (repeated) {
8152
- let attrTagCallsForTag = (info.attrTagCallsByTag ||= /* @__PURE__ */ new Map()).get(
8153
- parentTag
8154
- );
8155
- if (!attrTagCallsForTag) {
8156
- info.attrTagCallsByTag.set(
8157
- parentTag,
8158
- attrTagCallsForTag = /* @__PURE__ */ new Map()
8159
- );
8160
- }
8161
- const attrTagCall = attrTagCallsForTag.get(attrTagName);
8162
- if (attrTagCall) {
8163
- attrTagCall.expression = callRuntime(
8164
- "attrTags",
8165
- attrTagCall.expression,
8166
- translatedProps
8167
- );
8168
- return;
8169
- } else {
8170
- attrTagCallsForTag.set(
8171
- attrTagName,
8172
- translatedProps = import_compiler37.types.parenthesizedExpression(
8173
- callRuntime("attrTag", translatedProps)
8174
- )
8175
- );
8176
- }
8177
- } else {
8178
- translatedProps = callRuntime("attrTag", translatedProps);
8179
- }
8387
+ } else {
8388
+ for (const name2 of remaining) {
8389
+ const childAttrExports = getKnownFromPropTree(
8390
+ propTree,
8391
+ name2
8392
+ );
8393
+ const attrExportIdentifier = info.getBindingIdentifier(
8394
+ childAttrExports.binding,
8395
+ `${importAlias}_${name2}`
8396
+ );
8397
+ addStatement(
8398
+ "render",
8399
+ info.tagSection,
8400
+ void 0,
8401
+ import_compiler37.types.expressionStatement(
8402
+ import_compiler37.types.callExpression(attrExportIdentifier, [
8403
+ createScopeReadExpression(info.childScopeBinding, info.tagSection)
8404
+ ])
8405
+ )
8406
+ );
8407
+ }
8408
+ if (propTree.rest && !propTree.rest.props) {
8409
+ addStatement(
8410
+ "render",
8411
+ info.tagSection,
8412
+ tagReferencedBindings,
8413
+ import_compiler37.types.expressionStatement(
8414
+ import_compiler37.types.callExpression(
8415
+ info.getBindingIdentifier(
8416
+ propTree.rest.binding,
8417
+ importAlias + "_$rest"
8418
+ ),
8419
+ [
8420
+ createScopeReadExpression(
8421
+ info.childScopeBinding,
8422
+ info.tagSection
8423
+ ),
8424
+ import_compiler37.types.objectExpression(restProps || [])
8425
+ ]
8426
+ )
8427
+ ),
8428
+ void 0,
8429
+ true
8430
+ );
8180
8431
  }
8181
- addStatement(
8182
- "render",
8183
- info.tagSection,
8184
- referencedBindings,
8185
- import_compiler37.types.expressionStatement(
8186
- import_compiler37.types.callExpression(tagInputIdentifier, [
8187
- createScopeReadExpression(info.childScopeBinding, info.tagSection),
8188
- translatedProps
8189
- ])
8190
- ),
8191
- void 0,
8192
- true
8193
- );
8194
8432
  }
8195
8433
  }
8196
8434
  function mapParamReasonToExpr(exprs, reason) {
@@ -8255,15 +8493,16 @@ function createBinding(name2, type, section, upstreamAlias, property, excludePro
8255
8493
  assignmentSections: void 0,
8256
8494
  excludeProperties,
8257
8495
  sources: void 0,
8496
+ reads: /* @__PURE__ */ new Set(),
8258
8497
  aliases: /* @__PURE__ */ new Set(),
8259
8498
  hoists: /* @__PURE__ */ new Map(),
8260
8499
  propertyAliases: /* @__PURE__ */ new Map(),
8261
8500
  upstreamAlias,
8262
- downstreamExpressions: /* @__PURE__ */ new Set(),
8263
8501
  scopeOffset: void 0,
8264
8502
  scopeAccessor: void 0,
8265
8503
  export: void 0,
8266
- nullable: excludeProperties === void 0
8504
+ nullable: excludeProperties === void 0,
8505
+ pruned: void 0
8267
8506
  };
8268
8507
  if (property) {
8269
8508
  if (declared) upstreamAlias.nullable = false;
@@ -8541,6 +8780,7 @@ function trackAssignment(assignment, binding) {
8541
8780
  true
8542
8781
  );
8543
8782
  idExtra.assignmentTo = changeBinding;
8783
+ changeBinding.pruned = false;
8544
8784
  addReadToExpression(id, changeBinding);
8545
8785
  }
8546
8786
  }
@@ -8588,7 +8828,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
8588
8828
  scope,
8589
8829
  section,
8590
8830
  patternBinding,
8591
- property,
8831
+ void 0,
8592
8832
  excludeProperties
8593
8833
  );
8594
8834
  } else {
@@ -8680,13 +8920,48 @@ function trackReference(referencePath, binding) {
8680
8920
  }
8681
8921
  addReadToExpression(root, reference);
8682
8922
  }
8683
- var [getMergedReferences] = createProgramState(
8684
- () => /* @__PURE__ */ new Map()
8685
- );
8686
8923
  function mergeReferences(section, target, nodes) {
8687
8924
  const targetExtra = target.extra ??= {};
8925
+ const readsByExpression = getReadsByExpression();
8926
+ const fnReadsByExpression = getFunctionReadsByExpression();
8927
+ let reads = readsByExpression.get(targetExtra);
8928
+ let exprFnReads = fnReadsByExpression.get(targetExtra);
8929
+ let { isEffect } = targetExtra;
8930
+ for (const node of nodes) {
8931
+ if (!node) continue;
8932
+ const extra = node.extra ??= {};
8933
+ extra.merged = targetExtra;
8934
+ if (isReferencedExtra(extra)) {
8935
+ const additionalReads = readsByExpression.get(extra);
8936
+ const additionalExprFnReads = fnReadsByExpression.get(extra);
8937
+ isEffect ||= extra.isEffect;
8938
+ if (additionalReads) {
8939
+ forEach(additionalReads, (read) => {
8940
+ read.binding.reads.delete(extra);
8941
+ read.binding.reads.add(targetExtra);
8942
+ });
8943
+ reads = concat(reads, additionalReads);
8944
+ readsByExpression.delete(extra);
8945
+ }
8946
+ if (additionalExprFnReads) {
8947
+ if (exprFnReads) {
8948
+ for (const [key, value] of additionalExprFnReads) {
8949
+ exprFnReads.set(key, value);
8950
+ }
8951
+ } else {
8952
+ fnReadsByExpression.set(
8953
+ targetExtra,
8954
+ exprFnReads = new Map(additionalExprFnReads)
8955
+ );
8956
+ }
8957
+ }
8958
+ } else if (extra?.pruned) {
8959
+ throw new Error("Cannot merged a dropped reference.");
8960
+ }
8961
+ }
8962
+ readsByExpression.set(targetExtra, reads);
8963
+ targetExtra.isEffect = isEffect;
8688
8964
  targetExtra.section = section;
8689
- getMergedReferences().set(target, nodes);
8690
8965
  return targetExtra;
8691
8966
  }
8692
8967
  function compareReferences(a, b) {
@@ -8710,53 +8985,20 @@ function finalizeReferences() {
8710
8985
  const bindings = getBindings();
8711
8986
  const readsByExpression = getReadsByExpression();
8712
8987
  const fnReadsByExpression = getFunctionReadsByExpression();
8713
- const mergedReferences = getMergedReferences();
8714
- if (mergedReferences.size) {
8715
- for (const [target, nodes] of mergedReferences) {
8716
- const targetExtra = target.extra;
8717
- let reads = readsByExpression.get(targetExtra);
8718
- let exprFnReads = fnReadsByExpression.get(targetExtra);
8719
- let { isEffect } = targetExtra;
8720
- for (const node of nodes) {
8721
- const extra = node?.extra;
8722
- if (extra) {
8723
- setCanonicalExtra(extra, targetExtra);
8724
- if (isReferencedExtra(extra)) {
8725
- const additionalReads = readsByExpression.get(extra);
8726
- const additionalExprFnReads = fnReadsByExpression.get(extra);
8727
- isEffect ||= extra.isEffect;
8728
- if (additionalReads) {
8729
- reads = concat(reads, additionalReads);
8730
- readsByExpression.delete(extra);
8731
- }
8732
- if (additionalExprFnReads) {
8733
- if (exprFnReads) {
8734
- for (const [key, value] of additionalExprFnReads) {
8735
- exprFnReads.set(key, value);
8736
- }
8737
- } else {
8738
- fnReadsByExpression.set(
8739
- targetExtra,
8740
- exprFnReads = new Map(additionalExprFnReads)
8741
- );
8742
- }
8743
- }
8744
- }
8745
- }
8746
- }
8747
- readsByExpression.set(targetExtra, reads);
8748
- targetExtra.isEffect = isEffect;
8749
- }
8750
- }
8751
8988
  const intersectionsBySection = /* @__PURE__ */ new Map();
8752
8989
  for (const [expr, reads] of readsByExpression) {
8753
8990
  if (isReferencedExtra(expr)) {
8754
8991
  const { referencedBindings, constantBindings } = resolveReferencedBindings(expr, reads, intersectionsBySection);
8755
8992
  expr.referencedBindings = referencedBindings;
8756
- if (referencedBindings) {
8993
+ if (expr.isEffect) {
8757
8994
  forEach(referencedBindings, (binding) => {
8758
- binding.downstreamExpressions.add(expr);
8995
+ addSerializeReason(binding.section, true, binding);
8996
+ });
8997
+ forEach(constantBindings, (binding) => {
8998
+ addSerializeReason(binding.section, true, binding);
8759
8999
  });
9000
+ }
9001
+ if (referencedBindings) {
8760
9002
  const exprFnReads = fnReadsByExpression.get(expr);
8761
9003
  if (exprFnReads) {
8762
9004
  for (const [fn, fnReads] of exprFnReads) {
@@ -8771,16 +9013,13 @@ function finalizeReferences() {
8771
9013
  }
8772
9014
  }
8773
9015
  }
8774
- if (constantBindings) {
8775
- forEach(constantBindings, (binding) => {
8776
- binding.downstreamExpressions.add(expr);
8777
- });
8778
- }
8779
9016
  }
8780
9017
  }
8781
9018
  for (const binding of bindings) {
8782
- if (binding.type !== 0 /* dom */ && !binding.upstreamAlias) {
8783
- pruneBinding(bindings, binding);
9019
+ if (binding.type !== 0 /* dom */) {
9020
+ if (pruneBinding(binding)) {
9021
+ bindings.delete(binding);
9022
+ }
8784
9023
  }
8785
9024
  }
8786
9025
  forEachSection(finalizeTagDownstreams);
@@ -8803,11 +9042,7 @@ function finalizeReferences() {
8803
9042
  section.bindings,
8804
9043
  getCanonicalBinding(binding)
8805
9044
  );
8806
- for (const {
8807
- referencedBindings,
8808
- isEffect,
8809
- section: section2
8810
- } of binding.downstreamExpressions) {
9045
+ for (const { isEffect, section: section2 } of binding.reads) {
8811
9046
  if (section2 !== binding.section) {
8812
9047
  const canonicalUpstreamAlias = getCanonicalBinding(binding);
8813
9048
  canonicalUpstreamAlias.closureSections = sectionUtil.add(
@@ -8831,12 +9066,6 @@ function finalizeReferences() {
8831
9066
  );
8832
9067
  }
8833
9068
  }
8834
- if (isEffect) {
8835
- forEach(
8836
- referencedBindings,
8837
- (binding2) => addSerializeReason(binding2.section, true, binding2)
8838
- );
8839
- }
8840
9069
  }
8841
9070
  }
8842
9071
  forEachSection((section) => {
@@ -8947,7 +9176,7 @@ function finalizeReferences() {
8947
9176
  finalizeFunctionRegistry();
8948
9177
  const referencedExprs = /* @__PURE__ */ new Set();
8949
9178
  for (const binding of bindings) {
8950
- for (const expr of binding.downstreamExpressions) {
9179
+ for (const expr of binding.reads) {
8951
9180
  referencedExprs.add(expr);
8952
9181
  }
8953
9182
  }
@@ -9006,7 +9235,6 @@ function finalizeReferences() {
9006
9235
  programExtra.returnValueExpr
9007
9236
  );
9008
9237
  }
9009
- mergedReferences.clear();
9010
9238
  readsByExpression.clear();
9011
9239
  fnReadsByExpression.clear();
9012
9240
  }
@@ -9167,12 +9395,10 @@ var [getReadsByExpression] = createProgramState(
9167
9395
  var [getFunctionReadsByExpression] = createProgramState(
9168
9396
  () => /* @__PURE__ */ new Map()
9169
9397
  );
9170
- function addRead(exprExtra, readExtra, binding, section) {
9398
+ function addRead(exprExtra, extra, binding, section) {
9171
9399
  const readsByExpression = getReadsByExpression();
9172
- const read = {
9173
- binding,
9174
- extra: readExtra
9175
- };
9400
+ const read = { binding, extra };
9401
+ binding.reads.add(exprExtra);
9176
9402
  exprExtra.section = section;
9177
9403
  readsByExpression.set(
9178
9404
  exprExtra,
@@ -9180,8 +9406,28 @@ function addRead(exprExtra, readExtra, binding, section) {
9180
9406
  );
9181
9407
  return read;
9182
9408
  }
9183
- function dropRead(exprExtra) {
9184
- getReadsByExpression().delete(exprExtra);
9409
+ function dropNodes(node) {
9410
+ if (Array.isArray(node)) {
9411
+ for (const item of node) {
9412
+ dropExtra(item.extra ??= {});
9413
+ }
9414
+ } else {
9415
+ dropExtra(node.extra ??= {});
9416
+ }
9417
+ }
9418
+ function dropExtra(exprExtra) {
9419
+ if (exprExtra.merged) {
9420
+ throw new Error("Cannot drop a merged reference");
9421
+ }
9422
+ const readsByExpr = getReadsByExpression();
9423
+ const reads = readsByExpr.get(exprExtra);
9424
+ exprExtra.pruned = true;
9425
+ if (reads) {
9426
+ readsByExpr.delete(exprExtra);
9427
+ forEach(reads, (read) => {
9428
+ read.binding.reads.delete(exprExtra);
9429
+ });
9430
+ }
9185
9431
  }
9186
9432
  function addReadToExpression(root, binding) {
9187
9433
  const { node } = root;
@@ -9204,15 +9450,6 @@ function addReadToExpression(root, binding) {
9204
9450
  exprFnReads.set(fnExtra, push(exprFnReads.get(fnExtra), read));
9205
9451
  }
9206
9452
  }
9207
- function dropReferences(node) {
9208
- if (Array.isArray(node)) {
9209
- for (const item of node) {
9210
- (item.extra ??= {}).pruned = true;
9211
- }
9212
- } else {
9213
- (node.extra ??= {}).pruned = true;
9214
- }
9215
- }
9216
9453
  function getCanonicalBinding(binding) {
9217
9454
  const alias = binding.upstreamAlias;
9218
9455
  if (alias && binding.property === void 0 && binding.excludeProperties === void 0) {
@@ -9397,28 +9634,38 @@ function hasNonConstantPropertyAlias(ref) {
9397
9634
  }
9398
9635
  return false;
9399
9636
  }
9400
- function pruneBinding(bindings, binding) {
9401
- let shouldPrune = !binding.downstreamExpressions.size;
9637
+ function pruneBinding(binding) {
9638
+ if (binding.pruned !== void 0) {
9639
+ return binding.pruned;
9640
+ }
9641
+ for (const read of binding.reads) {
9642
+ let upstream = binding.upstreamAlias;
9643
+ while (upstream && !upstream.reads.has(read)) {
9644
+ upstream = upstream.upstreamAlias;
9645
+ }
9646
+ if (upstream) {
9647
+ binding.reads.delete(read);
9648
+ }
9649
+ }
9650
+ let shouldPrune = !binding.reads.size;
9402
9651
  if (binding.hoists.size) {
9403
9652
  shouldPrune = false;
9404
9653
  }
9405
9654
  for (const alias of binding.aliases) {
9406
- if (pruneBinding(bindings, alias)) {
9655
+ if (pruneBinding(alias)) {
9407
9656
  binding.aliases.delete(alias);
9408
9657
  } else if (alias.type !== 7 /* constant */) {
9409
9658
  shouldPrune = false;
9410
9659
  }
9411
9660
  }
9412
9661
  for (const [key, alias] of binding.propertyAliases) {
9413
- if (pruneBinding(bindings, alias)) {
9662
+ if (pruneBinding(alias)) {
9414
9663
  binding.propertyAliases.delete(key);
9415
9664
  } else if (alias.type !== 7 /* constant */) {
9416
9665
  shouldPrune = false;
9417
9666
  }
9418
9667
  }
9419
- if (shouldPrune) {
9420
- bindings.delete(binding);
9421
- }
9668
+ binding.pruned = shouldPrune;
9422
9669
  return shouldPrune;
9423
9670
  }
9424
9671
  function resolveReferencedBindingsInFunction(refs, reads) {
@@ -9604,6 +9851,7 @@ function getCanonicalExtra(extra) {
9604
9851
  }
9605
9852
  var serializeReasonCache = /* @__PURE__ */ new WeakMap();
9606
9853
  function getAllSerializeReasonsForExtra(extra) {
9854
+ if (extra.isEffect) return true;
9607
9855
  let reason = serializeReasonCache.get(extra);
9608
9856
  if (reason === false) return;
9609
9857
  if (reason === void 0) {
@@ -9614,7 +9862,7 @@ function getAllSerializeReasonsForExtra(extra) {
9614
9862
  forEach(extra.downstream, (binding) => {
9615
9863
  reason = mergeSerializeReasons(
9616
9864
  reason,
9617
- getAllSerializeReasonsForBinding(binding)
9865
+ getAllSerializeReasonsForBinding(binding, true)
9618
9866
  );
9619
9867
  });
9620
9868
  }
@@ -9624,32 +9872,34 @@ function getAllSerializeReasonsForExtra(extra) {
9624
9872
  }
9625
9873
  return reason;
9626
9874
  }
9627
- function getAllSerializeReasonsForBinding(binding) {
9875
+ function getAllSerializeReasonsForBinding(binding, properties) {
9628
9876
  let reason = serializeReasonCache.get(binding);
9629
- if (reason === false) return;
9630
9877
  if (reason === void 0) {
9631
9878
  reason = getSerializeReason(binding.section, binding);
9632
9879
  if (reason !== true) {
9633
- if (!reason) {
9634
- serializeReasonCache.set(binding, false);
9635
- }
9636
- for (const expr of binding.downstreamExpressions) {
9637
- reason = expr.isEffect || mergeSerializeReasons(reason, getAllSerializeReasonsForExtra(expr));
9638
- if (reason === true) break;
9880
+ serializeReasonCache.set(binding, reason || false);
9881
+ if (properties !== true && binding.upstreamAlias) {
9882
+ reason = mergeSerializeReasons(
9883
+ reason,
9884
+ getAllSerializeReasonsForBinding(
9885
+ binding.upstreamAlias,
9886
+ binding.property
9887
+ )
9888
+ );
9639
9889
  }
9640
9890
  if (reason !== true) {
9641
- for (const alias of binding.aliases) {
9891
+ for (const expr of binding.reads) {
9642
9892
  reason = mergeSerializeReasons(
9643
9893
  reason,
9644
- getAllSerializeReasonsForBinding(alias)
9894
+ getAllSerializeReasonsForExtra(expr)
9645
9895
  );
9646
9896
  if (reason === true) break;
9647
9897
  }
9648
9898
  if (reason !== true) {
9649
- for (const propBinding of binding.propertyAliases.values()) {
9899
+ for (const alias of binding.aliases) {
9650
9900
  reason = mergeSerializeReasons(
9651
9901
  reason,
9652
- getAllSerializeReasonsForBinding(propBinding)
9902
+ getAllSerializeReasonsForBinding(alias, properties)
9653
9903
  );
9654
9904
  if (reason === true) break;
9655
9905
  }
@@ -9660,11 +9910,56 @@ function getAllSerializeReasonsForBinding(binding) {
9660
9910
  serializeReasonCache.set(binding, reason);
9661
9911
  }
9662
9912
  }
9913
+ if (reason === false) {
9914
+ reason = void 0;
9915
+ }
9916
+ if (properties !== void 0) {
9917
+ if (properties === true) {
9918
+ if (reason !== true) {
9919
+ for (const propBinding of binding.propertyAliases.values()) {
9920
+ reason = mergeSerializeReasons(
9921
+ reason,
9922
+ getAllSerializeReasonsForBinding(propBinding, true)
9923
+ );
9924
+ if (reason === true) break;
9925
+ }
9926
+ }
9927
+ } else {
9928
+ let property;
9929
+ let rest2;
9930
+ if (Array.isArray(properties)) {
9931
+ property = properties[0];
9932
+ rest2 = properties.length === 2 ? properties[1] : properties.slice(1);
9933
+ } else {
9934
+ property = properties;
9935
+ }
9936
+ if (includes(binding.excludeProperties, property)) {
9937
+ reason = void 0;
9938
+ } else {
9939
+ const propBinding = binding.propertyAliases.get(property);
9940
+ if (propBinding) {
9941
+ reason = mergeSerializeReasons(
9942
+ reason,
9943
+ getAllSerializeReasonsForBinding(propBinding, rest2)
9944
+ );
9945
+ }
9946
+ if (reason !== true) {
9947
+ for (const alias of binding.aliases) {
9948
+ const propBinding2 = alias.propertyAliases.get(property);
9949
+ if (propBinding2) {
9950
+ reason = mergeSerializeReasons(
9951
+ reason,
9952
+ getAllSerializeReasonsForBinding(propBinding2, rest2)
9953
+ );
9954
+ if (reason === true) break;
9955
+ }
9956
+ }
9957
+ }
9958
+ }
9959
+ }
9960
+ }
9663
9961
  return reason;
9664
9962
  }
9665
- function setCanonicalExtra(extra, merged) {
9666
- extra.merged = merged;
9667
- }
9668
9963
  function addNumericPropertiesUntil(props, len) {
9669
9964
  let result = props;
9670
9965
  for (let i = len; i--; ) {
@@ -9883,7 +10178,7 @@ var const_default = {
9883
10178
  const valueExtra = evaluate(valueAttr.value);
9884
10179
  const upstreamAlias = import_compiler41.types.isIdentifier(valueAttr.value) ? tag.scope.getBinding(valueAttr.value.name)?.identifier.extra?.binding : void 0;
9885
10180
  if (upstreamAlias) {
9886
- valueExtra.pruned = true;
10181
+ dropNodes(valueAttr.value);
9887
10182
  }
9888
10183
  const binding = trackVarReferences(tag, 5 /* derived */, upstreamAlias);
9889
10184
  if (binding) {
@@ -9994,7 +10289,7 @@ var define_default = {
9994
10289
  const bodySection = startSection(tagBody);
9995
10290
  const varBinding = trackVarReferences(tag, 5 /* derived */);
9996
10291
  if (!varBinding) {
9997
- dropReferences(getAllTagReferenceNodes(tag.node));
10292
+ dropNodes(getAllTagReferenceNodes(tag.node));
9998
10293
  return;
9999
10294
  }
10000
10295
  trackParamsReferences(tagBody, 3 /* param */);
@@ -10011,13 +10306,13 @@ var define_default = {
10011
10306
  }
10012
10307
  if (ref.parent.type === "MarkoTag" && ref.parent.name === ref.node) {
10013
10308
  (ref.parent.extra ??= {}).defineBodySection = bodySection;
10014
- dropReferences(ref.parent.name);
10309
+ dropNodes(ref.parent.name);
10015
10310
  } else {
10016
10311
  allDirectReferences = false;
10017
10312
  }
10018
10313
  }
10019
10314
  if (allDirectReferences) {
10020
- dropReferences(getAllTagReferenceNodes(tag.node));
10315
+ dropNodes(getAllTagReferenceNodes(tag.node));
10021
10316
  return;
10022
10317
  }
10023
10318
  }
@@ -10904,7 +11199,7 @@ var let_default = {
10904
11199
  // src/translator/core/lifecycle.ts
10905
11200
  var import_compiler50 = require("@marko/compiler");
10906
11201
  var import_babel_utils39 = require("@marko/compiler/babel-utils");
10907
- var kRef = Symbol("lifecycle attrs reference");
11202
+ var [getIndex, setIndex] = createSectionState("lifecycleIndex", () => 0);
10908
11203
  var lifecycle_default = {
10909
11204
  analyze(tag) {
10910
11205
  (0, import_babel_utils39.assertNoArgs)(tag);
@@ -10918,12 +11213,7 @@ var lifecycle_default = {
10918
11213
  tag.node,
10919
11214
  getAllTagReferenceNodes(tag.node)
10920
11215
  );
10921
- const binding = tagExtra[kRef] = createBinding(
10922
- generateUid("lifecycle"),
10923
- 5 /* derived */,
10924
- section
10925
- );
10926
- binding.downstreamExpressions.add(tagExtra);
11216
+ tagExtra.isEffect = true;
10927
11217
  if (node.attributes.length === 0) {
10928
11218
  throw tag.get("name").buildCodeFrameError(
10929
11219
  "The [`<lifecycle>` tag](https://markojs.com/docs/reference/core-tag#lifecycle) requires at least one attribute."
@@ -10935,7 +11225,6 @@ var lifecycle_default = {
10935
11225
  "The [`<lifecycle>` tag](https://markojs.com/docs/reference/core-tag#lifecycle) does not support [`...spread` attributes](https://markojs.com/docs/reference/language#spread-attributes)."
10936
11226
  );
10937
11227
  }
10938
- (attr.value.extra ??= {}).isEffect = true;
10939
11228
  }
10940
11229
  (0, import_babel_utils39.getProgram)().node.extra.isInteractive = true;
10941
11230
  },
@@ -10945,16 +11234,17 @@ var lifecycle_default = {
10945
11234
  const section = getSection(tag);
10946
11235
  const tagExtra = node.extra;
10947
11236
  const { referencedBindings } = tagExtra;
10948
- const lifecycleAttrsRef = tagExtra[kRef];
10949
11237
  if (isOutputDOM()) {
10950
11238
  const translatedAttrs = translateAttrs(tag);
11239
+ const index = getIndex(section);
11240
+ setIndex(section, index + 1);
10951
11241
  translatedAttrs.statements.push(
10952
11242
  import_compiler50.types.expressionStatement(
10953
11243
  callRuntime(
10954
11244
  "_lifecycle",
10955
11245
  scopeIdentifier,
10956
- getScopeAccessorLiteral(lifecycleAttrsRef, true),
10957
- propsToExpression(translatedAttrs.properties)
11246
+ propsToExpression(translatedAttrs.properties),
11247
+ index > 0 ? import_compiler50.types.numericLiteral(index) : void 0
10958
11248
  )
10959
11249
  )
10960
11250
  );
@@ -11100,7 +11390,7 @@ var script_default = {
11100
11390
  }
11101
11391
  }
11102
11392
  if (!seenValueAttr) {
11103
- dropReferences(getAllTagReferenceNodes(node));
11393
+ dropNodes(getAllTagReferenceNodes(node));
11104
11394
  }
11105
11395
  },
11106
11396
  translate: {