marko 6.0.0-next.3.85 → 6.0.0

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.
@@ -110,7 +110,7 @@ var attrs_default = {
110
110
 
111
111
  // src/translator/core/await.ts
112
112
  var import_compiler25 = require("@marko/compiler");
113
- var import_babel_utils17 = require("@marko/compiler/babel-utils");
113
+ var import_babel_utils18 = require("@marko/compiler/babel-utils");
114
114
 
115
115
  // src/common/accessor.debug.ts
116
116
  var AccessorPrefix = /* @__PURE__ */ ((AccessorPrefix4) => {
@@ -132,6 +132,7 @@ var AccessorPrefix = /* @__PURE__ */ ((AccessorPrefix4) => {
132
132
  return AccessorPrefix4;
133
133
  })(AccessorPrefix || {});
134
134
  var AccessorProp = /* @__PURE__ */ ((AccessorProp4) => {
135
+ AccessorProp4["Owner"] = "_";
135
136
  AccessorProp4["BranchAccessor"] = "#BranchAccessor";
136
137
  AccessorProp4["CatchContent"] = "#CatchContent";
137
138
  AccessorProp4["PlaceholderBranch"] = "#PlaceholderBranch";
@@ -154,16 +155,85 @@ function evaluate(value) {
154
155
  if (computed) {
155
156
  extra.computed = computed.value;
156
157
  extra.confident = true;
158
+ extra.nullable = computed.value == null;
157
159
  } else {
158
160
  extra.computed = void 0;
159
161
  extra.confident = false;
162
+ extra.nullable = isNullableExpr(value);
160
163
  }
161
164
  }
162
165
  return extra;
163
166
  }
167
+ function isNullableExpr(expr) {
168
+ switch (expr.type) {
169
+ case "ArrayExpression":
170
+ case "ArrowFunctionExpression":
171
+ case "BigIntLiteral":
172
+ case "BinaryExpression":
173
+ case "BooleanLiteral":
174
+ case "ClassExpression":
175
+ case "FunctionExpression":
176
+ case "NewExpression":
177
+ case "NumericLiteral":
178
+ case "ObjectExpression":
179
+ case "RegExpLiteral":
180
+ case "StringLiteral":
181
+ case "TemplateLiteral":
182
+ case "UpdateExpression":
183
+ return false;
184
+ case "AssignmentExpression":
185
+ switch (expr.operator) {
186
+ case "=":
187
+ return isNullableExpr(expr.right);
188
+ case "*=":
189
+ case "/=":
190
+ case "%=":
191
+ case "+=":
192
+ case "-=":
193
+ case "<<=":
194
+ case ">>=":
195
+ case ">>>=":
196
+ case "&=":
197
+ case "^=":
198
+ case "|=":
199
+ case "**=":
200
+ return false;
201
+ case "||=":
202
+ case "??=":
203
+ return isNullableExpr(expr.right) || isNullableExpr(expr.left);
204
+ case "&&=":
205
+ return isNullableExpr(expr.left) && isNullableExpr(expr.right);
206
+ default:
207
+ return true;
208
+ }
209
+ case "AwaitExpression":
210
+ return isNullableExpr(expr.argument);
211
+ case "ConditionalExpression":
212
+ return isNullableExpr(expr.consequent) && isNullableExpr(expr.alternate);
213
+ case "LogicalExpression":
214
+ switch (expr.operator) {
215
+ case "||":
216
+ case "??":
217
+ return isNullableExpr(expr.right) || isNullableExpr(expr.left);
218
+ case "&&":
219
+ return isNullableExpr(expr.left) && isNullableExpr(expr.right);
220
+ default:
221
+ return true;
222
+ }
223
+ case "ParenthesizedExpression":
224
+ return isNullableExpr(expr.expression);
225
+ case "SequenceExpression":
226
+ return isNullableExpr(expr.expressions[expr.expressions.length - 1]);
227
+ case "UnaryExpression":
228
+ return expr.operator === "void";
229
+ default:
230
+ return true;
231
+ }
232
+ }
164
233
 
165
234
  // src/translator/util/references.ts
166
235
  var import_compiler24 = require("@marko/compiler");
236
+ var import_babel_utils17 = require("@marko/compiler/babel-utils");
167
237
 
168
238
  // src/translator/util/for-each-identifier.ts
169
239
  function forEachIdentifier(node, cb) {
@@ -310,6 +380,37 @@ function generateUid(name2 = "") {
310
380
  function generateUidIdentifier(name2) {
311
381
  return import_compiler3.types.identifier(generateUid(name2));
312
382
  }
383
+ var sharedUIDsForFile = /* @__PURE__ */ new WeakMap();
384
+ function getSharedUid(name2) {
385
+ const file = (0, import_babel_utils4.getFile)();
386
+ let sharedUIDs = sharedUIDsForFile.get(file);
387
+ if (!sharedUIDs) {
388
+ const { cache } = file.markoOpts;
389
+ const { filename } = file.opts;
390
+ const cacheKey = `uid-shared:${filename}`;
391
+ sharedUIDs = cache.get(cacheKey);
392
+ if (sharedUIDs) {
393
+ if (isTranslate()) {
394
+ sharedUIDs = new Map(sharedUIDs);
395
+ }
396
+ } else {
397
+ sharedUIDs = /* @__PURE__ */ new Map();
398
+ if (!isTranslate()) {
399
+ cache.set(cacheKey, sharedUIDs);
400
+ }
401
+ }
402
+ sharedUIDsForFile.set(file, sharedUIDs);
403
+ }
404
+ let uniqueName = sharedUIDs.get(name2);
405
+ if (!uniqueName) {
406
+ uniqueName = generateUid(name2);
407
+ sharedUIDs.set(name2, uniqueName);
408
+ }
409
+ return uniqueName;
410
+ }
411
+ function usedSharedUid(name2) {
412
+ return !!sharedUIDsForFile.get((0, import_babel_utils4.getFile)())?.has(name2);
413
+ }
313
414
  function getInitialCounts(file) {
314
415
  const counts = /* @__PURE__ */ new Map();
315
416
  const program = file.path;
@@ -352,6 +453,7 @@ var AccessorPrefix2 = /* @__PURE__ */ ((AccessorPrefix4) => {
352
453
  return AccessorPrefix4;
353
454
  })(AccessorPrefix2 || {});
354
455
  var AccessorProp2 = /* @__PURE__ */ ((AccessorProp4) => {
456
+ AccessorProp4["Owner"] = "_";
355
457
  AccessorProp4["BranchAccessor"] = "a";
356
458
  AccessorProp4["CatchContent"] = "b";
357
459
  AccessorProp4["PlaceholderBranch"] = "c";
@@ -506,18 +608,8 @@ var Sorted = class {
506
608
  findIndex(data, item) {
507
609
  if (data) {
508
610
  if (Array.isArray(data)) {
509
- let max = data.length;
510
- let pos = 0;
511
- while (pos < max) {
512
- const mid = pos + max >>> 1;
513
- const compareResult = this.compare(data[mid], item);
514
- if (compareResult === 0) return mid;
515
- if (compareResult > 0) max = mid;
516
- else pos = mid + 1;
517
- }
518
- return -1;
519
- }
520
- if (this.compare(data, item) === 0) {
611
+ return findIndexSorted(this.compare, data, item);
612
+ } else if (this.compare(data, item) === 0) {
521
613
  return 0;
522
614
  }
523
615
  }
@@ -640,9 +732,41 @@ function find(data, cb) {
640
732
  }
641
733
  }
642
734
  }
643
- function map(data, cb) {
735
+ function toArray(data, cb) {
644
736
  return data ? Array.isArray(data) ? data.map(cb) : [cb(data, 0)] : [];
645
737
  }
738
+ function filterMap(data, cb) {
739
+ if (data) {
740
+ if (Array.isArray(data)) {
741
+ const len = data.length;
742
+ let result;
743
+ let i = 0;
744
+ while (i < len) {
745
+ let item = cb(data[i++]);
746
+ if (item) {
747
+ result = item;
748
+ while (i < len) {
749
+ item = cb(data[i++]);
750
+ if (item) {
751
+ result = [result, item];
752
+ while (i < len) {
753
+ item = cb(data[i++]);
754
+ if (item) {
755
+ result.push(item);
756
+ }
757
+ }
758
+ return result;
759
+ }
760
+ }
761
+ return result;
762
+ }
763
+ }
764
+ return result;
765
+ } else {
766
+ return cb(data);
767
+ }
768
+ }
769
+ }
646
770
  function findSorted(compare, data, item) {
647
771
  let max = data.length;
648
772
  let pos = 0;
@@ -655,6 +779,18 @@ function findSorted(compare, data, item) {
655
779
  else pos = mid + 1;
656
780
  }
657
781
  }
782
+ function findIndexSorted(compare, data, item) {
783
+ let max = data.length;
784
+ let pos = 0;
785
+ while (pos < max) {
786
+ const mid = pos + max >>> 1;
787
+ const compareResult = compare(data[mid], item);
788
+ if (compareResult === 0) return mid;
789
+ if (compareResult > 0) max = mid;
790
+ else pos = mid + 1;
791
+ }
792
+ return -1;
793
+ }
658
794
  function addSorted(compare, data, item) {
659
795
  const len = data.length;
660
796
  let max = len;
@@ -783,9 +919,81 @@ var entry_builder_default = {
783
919
  }
784
920
  };
785
921
 
922
+ // src/translator/util/get-known-attr-values.ts
923
+ function getKnownAttrValues(tag) {
924
+ const attrs2 = {};
925
+ for (const attr2 of tag.attributes) {
926
+ if (attr2.type === "MarkoAttribute") {
927
+ attrs2[attr2.name] = attr2.value;
928
+ }
929
+ }
930
+ return attrs2;
931
+ }
932
+
933
+ // src/translator/util/is-core-tag.ts
934
+ var import_babel_utils7 = require("@marko/compiler/babel-utils");
935
+
936
+ // src/translator/util/get-tag-name.ts
937
+ function getTagName(tag) {
938
+ return tag.node.name.value;
939
+ }
940
+
941
+ // src/translator/util/is-core-tag.ts
942
+ var { taglibId } = runtime_info_default;
943
+ var htmlTaglibId = "marko-html";
944
+ var interopTaglibId = "@marko/translator-interop-class-tags";
945
+ function isCoreTag(tag) {
946
+ if (tag.isMarkoTag()) {
947
+ const tagDef = (0, import_babel_utils7.getTagDef)(tag);
948
+ if (tagDef) {
949
+ switch (tagDef.taglibId) {
950
+ case taglibId:
951
+ case interopTaglibId:
952
+ return true;
953
+ case htmlTaglibId:
954
+ switch (tagDef.name) {
955
+ case "script":
956
+ case "style":
957
+ return true;
958
+ }
959
+ break;
960
+ }
961
+ }
962
+ }
963
+ return false;
964
+ }
965
+ function isCoreTagName(tag, name2) {
966
+ return isCoreTag(tag) && getTagName(tag) === name2;
967
+ }
968
+ function isConditionTag(tag) {
969
+ if (isCoreTag(tag)) {
970
+ switch (getTagName(tag)) {
971
+ case "if":
972
+ case "else-if":
973
+ case "else":
974
+ return true;
975
+ }
976
+ }
977
+ return false;
978
+ }
979
+ function isControlFlowTag(tag) {
980
+ if (isCoreTag(tag)) {
981
+ switch (getTagName(tag)) {
982
+ case "if":
983
+ case "else-if":
984
+ case "else":
985
+ case "for":
986
+ case "await":
987
+ case "try":
988
+ return true;
989
+ }
990
+ }
991
+ return false;
992
+ }
993
+
786
994
  // src/translator/util/runtime.ts
787
995
  var import_compiler7 = require("@marko/compiler");
788
- var import_babel_utils7 = require("@marko/compiler/babel-utils");
996
+ var import_babel_utils8 = require("@marko/compiler/babel-utils");
789
997
 
790
998
  // src/common/attr-tag.ts
791
999
  var rest = false ? Symbol("Attribute Tag") : Symbol();
@@ -1251,7 +1459,7 @@ var pureDOMFunctions = /* @__PURE__ */ new Set([
1251
1459
  function importRuntime(name2) {
1252
1460
  const { output } = getMarkoOpts();
1253
1461
  return toMemberExpression(
1254
- (0, import_babel_utils7.importStar)((0, import_babel_utils7.getFile)(), getRuntimePath(output), "$"),
1462
+ (0, import_babel_utils8.importStar)((0, import_babel_utils8.getFile)(), getRuntimePath(output), "$"),
1255
1463
  name2
1256
1464
  );
1257
1465
  }
@@ -1304,82 +1512,27 @@ function getCompatRuntimeFile() {
1304
1512
  var import_compiler10 = require("@marko/compiler");
1305
1513
  var import_babel_utils11 = require("@marko/compiler/babel-utils");
1306
1514
 
1307
- // src/translator/util/is-core-tag.ts
1308
- var import_babel_utils8 = require("@marko/compiler/babel-utils");
1309
-
1310
- // src/translator/util/get-tag-name.ts
1311
- function getTagName(tag) {
1312
- return tag.node.name.value;
1313
- }
1314
-
1315
- // src/translator/util/is-core-tag.ts
1316
- var { taglibId } = runtime_info_default;
1317
- var htmlTaglibId = "marko-html";
1318
- var interopTaglibId = "@marko/translator-interop-class-tags";
1319
- function isCoreTag(tag) {
1320
- if (tag.isMarkoTag()) {
1321
- const tagDef = (0, import_babel_utils8.getTagDef)(tag);
1322
- if (tagDef) {
1323
- switch (tagDef.taglibId) {
1324
- case taglibId:
1325
- case interopTaglibId:
1326
- return true;
1327
- case htmlTaglibId:
1328
- switch (tagDef.name) {
1329
- case "script":
1330
- case "style":
1331
- return true;
1332
- }
1333
- break;
1334
- }
1335
- }
1336
- }
1337
- return false;
1338
- }
1339
- function isCoreTagName(tag, name2) {
1340
- return isCoreTag(tag) && getTagName(tag) === name2;
1341
- }
1342
- function isConditionTag(tag) {
1343
- if (isCoreTag(tag)) {
1344
- switch (getTagName(tag)) {
1345
- case "if":
1346
- case "else-if":
1347
- case "else":
1348
- return true;
1349
- }
1350
- }
1351
- return false;
1352
- }
1353
- function isControlFlowTag(tag) {
1354
- if (isCoreTag(tag)) {
1355
- switch (getTagName(tag)) {
1356
- case "if":
1357
- case "else-if":
1358
- case "else":
1359
- case "for":
1360
- case "await":
1361
- case "try":
1362
- return true;
1363
- }
1364
- }
1365
- return false;
1366
- }
1367
-
1368
1515
  // src/translator/util/serialize-reasons.ts
1369
1516
  var import_compiler8 = require("@marko/compiler");
1370
- var serializeReasonExprs = /* @__PURE__ */ new WeakMap();
1517
+ var reasonExprs = /* @__PURE__ */ new WeakMap();
1518
+ var keyedReasonExprs = /* @__PURE__ */ new WeakMap();
1371
1519
  var serializeKeysByBinding = /* @__PURE__ */ new WeakMap();
1372
1520
  var serializeKeyBySourceModifier = {};
1373
- function forcePropSerialize(section, extra, prop) {
1374
- forceSerialize(section, getPropSerializeReasonKey(extra, prop));
1521
+ function forceSectionSerialize(section, prop) {
1522
+ if (prop) {
1523
+ forceSerializeKey(section, getSectionPropSerializeReasonKey(section, prop));
1524
+ } else if (section.serializeReason !== true) {
1525
+ reasonExprs.delete(section);
1526
+ section.serializeReason = true;
1527
+ }
1375
1528
  }
1376
1529
  function forceBindingSerialize(section, binding, prefix2) {
1377
- forceSerialize(section, getBindingSerializeReasonKey(binding, prefix2));
1530
+ forceSerializeKey(section, getBindingSerializeReasonKey(binding, prefix2));
1378
1531
  }
1379
- function forceSerialize(section, key) {
1532
+ function forceSerializeKey(section, key) {
1380
1533
  if (section.serializeReasons.get(key) !== true) {
1381
1534
  section.serializeReasons.set(key, true);
1382
- serializeReasonExprs.get(section)?.delete(key);
1535
+ keyedReasonExprs.get(section)?.delete(key);
1383
1536
  }
1384
1537
  }
1385
1538
  function isBindingForceSerialized(section, binding, prefix2) {
@@ -1387,73 +1540,85 @@ function isBindingForceSerialized(section, binding, prefix2) {
1387
1540
  getBindingSerializeReasonKey(binding, prefix2)
1388
1541
  ) === true;
1389
1542
  }
1390
- function addPropSerializeReasonExpr(section, extra, prop, expr) {
1391
- return addSerializeReasonExpr(
1392
- section,
1393
- getPropSerializeReasonKey(extra, prop),
1394
- expr
1395
- );
1543
+ function addSectionSerializeReasonExpr(section, expr, prop) {
1544
+ if (expr) {
1545
+ if (prop) {
1546
+ addKeyedSerializeReasonExpr(
1547
+ section,
1548
+ getSectionPropSerializeReasonKey(section, prop),
1549
+ expr
1550
+ );
1551
+ } else if (section.serializeReason !== true) {
1552
+ if (expr === true) {
1553
+ forceSectionSerialize(section);
1554
+ } else {
1555
+ const existingExpr = reasonExprs.get(section);
1556
+ reasonExprs.set(
1557
+ section,
1558
+ existingExpr ? concat(existingExpr, expr) : expr
1559
+ );
1560
+ }
1561
+ }
1562
+ }
1396
1563
  }
1397
1564
  function addBindingSerializeReasonExpr(section, binding, expr, prefix2) {
1398
- return addSerializeReasonExpr(
1399
- section,
1400
- getBindingSerializeReasonKey(binding, prefix2),
1401
- expr
1402
- );
1403
- }
1404
- function addSerializeReasonExpr(section, key, expr) {
1565
+ const key = getBindingSerializeReasonKey(binding, prefix2);
1405
1566
  if (expr && section.serializeReasons.get(key) !== true) {
1406
- if (expr === true) {
1407
- forceSerialize(section, key);
1567
+ addKeyedSerializeReasonExpr(section, key, expr);
1568
+ }
1569
+ }
1570
+ function addKeyedSerializeReasonExpr(section, key, expr) {
1571
+ if (expr === true) {
1572
+ forceSerializeKey(section, key);
1573
+ } else {
1574
+ let existingExpr;
1575
+ let keyedExprs = keyedReasonExprs.get(section);
1576
+ if (keyedExprs) {
1577
+ existingExpr = keyedExprs.get(key);
1408
1578
  } else {
1409
- let existingExpr;
1410
- let exprsByKey = serializeReasonExprs.get(section);
1411
- if (exprsByKey) {
1412
- existingExpr = exprsByKey.get(key);
1413
- } else {
1414
- exprsByKey = /* @__PURE__ */ new Map();
1415
- serializeReasonExprs.set(section, exprsByKey);
1416
- }
1417
- exprsByKey.set(key, existingExpr ? concat(existingExpr, expr) : expr);
1579
+ keyedExprs = /* @__PURE__ */ new Map();
1580
+ keyedReasonExprs.set(section, keyedExprs);
1418
1581
  }
1582
+ keyedExprs.set(key, existingExpr ? concat(existingExpr, expr) : expr);
1419
1583
  }
1420
1584
  }
1421
- function addPropSerializeReasonRef(section, extra, prop, ref) {
1422
- addSerializeReasonRef(section, getPropSerializeReasonKey(extra, prop), ref);
1423
- }
1424
- function addSerializeReasonRef(section, key, ref) {
1585
+ function addSectionSerializeReasonRef(section, ref, prop) {
1425
1586
  if (ref) {
1426
- const existingReason = section.serializeReasons.get(key);
1427
- if (existingReason !== true) {
1428
- if (ref === true) {
1429
- forceSerialize(section, key);
1430
- } else {
1431
- const reason = getSerializeSourcesForRef(ref);
1432
- if (reason === true) {
1433
- forceSerialize(section, key);
1587
+ if (prop) {
1588
+ addKeyedSerializeReasonRef(
1589
+ section,
1590
+ getSectionPropSerializeReasonKey(section, prop),
1591
+ ref
1592
+ );
1593
+ } else {
1594
+ const existingReason = section.serializeReason;
1595
+ if (existingReason !== true) {
1596
+ if (ref === true) {
1597
+ forceSectionSerialize(section);
1434
1598
  } else {
1435
- section.serializeReasons.set(
1436
- key,
1437
- mergeSerializeReasons(existingReason, reason)
1438
- );
1599
+ const reason = getSerializeSourcesForRef(ref);
1600
+ if (reason === true) {
1601
+ forceSectionSerialize(section);
1602
+ } else {
1603
+ section.serializeReason = mergeSerializeReasons(
1604
+ existingReason,
1605
+ reason
1606
+ );
1607
+ }
1439
1608
  }
1440
1609
  }
1441
1610
  }
1442
1611
  }
1443
1612
  }
1444
- function addBindingSerializeReason(section, binding, reason, prefix2) {
1445
- addSerializeReason(
1446
- section,
1447
- getBindingSerializeReasonKey(binding, prefix2),
1448
- reason
1449
- );
1450
- }
1451
- function addSerializeReason(section, key, reason) {
1452
- if (reason) {
1453
- const existingReason = section.serializeReasons.get(key);
1454
- if (existingReason !== true) {
1613
+ function addKeyedSerializeReasonRef(section, key, ref) {
1614
+ const existingReason = section.serializeReasons.get(key);
1615
+ if (existingReason !== true) {
1616
+ if (ref === true) {
1617
+ forceSerializeKey(section, key);
1618
+ } else {
1619
+ const reason = getSerializeSourcesForRef(ref);
1455
1620
  if (reason === true) {
1456
- forceSerialize(section, key);
1621
+ forceSerializeKey(section, key);
1457
1622
  } else {
1458
1623
  section.serializeReasons.set(
1459
1624
  key,
@@ -1463,31 +1628,119 @@ function addSerializeReason(section, key, reason) {
1463
1628
  }
1464
1629
  }
1465
1630
  }
1466
- function getPropSerializeReason(section, extra, prop) {
1467
- return section.serializeReasons.get(getPropSerializeReasonKey(extra, prop));
1631
+ function addSectionSerializeReason(section, reason, prop) {
1632
+ if (reason) {
1633
+ if (prop) {
1634
+ addKeyedSerializeReason(
1635
+ section,
1636
+ getSectionPropSerializeReasonKey(section, prop),
1637
+ reason
1638
+ );
1639
+ } else {
1640
+ const existingReason = section.serializeReason;
1641
+ if (existingReason !== true) {
1642
+ if (reason === true) {
1643
+ forceSectionSerialize(section);
1644
+ } else {
1645
+ section.serializeReason = mergeSerializeReasons(
1646
+ existingReason,
1647
+ reason
1648
+ );
1649
+ }
1650
+ }
1651
+ }
1652
+ }
1653
+ }
1654
+ function addBindingSerializeReason(section, binding, reason, prefix2) {
1655
+ if (reason) {
1656
+ addKeyedSerializeReason(
1657
+ section,
1658
+ getBindingSerializeReasonKey(binding, prefix2),
1659
+ reason
1660
+ );
1661
+ }
1662
+ }
1663
+ function addKeyedSerializeReason(section, key, reason) {
1664
+ const existingReason = section.serializeReasons.get(key);
1665
+ if (existingReason !== true) {
1666
+ if (reason === true) {
1667
+ forceSerializeKey(section, key);
1668
+ } else {
1669
+ section.serializeReasons.set(
1670
+ key,
1671
+ mergeSerializeReasons(existingReason, reason)
1672
+ );
1673
+ }
1674
+ }
1675
+ }
1676
+ function getSectionSerializeReason(section, prop) {
1677
+ return prop ? section.serializeReasons.get(
1678
+ getSectionPropSerializeReasonKey(section, prop)
1679
+ ) : section.serializeReason;
1468
1680
  }
1469
1681
  function getBindingSerializeReason(section, binding, prefix2) {
1470
1682
  return section.serializeReasons.get(
1471
1683
  getBindingSerializeReasonKey(binding, prefix2)
1472
1684
  );
1473
1685
  }
1474
- function getPropSerializeReasonKey(extra, prop) {
1475
- return extra[prop] ||= Symbol(
1476
- typeof prop === "symbol" ? prop.description : prop
1477
- );
1686
+ function getSectionPropSerializeReasonKey(section, prop) {
1687
+ const keys = serializeKeyBySourceModifier[prop] ||= /* @__PURE__ */ new WeakMap();
1688
+ let key = keys.get(section);
1689
+ if (!key) {
1690
+ keys.set(
1691
+ section,
1692
+ key = Symbol(
1693
+ typeof prop === "symbol" ? `Symbol(${prop.description})` : prop
1694
+ )
1695
+ );
1696
+ }
1697
+ return key;
1478
1698
  }
1479
1699
  function getBindingSerializeReasonKey(binding, prefix2) {
1480
1700
  const keys = prefix2 ? serializeKeyBySourceModifier[prefix2] ||= /* @__PURE__ */ new WeakMap() : serializeKeysByBinding;
1481
1701
  let key = keys.get(binding);
1482
1702
  if (!key) {
1483
- keys.set(binding, key = Symbol((prefix2 || "") + binding.name));
1703
+ keys.set(
1704
+ binding,
1705
+ key = Symbol(
1706
+ (prefix2 ? typeof prefix2 === "symbol" ? `Symbol(${prefix2.description})` : prefix2 : "") + binding.name
1707
+ )
1708
+ );
1484
1709
  }
1485
1710
  return key;
1486
1711
  }
1487
- function consumeSerializeReasonExprs(section) {
1488
- const exprs = serializeReasonExprs.get(section);
1489
- serializeReasonExprs.delete(section);
1490
- return exprs;
1712
+ function applySerializeReasonExprs(section) {
1713
+ const keyedExprs = keyedReasonExprs.get(section);
1714
+ if (keyedExprs) {
1715
+ keyedReasonExprs.delete(section);
1716
+ for (const [key, exprs] of keyedExprs) {
1717
+ const reason = getSerializeSourcesForExprs(exprs);
1718
+ if (reason) {
1719
+ section.serializeReasons.set(
1720
+ key,
1721
+ mergeSerializeReasons(section.serializeReasons.get(key), reason)
1722
+ );
1723
+ }
1724
+ }
1725
+ }
1726
+ section.serializeReason = mergeSerializeReasons(
1727
+ section.serializeReason,
1728
+ getSerializeSourcesForExprs(reasonExprs.get(section))
1729
+ );
1730
+ reasonExprs.delete(section);
1731
+ }
1732
+ function finalizeSectionSerializeReasons(section) {
1733
+ let reason = section.serializeReason;
1734
+ if (reason !== true) {
1735
+ for (const [, keyedReason] of section.serializeReasons) {
1736
+ if (keyedReason === true) {
1737
+ reason = true;
1738
+ break;
1739
+ }
1740
+ reason = mergeSerializeReasons(reason, keyedReason);
1741
+ }
1742
+ section.serializeReason = reason;
1743
+ }
1491
1744
  }
1492
1745
  function getSerializeSourcesForExpr(expr) {
1493
1746
  if (isReferencedExtra(expr)) {
@@ -1534,17 +1787,17 @@ function mergeSerializeReasons(a, b) {
1534
1787
  // src/translator/util/state.ts
1535
1788
  var import_babel_utils9 = require("@marko/compiler/babel-utils");
1536
1789
  var createProgramState = (init) => {
1537
- const map2 = /* @__PURE__ */ new WeakMap();
1790
+ const map = /* @__PURE__ */ new WeakMap();
1538
1791
  return [
1539
1792
  () => {
1540
- let state = map2.get((0, import_babel_utils9.getProgram)());
1793
+ let state = map.get((0, import_babel_utils9.getProgram)());
1541
1794
  if (!state) {
1542
- map2.set((0, import_babel_utils9.getProgram)(), state = init());
1795
+ map.set((0, import_babel_utils9.getProgram)(), state = init());
1543
1796
  }
1544
1797
  return state;
1545
1798
  },
1546
1799
  (value) => {
1547
- map2.set((0, import_babel_utils9.getProgram)(), value);
1800
+ map.set((0, import_babel_utils9.getProgram)(), value);
1548
1801
  }
1549
1802
  ];
1550
1803
  };
@@ -1681,7 +1934,6 @@ function analyzeExpressionTagName(name2, extra) {
1681
1934
  }
1682
1935
 
1683
1936
  // src/translator/util/sections.ts
1684
- var kBranchSerializeReason = Symbol("serialize branch reason");
1685
1937
  var sectionUtil = new Sorted(function compareSections(a, b) {
1686
1938
  return a.id - b.id;
1687
1939
  });
@@ -1710,6 +1962,7 @@ function startSection(path5) {
1710
1962
  hoisted: void 0,
1711
1963
  isHoistThrough: void 0,
1712
1964
  assignments: void 0,
1965
+ serializeReason: void 0,
1713
1966
  serializeReasons: /* @__PURE__ */ new Map(),
1714
1967
  content: getContentInfo(path5),
1715
1968
  upstreamExpression: void 0,
@@ -1923,8 +2176,8 @@ function isNativeNode(tag) {
1923
2176
  }
1924
2177
 
1925
2178
  // src/translator/visitors/program/dom.ts
1926
- var import_compiler20 = require("@marko/compiler");
1927
- var import_babel_utils14 = require("@marko/compiler/babel-utils");
2179
+ var import_compiler21 = require("@marko/compiler");
2180
+ var import_babel_utils15 = require("@marko/compiler/babel-utils");
1928
2181
 
1929
2182
  // src/translator/util/get-style-file.ts
1930
2183
  var import_path = __toESM(require("path"));
@@ -1963,23 +2216,12 @@ function escapeRegExp(str) {
1963
2216
  }
1964
2217
 
1965
2218
  // src/translator/util/signals.ts
1966
- var import_compiler19 = require("@marko/compiler");
1967
- var import_babel_utils13 = require("@marko/compiler/babel-utils");
2219
+ var import_compiler20 = require("@marko/compiler");
2220
+ var import_babel_utils14 = require("@marko/compiler/babel-utils");
1968
2221
 
1969
2222
  // src/translator/core/return.ts
1970
- var import_compiler15 = require("@marko/compiler");
1971
- var import_babel_utils12 = require("@marko/compiler/babel-utils");
1972
-
1973
- // src/translator/util/get-known-attr-values.ts
1974
- function getKnownAttrValues(tag) {
1975
- const attrs2 = {};
1976
- for (const attr2 of tag.attributes) {
1977
- if (attr2.type === "MarkoAttribute") {
1978
- attrs2[attr2.name] = attr2.value;
1979
- }
1980
- }
1981
- return attrs2;
1982
- }
2223
+ var import_compiler17 = require("@marko/compiler");
2224
+ var import_babel_utils13 = require("@marko/compiler/babel-utils");
1983
2225
 
1984
2226
  // src/translator/util/get-parent-tag.ts
1985
2227
  function getParentTag(tag) {
@@ -2055,10 +2297,201 @@ function translateByTarget({
2055
2297
  }
2056
2298
 
2057
2299
  // src/translator/util/writer.ts
2058
- var import_compiler14 = require("@marko/compiler");
2300
+ var import_compiler16 = require("@marko/compiler");
2059
2301
 
2060
- // src/translator/util/normalize-string-expression.ts
2302
+ // src/translator/visitors/program/html.ts
2303
+ var import_compiler13 = require("@marko/compiler");
2304
+ var import_babel_utils12 = require("@marko/compiler/babel-utils");
2305
+
2306
+ // src/translator/util/is-static.ts
2307
+ function isStatic(path5) {
2308
+ return path5.isImportDeclaration() || path5.isExportDeclaration() || path5.isMarkoScriptlet({ static: true });
2309
+ }
2310
+
2311
+ // src/translator/util/simplify-fn.ts
2061
2312
  var import_compiler12 = require("@marko/compiler");
2313
+ function simplifyFunction(fn) {
2314
+ switch (fn.type) {
2315
+ case "FunctionDeclaration":
2316
+ case "FunctionExpression":
2317
+ case "ArrowFunctionExpression":
2318
+ return fn;
2319
+ default:
2320
+ return import_compiler12.types.functionExpression(
2321
+ null,
2322
+ fn.params,
2323
+ fn.body,
2324
+ fn.async,
2325
+ fn.generator
2326
+ );
2327
+ }
2328
+ }
2329
+
2330
+ // src/translator/visitors/program/html.ts
2331
+ function getTemplateContentName() {
2332
+ return getSharedUid("content");
2333
+ }
2334
+ function getExprIfSerialized(reason, expr) {
2335
+ return reason ? reason === true ? expr : import_compiler13.types.logicalExpression(
2336
+ "&&",
2337
+ callRuntime(
2338
+ "serializeIf",
2339
+ import_compiler13.types.identifier(getSharedUid("serialize")),
2340
+ import_compiler13.types.numericLiteral(
2341
+ resolveSerializeReasonId(
2342
+ (0, import_babel_utils12.getProgram)().node.extra.inputSerializeReasons,
2343
+ reason
2344
+ )
2345
+ )
2346
+ ),
2347
+ expr
2348
+ ) : void 0;
2349
+ }
2350
+ function getSerializeGuard(reason) {
2351
+ return reason ? reason === true ? import_compiler13.types.numericLiteral(1) : callRuntime(
2352
+ "serializeGuard",
2353
+ import_compiler13.types.identifier(getSharedUid("serialize")),
2354
+ import_compiler13.types.numericLiteral(
2355
+ resolveSerializeReasonId(
2356
+ (0, import_babel_utils12.getProgram)().node.extra.inputSerializeReasons,
2357
+ reason
2358
+ )
2359
+ )
2360
+ ) : void 0;
2361
+ }
2362
+ var html_default = {
2363
+ translate: {
2364
+ exit(program) {
2365
+ flushInto(program);
2366
+ writeHTMLResumeStatements(program);
2367
+ traverseReplace(program.node, "body", replaceNode);
2368
+ const renderContent = [];
2369
+ for (const child of program.get("body")) {
2370
+ if (!isStatic(child)) {
2371
+ renderContent.push(child.node);
2372
+ child.remove();
2373
+ } else if (child.isMarkoScriptlet()) {
2374
+ if (child.node.target && child.node.target !== "server") {
2375
+ child.remove();
2376
+ } else {
2377
+ child.replaceWithMultiple(child.node.body);
2378
+ }
2379
+ }
2380
+ }
2381
+ const serializeId = usedSharedUid("serialize") && getSharedUid("serialize");
2382
+ const contentId = usedSharedUid("content") && getTemplateContentName();
2383
+ const contentFn = import_compiler13.types.arrowFunctionExpression(
2384
+ serializeId ? [import_compiler13.types.identifier("input"), import_compiler13.types.identifier(serializeId)] : [import_compiler13.types.identifier("input")],
2385
+ import_compiler13.types.blockStatement(renderContent)
2386
+ );
2387
+ const exportDefault = import_compiler13.types.exportDefaultDeclaration(
2388
+ callRuntime(
2389
+ "createTemplate",
2390
+ import_compiler13.types.stringLiteral(program.hub.file.metadata.marko.id),
2391
+ contentId ? import_compiler13.types.identifier(contentId) : contentFn
2392
+ )
2393
+ );
2394
+ if (contentId) {
2395
+ program.node.body.push(
2396
+ import_compiler13.types.variableDeclaration("const", [
2397
+ import_compiler13.types.variableDeclarator(import_compiler13.types.identifier(contentId), contentFn)
2398
+ ]),
2399
+ exportDefault
2400
+ );
2401
+ } else {
2402
+ program.node.body.push(exportDefault);
2403
+ }
2404
+ }
2405
+ }
2406
+ };
2407
+ function replaceNode(node, container) {
2408
+ return replaceBindingReadNode(node) || replaceRegisteredFunctionNode(node, container);
2409
+ }
2410
+ function replaceBindingReadNode(node) {
2411
+ switch (node.type) {
2412
+ case "Identifier":
2413
+ case "MemberExpression": {
2414
+ const { extra } = node;
2415
+ if (extra && !(extra.read && !extra.read.binding.declared || extra.binding && !extra.binding.declared)) {
2416
+ return getReadReplacement(node);
2417
+ }
2418
+ }
2419
+ }
2420
+ }
2421
+ function replaceRegisteredFunctionNode(node, container) {
2422
+ switch (node.type) {
2423
+ case "ClassMethod": {
2424
+ const replacement = getRegisteredFnExpression(node);
2425
+ return replacement && import_compiler13.types.classProperty(node.key, replacement);
2426
+ }
2427
+ case "ClassPrivateMethod": {
2428
+ const replacement = getRegisteredFnExpression(node);
2429
+ return replacement && import_compiler13.types.classPrivateProperty(node.key, replacement);
2430
+ }
2431
+ case "ObjectMethod": {
2432
+ const replacement = getRegisteredFnExpression(node);
2433
+ return replacement && import_compiler13.types.objectProperty(node.key, replacement);
2434
+ }
2435
+ case "FunctionDeclaration": {
2436
+ const { extra } = node;
2437
+ if (isRegisteredFnExtra(extra)) {
2438
+ let registeredFnDeclarations = registeredFnDeclarationsByBody.get(
2439
+ container
2440
+ );
2441
+ if (!registeredFnDeclarations) {
2442
+ registeredFnDeclarationsByBody.set(
2443
+ container,
2444
+ registeredFnDeclarations = []
2445
+ );
2446
+ }
2447
+ registeredFnDeclarations.push({
2448
+ id: node.id.name,
2449
+ registerId: extra.registerId
2450
+ });
2451
+ }
2452
+ break;
2453
+ }
2454
+ case "ArrowFunctionExpression":
2455
+ case "FunctionExpression": {
2456
+ return getRegisteredFnExpression(node);
2457
+ }
2458
+ case "BlockStatement":
2459
+ case "MarkoScriptlet":
2460
+ addRegisteredDeclarations(node.body);
2461
+ break;
2462
+ }
2463
+ }
2464
+ var registeredFnDeclarationsByBody = /* @__PURE__ */ new WeakMap();
2465
+ function addRegisteredDeclarations(body) {
2466
+ const registeredFnDeclarations = registeredFnDeclarationsByBody.get(body);
2467
+ if (registeredFnDeclarations) {
2468
+ for (const { id, registerId } of registeredFnDeclarations) {
2469
+ body.push(
2470
+ import_compiler13.types.expressionStatement(
2471
+ callRuntime(
2472
+ "register",
2473
+ import_compiler13.types.identifier(id),
2474
+ import_compiler13.types.stringLiteral(registerId)
2475
+ )
2476
+ )
2477
+ );
2478
+ }
2479
+ }
2480
+ }
2481
+ function getRegisteredFnExpression(node) {
2482
+ const { extra } = node;
2483
+ if (isRegisteredFnExtra(extra)) {
2484
+ return callRuntime(
2485
+ "register",
2486
+ simplifyFunction(node),
2487
+ import_compiler13.types.stringLiteral(extra.registerId),
2488
+ (extra.referencedBindingsInFunction || extra.referencesScope) && getScopeIdIdentifier(extra.section)
2489
+ );
2490
+ }
2491
+ }
2492
+
2493
+ // src/translator/util/normalize-string-expression.ts
2494
+ var import_compiler14 = require("@marko/compiler");
2062
2495
  function normalizeStringExpression(parts) {
2063
2496
  const strs = [];
2064
2497
  const exprs = [];
@@ -2066,9 +2499,9 @@ function normalizeStringExpression(parts) {
2066
2499
  for (let i = 1; i < parts.length; i++) {
2067
2500
  let content = parts[i];
2068
2501
  if (typeof content === "object") {
2069
- if (import_compiler12.types.isStringLiteral(content)) {
2502
+ if (import_compiler14.types.isStringLiteral(content)) {
2070
2503
  content = content.value;
2071
- } else if (import_compiler12.types.isTemplateLiteral(content)) {
2504
+ } else if (import_compiler14.types.isTemplateLiteral(content)) {
2072
2505
  let nextIndex = i + 1;
2073
2506
  const exprLen = content.expressions.length;
2074
2507
  shiftItems(parts, nextIndex, content.quasis.length + exprLen);
@@ -2092,12 +2525,12 @@ function normalizeStringExpression(parts) {
2092
2525
  return exprs[0];
2093
2526
  }
2094
2527
  strs.push(curStr);
2095
- return import_compiler12.types.templateLiteral(
2096
- strs.map((raw) => import_compiler12.types.templateElement({ raw })),
2528
+ return import_compiler14.types.templateLiteral(
2529
+ strs.map((raw) => import_compiler14.types.templateElement({ raw })),
2097
2530
  exprs
2098
2531
  );
2099
2532
  } else if (curStr) {
2100
- return import_compiler12.types.stringLiteral(curStr);
2533
+ return import_compiler14.types.stringLiteral(curStr);
2101
2534
  }
2102
2535
  }
2103
2536
  function appendLiteral(arr, str) {
@@ -2110,7 +2543,7 @@ function shiftItems(list, start, offset) {
2110
2543
  }
2111
2544
 
2112
2545
  // src/translator/util/walks.ts
2113
- var import_compiler13 = require("@marko/compiler");
2546
+ var import_compiler15 = require("@marko/compiler");
2114
2547
  var [getWalks] = createSectionState(
2115
2548
  "walks",
2116
2549
  () => [""]
@@ -2289,16 +2722,16 @@ function consumeHTML(path5) {
2289
2722
  trailers.length = 0;
2290
2723
  trailers[0] = "";
2291
2724
  if (writeResult && trailerResult) {
2292
- return import_compiler14.types.expressionStatement(
2293
- import_compiler14.types.sequenceExpression([
2725
+ return import_compiler16.types.expressionStatement(
2726
+ import_compiler16.types.sequenceExpression([
2294
2727
  callRuntime("write", writeResult),
2295
2728
  callRuntime("writeTrailers", trailerResult)
2296
2729
  ])
2297
2730
  );
2298
2731
  } else if (writeResult) {
2299
- return import_compiler14.types.expressionStatement(callRuntime("write", writeResult));
2732
+ return import_compiler16.types.expressionStatement(callRuntime("write", writeResult));
2300
2733
  } else if (trailerResult) {
2301
- return import_compiler14.types.expressionStatement(callRuntime("writeTrailers", trailerResult));
2734
+ return import_compiler16.types.expressionStatement(callRuntime("writeTrailers", trailerResult));
2302
2735
  }
2303
2736
  }
2304
2737
  function flushBefore(path5) {
@@ -2324,19 +2757,22 @@ function getSectionMeta(section) {
2324
2757
  writes: normalizeStringExpression([writePrefix, ...writes, writePostfix])
2325
2758
  };
2326
2759
  }
2327
- function markNode(path5, binding) {
2328
- const section = getSection(path5);
2329
- if (binding.type !== 0 /* dom */) {
2760
+ function markNode(path5, nodeBinding, reason) {
2761
+ if (nodeBinding.type !== 0 /* dom */) {
2330
2762
  throw path5.buildCodeFrameError(
2331
2763
  "Tried to mark a node that was not determined to need a mark during analyze."
2332
2764
  );
2333
2765
  }
2334
2766
  if (isOutputHTML()) {
2335
- writeTo(path5)`${callRuntime(
2336
- "markResumeNode",
2337
- getScopeIdIdentifier(section),
2338
- getScopeAccessorLiteral(binding)
2339
- )}`;
2767
+ if (reason) {
2768
+ const section = getSection(path5);
2769
+ writeTo(path5)`${callRuntime(
2770
+ "markResumeNode",
2771
+ getScopeIdIdentifier(section),
2772
+ getScopeAccessorLiteral(nodeBinding),
2773
+ reason === true ? void 0 : getSerializeGuard(reason)
2774
+ )}`;
2775
+ }
2340
2776
  }
2341
2777
  }
2342
2778
 
@@ -2345,14 +2781,14 @@ var tagsWithReturn = /* @__PURE__ */ new WeakSet();
2345
2781
  var [getSectionReturnValueIdentifier, setReturnValueIdentifier] = createSectionState("returnValue");
2346
2782
  var return_default = {
2347
2783
  analyze(tag) {
2348
- (0, import_babel_utils12.assertNoArgs)(tag);
2349
- (0, import_babel_utils12.assertNoVar)(tag);
2350
- (0, import_babel_utils12.assertNoParams)(tag);
2784
+ (0, import_babel_utils13.assertNoArgs)(tag);
2785
+ (0, import_babel_utils13.assertNoVar)(tag);
2786
+ (0, import_babel_utils13.assertNoParams)(tag);
2351
2787
  assertNoBodyContent(tag);
2352
- (0, import_babel_utils12.assertAllowedAttributes)(tag, ["value", "valueChange"]);
2788
+ (0, import_babel_utils13.assertAllowedAttributes)(tag, ["value", "valueChange"]);
2353
2789
  const parentTag = getParentTag(tag);
2354
2790
  if (parentTag) {
2355
- if ((0, import_babel_utils12.isNativeTag)(parentTag)) {
2791
+ if ((0, import_babel_utils13.isNativeTag)(parentTag)) {
2356
2792
  throw tag.get("name").buildCodeFrameError(
2357
2793
  "The `return` tag can not be used in a native tag."
2358
2794
  );
@@ -2369,9 +2805,16 @@ var return_default = {
2369
2805
  } else {
2370
2806
  tagsWithReturn.add(tag.parentPath);
2371
2807
  }
2372
- if (!getKnownAttrValues(tag.node).value) {
2808
+ const attrs2 = getKnownAttrValues(tag.node);
2809
+ if (!attrs2.value) {
2373
2810
  throw tag.get("name").buildCodeFrameError("The `return` tag requires a value.");
2374
2811
  }
2812
+ if (attrs2.valueChange) {
2813
+ forceSectionSerialize(
2814
+ getSection(tag),
2815
+ getAccessorProp().TagVariableChange
2816
+ );
2817
+ }
2375
2818
  },
2376
2819
  translate: translateByTarget({
2377
2820
  html: {
@@ -2380,7 +2823,7 @@ var return_default = {
2380
2823
  const attrs2 = getKnownAttrValues(tag.node);
2381
2824
  flushBefore(tag);
2382
2825
  if (attrs2.valueChange) {
2383
- setSerializedValue(
2826
+ setSectionSerializedValue(
2384
2827
  section,
2385
2828
  getAccessorProp().TagVariableChange,
2386
2829
  attrs2.valueChange
@@ -2390,8 +2833,8 @@ var return_default = {
2390
2833
  const returnId = generateUidIdentifier("return");
2391
2834
  setReturnValueIdentifier(section, returnId);
2392
2835
  tag.replaceWith(
2393
- import_compiler15.types.variableDeclaration("const", [
2394
- import_compiler15.types.variableDeclarator(returnId, attrs2.value)
2836
+ import_compiler17.types.variableDeclaration("const", [
2837
+ import_compiler17.types.variableDeclarator(returnId, attrs2.value)
2395
2838
  ])
2396
2839
  )[0].skip();
2397
2840
  }
@@ -2441,44 +2884,25 @@ var return_default = {
2441
2884
  };
2442
2885
 
2443
2886
  // src/translator/util/get-defined-binding-expression.ts
2444
- var import_compiler16 = require("@marko/compiler");
2887
+ var import_compiler18 = require("@marko/compiler");
2445
2888
  function getDeclaredBindingExpression(binding) {
2446
2889
  if (binding.declared || !binding.upstreamAlias) {
2447
- return import_compiler16.types.identifier(binding.name);
2448
- } else if (binding.property !== void 0) {
2449
- return toMemberExpression(
2450
- getDeclaredBindingExpression(binding.upstreamAlias),
2451
- binding.property,
2452
- binding.upstreamAlias.nullable
2453
- );
2454
- } else {
2455
- return getDeclaredBindingExpression(binding.upstreamAlias);
2456
- }
2457
- }
2458
-
2459
- // src/translator/util/simplify-fn.ts
2460
- var import_compiler17 = require("@marko/compiler");
2461
- function simplifyFunction(fn) {
2462
- switch (fn.type) {
2463
- case "FunctionDeclaration":
2464
- case "FunctionExpression":
2465
- case "ArrowFunctionExpression":
2466
- return fn;
2467
- default:
2468
- return import_compiler17.types.functionExpression(
2469
- null,
2470
- fn.params,
2471
- fn.body,
2472
- fn.async,
2473
- fn.generator
2474
- );
2890
+ return import_compiler18.types.identifier(binding.name);
2891
+ } else if (binding.property !== void 0) {
2892
+ return toMemberExpression(
2893
+ getDeclaredBindingExpression(binding.upstreamAlias),
2894
+ binding.property,
2895
+ binding.upstreamAlias.nullable
2896
+ );
2897
+ } else {
2898
+ return getDeclaredBindingExpression(binding.upstreamAlias);
2475
2899
  }
2476
2900
  }
2477
2901
 
2478
2902
  // src/translator/util/to-first-expression-or-block.ts
2479
- var import_compiler18 = require("@marko/compiler");
2903
+ var import_compiler19 = require("@marko/compiler");
2480
2904
  function toFirstExpressionOrBlock(stmts) {
2481
- if (stmts.length === 1 && import_compiler18.types.isExpressionStatement(stmts[0])) {
2905
+ if (stmts.length === 1 && import_compiler19.types.isExpressionStatement(stmts[0])) {
2482
2906
  const { expression } = stmts[0];
2483
2907
  switch (expression.type) {
2484
2908
  case "ObjectExpression":
@@ -2488,13 +2912,13 @@ function toFirstExpressionOrBlock(stmts) {
2488
2912
  return expression;
2489
2913
  }
2490
2914
  }
2491
- return import_compiler18.types.blockStatement(stmts);
2915
+ return import_compiler19.types.blockStatement(stmts);
2492
2916
  }
2493
2917
  function toParenthesizedExpressionIfNeeded(expr) {
2494
2918
  switch (expr.type) {
2495
2919
  case "ObjectExpression":
2496
2920
  case "AssignmentExpression":
2497
- return import_compiler18.types.parenthesizedExpression(expr);
2921
+ return import_compiler19.types.parenthesizedExpression(expr);
2498
2922
  default:
2499
2923
  return expr;
2500
2924
  }
@@ -2509,22 +2933,13 @@ var [getClosureSignalBuilder, _setClosureSignalBuilder] = createSectionState("qu
2509
2933
  function setClosureSignalBuilder(tag, builder) {
2510
2934
  _setClosureSignalBuilder(getSectionForBody(tag.get("body")), builder);
2511
2935
  }
2512
- var [serializeSectionReason, setSerializeSectionReason] = createSectionState("serializeSectionSources");
2513
- function serializeSectionIfNeeded(section, reason) {
2936
+ var [getSerializedAccessors] = createSectionState("serializedScopeProperties", () => /* @__PURE__ */ new Map());
2937
+ function setSectionSerializedValue(section, prop, expression) {
2938
+ const reason = getSectionSerializeReason(section, prop);
2514
2939
  if (reason) {
2515
- const existingReason = serializeSectionReason(section);
2516
- if (existingReason === true) return;
2517
- if (!existingReason || reason === true) {
2518
- setSerializeSectionReason(section, reason);
2519
- } else {
2520
- setSerializeSectionReason(
2521
- section,
2522
- bindingUtil.union(existingReason, reason)
2523
- );
2524
- }
2940
+ getSerializedAccessors(section).set(prop, { expression, reason });
2525
2941
  }
2526
2942
  }
2527
- var [getSerializedAccessors] = createSectionState("serializedScopeProperties", () => /* @__PURE__ */ new Map());
2528
2943
  function setBindingSerializedValue(section, binding, expression, prefix2) {
2529
2944
  const reason = getBindingSerializeReason(section, binding, prefix2);
2530
2945
  if (reason) {
@@ -2534,7 +2949,9 @@ function setBindingSerializedValue(section, binding, expression, prefix2) {
2534
2949
  );
2535
2950
  }
2536
2951
  }
2952
+ var nonAnalyzedForceSerializedSection = /* @__PURE__ */ new WeakSet();
2537
2953
  function setSerializedValue(section, key, expression) {
2954
+ nonAnalyzedForceSerializedSection.add(section);
2538
2955
  getSerializedAccessors(section).set(key, { expression, reason: true });
2539
2956
  }
2540
2957
  var [getSectionWriteScopeBuilder, setSectionWriteScopeBuilder] = createSectionState(
@@ -2565,17 +2982,17 @@ function getHoistFunctionIdentifier(hoistedBinding) {
2565
2982
  return identifier;
2566
2983
  }
2567
2984
  var unimplementedBuild = () => {
2568
- return import_compiler19.types.stringLiteral("SIGNAL NOT INITIALIZED");
2985
+ return import_compiler20.types.stringLiteral("SIGNAL NOT INITIALIZED");
2569
2986
  };
2570
2987
  function getSignal(section, referencedBindings, name2 = generateSignalName(referencedBindings)) {
2571
2988
  const signals = getSignals(section);
2572
2989
  let signal = signals.get(referencedBindings);
2573
2990
  if (!signal) {
2574
- const exportName = referencedBindings ? !Array.isArray(referencedBindings) && referencedBindings.section === section && referencedBindings.export : !section.parent && (0, import_babel_utils13.getProgram)().node.extra.domExports?.setup;
2991
+ const exportName = referencedBindings ? !Array.isArray(referencedBindings) && referencedBindings.section === section && referencedBindings.export : !section.parent && (0, import_babel_utils14.getProgram)().node.extra.domExports?.setup;
2575
2992
  signals.set(
2576
2993
  referencedBindings,
2577
2994
  signal = {
2578
- identifier: exportName ? import_compiler19.types.identifier(exportName) : generateUidIdentifier(name2 + section.name.replace("_", "$")),
2995
+ identifier: exportName ? import_compiler20.types.identifier(exportName) : generateUidIdentifier(name2 + section.name.replace("_", "$")),
2579
2996
  referencedBindings,
2580
2997
  section,
2581
2998
  values: [],
@@ -2630,9 +3047,9 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
2630
3047
  const { id, scopeOffset } = intersectionMeta.get(referencedBindings);
2631
3048
  return callRuntime(
2632
3049
  "intersection",
2633
- import_compiler19.types.numericLiteral(id),
3050
+ import_compiler20.types.numericLiteral(id),
2634
3051
  getSignalFn(signal),
2635
- scopeOffset || referencedBindings.length > 2 ? import_compiler19.types.numericLiteral(referencedBindings.length - 1) : void 0,
3052
+ scopeOffset || referencedBindings.length > 2 ? import_compiler20.types.numericLiteral(referencedBindings.length - 1) : void 0,
2636
3053
  scopeOffset && getScopeAccessorLiteral(scopeOffset)
2637
3054
  );
2638
3055
  };
@@ -2644,7 +3061,7 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
2644
3061
  "dynamicClosureRead",
2645
3062
  getScopeAccessorLiteral(referencedBindings),
2646
3063
  render,
2647
- isImmediateOwner(section, referencedBindings) ? void 0 : import_compiler19.types.arrowFunctionExpression(
3064
+ isImmediateOwner(section, referencedBindings) ? void 0 : import_compiler20.types.arrowFunctionExpression(
2648
3065
  [scopeIdentifier],
2649
3066
  getScopeExpression(section, referencedBindings.section)
2650
3067
  )
@@ -2692,7 +3109,7 @@ function getSignalFn(signal) {
2692
3109
  const isValue = isBinding && binding.section === section;
2693
3110
  let canUseCalleeDirectly = !signal.render.length;
2694
3111
  if (isBinding && (signal.renderReferencedBindings || binding.aliases.size || binding.propertyAliases.size)) {
2695
- const valueParam = import_compiler19.types.identifier(binding.name);
3112
+ const valueParam = import_compiler20.types.identifier(binding.name);
2696
3113
  if (binding.loc) {
2697
3114
  valueParam.loc = binding.loc;
2698
3115
  valueParam.start = binding.loc.start.index;
@@ -2704,10 +3121,10 @@ function getSignalFn(signal) {
2704
3121
  for (const alias of binding.aliases) {
2705
3122
  const aliasSignal = getSignal(alias.section, alias);
2706
3123
  signal.render.push(
2707
- import_compiler19.types.expressionStatement(
2708
- import_compiler19.types.callExpression(aliasSignal.identifier, [
3124
+ import_compiler20.types.expressionStatement(
3125
+ import_compiler20.types.callExpression(aliasSignal.identifier, [
2709
3126
  scopeIdentifier,
2710
- import_compiler19.types.identifier(binding.name),
3127
+ import_compiler20.types.identifier(binding.name),
2711
3128
  ...getTranslatedExtraArgs(aliasSignal)
2712
3129
  ])
2713
3130
  )
@@ -2716,11 +3133,11 @@ function getSignalFn(signal) {
2716
3133
  for (const [key, alias] of binding.propertyAliases) {
2717
3134
  const aliasSignal = getSignal(alias.section, alias);
2718
3135
  signal.render.push(
2719
- import_compiler19.types.expressionStatement(
2720
- import_compiler19.types.callExpression(aliasSignal.identifier, [
3136
+ import_compiler20.types.expressionStatement(
3137
+ import_compiler20.types.callExpression(aliasSignal.identifier, [
2721
3138
  scopeIdentifier,
2722
3139
  toMemberExpression(
2723
- import_compiler19.types.identifier(binding.name),
3140
+ import_compiler20.types.identifier(binding.name),
2724
3141
  key,
2725
3142
  binding.nullable
2726
3143
  ),
@@ -2732,8 +3149,8 @@ function getSignalFn(signal) {
2732
3149
  }
2733
3150
  for (const value of signal.values) {
2734
3151
  signal.render.push(
2735
- import_compiler19.types.expressionStatement(
2736
- import_compiler19.types.callExpression(value.signal.identifier, [
3152
+ import_compiler20.types.expressionStatement(
3153
+ import_compiler20.types.callExpression(value.signal.identifier, [
2737
3154
  value.scope,
2738
3155
  value.value,
2739
3156
  ...getTranslatedExtraArgs(value.signal)
@@ -2743,7 +3160,7 @@ function getSignalFn(signal) {
2743
3160
  }
2744
3161
  forEach(signal.intersection, (intersection) => {
2745
3162
  signal.render.push(
2746
- import_compiler19.types.expressionStatement(import_compiler19.types.callExpression(intersection, [scopeIdentifier]))
3163
+ import_compiler20.types.expressionStatement(import_compiler20.types.callExpression(intersection, [scopeIdentifier]))
2747
3164
  );
2748
3165
  });
2749
3166
  if (isValue) {
@@ -2758,8 +3175,8 @@ function getSignalFn(signal) {
2758
3175
  signal.identifier.name + "_closure"
2759
3176
  );
2760
3177
  signal.render.push(
2761
- import_compiler19.types.expressionStatement(
2762
- import_compiler19.types.callExpression(dynamicClosureSignalIdentifier, [
3178
+ import_compiler20.types.expressionStatement(
3179
+ import_compiler20.types.callExpression(dynamicClosureSignalIdentifier, [
2763
3180
  scopeIdentifier
2764
3181
  ])
2765
3182
  )
@@ -2770,8 +3187,8 @@ function getSignalFn(signal) {
2770
3187
  );
2771
3188
  } else {
2772
3189
  signal.render.push(
2773
- import_compiler19.types.expressionStatement(
2774
- import_compiler19.types.callExpression(getSignal(closureSection, binding).identifier, [
3190
+ import_compiler20.types.expressionStatement(
3191
+ import_compiler20.types.callExpression(getSignal(closureSection, binding).identifier, [
2775
3192
  scopeIdentifier
2776
3193
  ])
2777
3194
  )
@@ -2781,8 +3198,8 @@ function getSignalFn(signal) {
2781
3198
  });
2782
3199
  if (dynamicClosureSignalIdentifier) {
2783
3200
  (signal.prependStatements ||= []).push(
2784
- import_compiler19.types.variableDeclaration("const", [
2785
- import_compiler19.types.variableDeclarator(
3201
+ import_compiler20.types.variableDeclaration("const", [
3202
+ import_compiler20.types.variableDeclarator(
2786
3203
  dynamicClosureSignalIdentifier,
2787
3204
  callRuntime("dynamicClosure", ...dynamicClosureArgs)
2788
3205
  )
@@ -2791,17 +3208,17 @@ function getSignalFn(signal) {
2791
3208
  }
2792
3209
  }
2793
3210
  if (signal.effect.length) {
2794
- const effectIdentifier = import_compiler19.types.identifier(`${signal.identifier.name}_effect`);
3211
+ const effectIdentifier = import_compiler20.types.identifier(`${signal.identifier.name}_effect`);
2795
3212
  signal.render.push(
2796
- import_compiler19.types.expressionStatement(
2797
- import_compiler19.types.callExpression(effectIdentifier, [scopeIdentifier])
3213
+ import_compiler20.types.expressionStatement(
3214
+ import_compiler20.types.callExpression(effectIdentifier, [scopeIdentifier])
2798
3215
  )
2799
3216
  );
2800
3217
  }
2801
3218
  if (isIntersection && signal.renderReferencedBindings) {
2802
3219
  signal.render.unshift(
2803
- import_compiler19.types.variableDeclaration("const", [
2804
- import_compiler19.types.variableDeclarator(
3220
+ import_compiler20.types.variableDeclaration("const", [
3221
+ import_compiler20.types.variableDeclarator(
2805
3222
  createScopeReadPattern(section, signal.renderReferencedBindings),
2806
3223
  scopeIdentifier
2807
3224
  )
@@ -2830,7 +3247,7 @@ function getSignalFn(signal) {
2830
3247
  }
2831
3248
  }
2832
3249
  }
2833
- return import_compiler19.types.arrowFunctionExpression(params, import_compiler19.types.blockStatement(signal.render));
3250
+ return import_compiler20.types.arrowFunctionExpression(params, import_compiler20.types.blockStatement(signal.render));
2834
3251
  }
2835
3252
  var hasTranslatedExtraArgs = /* @__PURE__ */ new WeakSet();
2836
3253
  var emptyExtraArgs = [];
@@ -2875,19 +3292,19 @@ function replaceNullishAndEmptyFunctionsWith0(args) {
2875
3292
  for (let i = args.length; i--; ) {
2876
3293
  const arg = args[i];
2877
3294
  if (!arg) {
2878
- args[i] = import_compiler19.types.numericLiteral(0);
2879
- } else if (import_compiler19.types.isArrowFunctionExpression(arg) && import_compiler19.types.isBlockStatement(arg.body)) {
3295
+ args[i] = import_compiler20.types.numericLiteral(0);
3296
+ } else if (import_compiler20.types.isArrowFunctionExpression(arg) && import_compiler20.types.isBlockStatement(arg.body)) {
2880
3297
  const body = arg.body.body;
2881
3298
  if (body.length === 0) {
2882
- args[i] = import_compiler19.types.numericLiteral(0);
2883
- } else if (body.length === 1 && import_compiler19.types.isExpressionStatement(body[0])) {
3299
+ args[i] = import_compiler20.types.numericLiteral(0);
3300
+ } else if (body.length === 1 && import_compiler20.types.isExpressionStatement(body[0])) {
2884
3301
  arg.body = toParenthesizedExpressionIfNeeded(body[0].expression);
2885
3302
  }
2886
- } else if (import_compiler19.types.isNullLiteral(arg) || import_compiler19.types.isUnaryExpression(arg) && arg.operator === "void") {
2887
- args[i] = import_compiler19.types.numericLiteral(0);
3303
+ } else if (import_compiler20.types.isNullLiteral(arg) || import_compiler20.types.isUnaryExpression(arg) && arg.operator === "void") {
3304
+ args[i] = import_compiler20.types.numericLiteral(0);
2888
3305
  }
2889
3306
  }
2890
- for (let i = args.length - 1; import_compiler19.types.isNumericLiteral(args[i]) && args[i].value === 0; ) {
3307
+ for (let i = args.length - 1; import_compiler20.types.isNumericLiteral(args[i]) && args[i].value === 0; ) {
2891
3308
  args.length = i--;
2892
3309
  }
2893
3310
  return args;
@@ -2936,7 +3353,7 @@ function getResumeRegisterId(section, referencedBindings, type) {
2936
3353
  const {
2937
3354
  markoOpts,
2938
3355
  opts: { filename }
2939
- } = (0, import_babel_utils13.getFile)();
3356
+ } = (0, import_babel_utils14.getFile)();
2940
3357
  let name2 = "";
2941
3358
  if (referencedBindings) {
2942
3359
  if (typeof referencedBindings === "string") {
@@ -2949,7 +3366,7 @@ function getResumeRegisterId(section, referencedBindings, type) {
2949
3366
  name2 += `_${referencedBindings.name}`;
2950
3367
  }
2951
3368
  }
2952
- return (0, import_babel_utils13.getTemplateId)(
3369
+ return (0, import_babel_utils14.getTemplateId)(
2953
3370
  markoOpts,
2954
3371
  filename,
2955
3372
  `${section.id}${name2}${type ? "/" + type : ""}`
@@ -2960,10 +3377,10 @@ function getRegisterUID(section, name2) {
2960
3377
  const {
2961
3378
  markoOpts,
2962
3379
  opts: { filename }
2963
- } = (0, import_babel_utils13.getFile)();
3380
+ } = (0, import_babel_utils14.getFile)();
2964
3381
  let used = usedRegisterIdsBySection.get(section);
2965
3382
  if (!used) usedRegisterIdsBySection.set(section, used = /* @__PURE__ */ new Set());
2966
- const baseId = (0, import_babel_utils13.getTemplateId)(
3383
+ const baseId = (0, import_babel_utils14.getTemplateId)(
2967
3384
  markoOpts,
2968
3385
  filename,
2969
3386
  `${section.id}/${name2}`
@@ -2980,7 +3397,7 @@ function writeSignals(section) {
2980
3397
  forEach(section.hoisted, (binding) => {
2981
3398
  for (const hoistedBinding of binding.hoists.values()) {
2982
3399
  const accessors = [
2983
- binding.type === 0 /* dom */ ? import_compiler19.types.stringLiteral(
3400
+ binding.type === 0 /* dom */ ? import_compiler20.types.stringLiteral(
2984
3401
  getAccessorPrefix().Getter + getScopeAccessor(binding)
2985
3402
  ) : getScopeAccessorLiteral(binding)
2986
3403
  ];
@@ -2993,13 +3410,13 @@ function writeSignals(section) {
2993
3410
  currentSection = parentSection;
2994
3411
  }
2995
3412
  const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
2996
- (0, import_babel_utils13.getProgram)().node.body.push(
2997
- import_compiler19.types.variableDeclaration("const", [
2998
- import_compiler19.types.variableDeclarator(
3413
+ (0, import_babel_utils14.getProgram)().node.body.push(
3414
+ import_compiler20.types.variableDeclaration("const", [
3415
+ import_compiler20.types.variableDeclarator(
2999
3416
  hoistIdentifier,
3000
3417
  hoistedBinding.downstreamExpressions.size ? callRuntime(
3001
3418
  "register",
3002
- import_compiler19.types.stringLiteral(
3419
+ import_compiler20.types.stringLiteral(
3003
3420
  getResumeRegisterId(
3004
3421
  hoistedBinding.section,
3005
3422
  hoistedBinding,
@@ -3016,7 +3433,7 @@ function writeSignals(section) {
3016
3433
  hoistedBinding.section,
3017
3434
  void 0,
3018
3435
  initValue(hoistedBinding),
3019
- import_compiler19.types.callExpression(hoistIdentifier, [scopeIdentifier])
3436
+ import_compiler20.types.callExpression(hoistIdentifier, [scopeIdentifier])
3020
3437
  );
3021
3438
  }
3022
3439
  }
@@ -3030,20 +3447,20 @@ function writeSignals(section) {
3030
3447
  let effectDeclarator;
3031
3448
  if (signal.effect.length) {
3032
3449
  traverseReplace(signal, "effect", replaceEffectNode);
3033
- const effectIdentifier = import_compiler19.types.identifier(`${signal.identifier.name}_effect`);
3450
+ const effectIdentifier = import_compiler20.types.identifier(`${signal.identifier.name}_effect`);
3034
3451
  const referencedBindings = signal.effectReferencedBindings;
3035
3452
  const referencesScope = traverseContains(
3036
3453
  signal.effect,
3037
3454
  isScopeIdentifier
3038
3455
  );
3039
- effectDeclarator = import_compiler19.types.variableDeclarator(
3456
+ effectDeclarator = import_compiler20.types.variableDeclarator(
3040
3457
  effectIdentifier,
3041
3458
  callRuntime(
3042
3459
  "effect",
3043
- import_compiler19.types.stringLiteral(
3460
+ import_compiler20.types.stringLiteral(
3044
3461
  getResumeRegisterId(section, signal.referencedBindings)
3045
3462
  ),
3046
- import_compiler19.types.arrowFunctionExpression(
3463
+ import_compiler20.types.arrowFunctionExpression(
3047
3464
  referencedBindings ? referencesScope ? [
3048
3465
  scopeIdentifier,
3049
3466
  createScopeReadPattern(section, referencedBindings)
@@ -3054,44 +3471,44 @@ function writeSignals(section) {
3054
3471
  );
3055
3472
  }
3056
3473
  let value = signal.build();
3057
- if (import_compiler19.types.isCallExpression(value)) {
3474
+ if (import_compiler20.types.isCallExpression(value)) {
3058
3475
  replaceNullishAndEmptyFunctionsWith0(value.arguments);
3059
3476
  }
3060
3477
  if (signal.register) {
3061
3478
  value = callRuntime(
3062
3479
  "registerBoundSignal",
3063
- import_compiler19.types.stringLiteral(
3480
+ import_compiler20.types.stringLiteral(
3064
3481
  getResumeRegisterId(section, signal.referencedBindings, "var")
3065
3482
  ),
3066
3483
  value
3067
3484
  );
3068
3485
  }
3069
- const signalDeclarator = import_compiler19.types.variableDeclarator(signal.identifier, value);
3070
- let signalDeclaration = !section.parent && !signal.referencedBindings && (import_compiler19.types.isFunctionExpression(value) || import_compiler19.types.isArrowFunctionExpression(value)) ? import_compiler19.types.functionDeclaration(
3486
+ const signalDeclarator = import_compiler20.types.variableDeclarator(signal.identifier, value);
3487
+ let signalDeclaration = !section.parent && !signal.referencedBindings && (import_compiler20.types.isFunctionExpression(value) || import_compiler20.types.isArrowFunctionExpression(value)) ? import_compiler20.types.functionDeclaration(
3071
3488
  signal.identifier,
3072
3489
  value.params,
3073
- import_compiler19.types.isExpression(value.body) ? import_compiler19.types.blockStatement([import_compiler19.types.expressionStatement(value.body)]) : value.body
3074
- ) : import_compiler19.types.variableDeclaration("const", [signalDeclarator]);
3490
+ import_compiler20.types.isExpression(value.body) ? import_compiler20.types.blockStatement([import_compiler20.types.expressionStatement(value.body)]) : value.body
3491
+ ) : import_compiler20.types.variableDeclaration("const", [signalDeclarator]);
3075
3492
  if (signal.export) {
3076
- signalDeclaration = import_compiler19.types.exportNamedDeclaration(signalDeclaration);
3493
+ signalDeclaration = import_compiler20.types.exportNamedDeclaration(signalDeclaration);
3077
3494
  }
3078
3495
  const signalStatements = signal.prependStatements || [];
3079
3496
  if (effectDeclarator) {
3080
- signalStatements.push(import_compiler19.types.variableDeclaration("const", [effectDeclarator]));
3497
+ signalStatements.push(import_compiler20.types.variableDeclaration("const", [effectDeclarator]));
3081
3498
  }
3082
3499
  signalStatements.push(signalDeclaration);
3083
- (0, import_babel_utils13.getProgram)().node.body.push(...signalStatements);
3500
+ (0, import_babel_utils14.getProgram)().node.body.push(...signalStatements);
3084
3501
  }
3085
3502
  }
3086
3503
  function writeRegisteredFns() {
3087
- const registeredFns = registeredFnsForProgram.get((0, import_babel_utils13.getProgram)().node);
3504
+ const registeredFns = registeredFnsForProgram.get((0, import_babel_utils14.getProgram)().node);
3088
3505
  const statements = [];
3089
3506
  if (registeredFns) {
3090
3507
  for (const registeredFn of registeredFns) {
3091
3508
  let fn;
3092
3509
  const params = registeredFn.referencedBindings ? registeredFn.referencesScope ? [
3093
3510
  scopeIdentifier,
3094
- import_compiler19.types.assignmentPattern(
3511
+ import_compiler20.types.assignmentPattern(
3095
3512
  createScopeReadPattern(
3096
3513
  registeredFn.section,
3097
3514
  registeredFn.referencedBindings
@@ -3105,18 +3522,18 @@ function writeRegisteredFns() {
3105
3522
  )
3106
3523
  ] : registeredFn.referencesScope ? [scopeIdentifier] : void 0;
3107
3524
  if (params) {
3108
- fn = import_compiler19.types.functionDeclaration(
3109
- import_compiler19.types.identifier(registeredFn.id),
3525
+ fn = import_compiler20.types.functionDeclaration(
3526
+ import_compiler20.types.identifier(registeredFn.id),
3110
3527
  params,
3111
- import_compiler19.types.blockStatement(toReturnedFunction(registeredFn.node))
3528
+ import_compiler20.types.blockStatement(toReturnedFunction(registeredFn.node))
3112
3529
  );
3113
3530
  } else if (registeredFn.node.type === "FunctionDeclaration" && registeredFn.node.id?.name === registeredFn.id) {
3114
3531
  fn = registeredFn.node;
3115
3532
  } else {
3116
- fn = import_compiler19.types.functionDeclaration(
3117
- import_compiler19.types.identifier(registeredFn.id),
3533
+ fn = import_compiler20.types.functionDeclaration(
3534
+ import_compiler20.types.identifier(registeredFn.id),
3118
3535
  registeredFn.node.params,
3119
- registeredFn.node.body.type === "BlockStatement" ? registeredFn.node.body : import_compiler19.types.blockStatement([import_compiler19.types.returnStatement(registeredFn.node.body)]),
3536
+ registeredFn.node.body.type === "BlockStatement" ? registeredFn.node.body : import_compiler20.types.blockStatement([import_compiler20.types.returnStatement(registeredFn.node.body)]),
3120
3537
  registeredFn.node.generator,
3121
3538
  registeredFn.node.async
3122
3539
  );
@@ -3125,21 +3542,21 @@ function writeRegisteredFns() {
3125
3542
  }
3126
3543
  for (const registeredFn of registeredFns) {
3127
3544
  statements.push(
3128
- import_compiler19.types.expressionStatement(
3545
+ import_compiler20.types.expressionStatement(
3129
3546
  callRuntime(
3130
3547
  "register",
3131
- import_compiler19.types.stringLiteral(registeredFn.registerId),
3132
- import_compiler19.types.identifier(registeredFn.id)
3548
+ import_compiler20.types.stringLiteral(registeredFn.registerId),
3549
+ import_compiler20.types.identifier(registeredFn.id)
3133
3550
  )
3134
3551
  )
3135
3552
  );
3136
3553
  }
3137
- (0, import_babel_utils13.getProgram)().node.body.push(...statements);
3554
+ (0, import_babel_utils14.getProgram)().node.body.push(...statements);
3138
3555
  }
3139
3556
  }
3140
3557
  function toReturnedFunction(rawFn) {
3141
3558
  const fn = simplifyFunction(rawFn);
3142
- return fn.type === "FunctionDeclaration" ? [fn, import_compiler19.types.returnStatement(fn.id)] : [import_compiler19.types.returnStatement(fn)];
3559
+ return fn.type === "FunctionDeclaration" ? [fn, import_compiler20.types.returnStatement(fn.id)] : [import_compiler20.types.returnStatement(fn)];
3143
3560
  }
3144
3561
  function sortSignals(a, b) {
3145
3562
  const aReferencedBindings = getReferencedBindings(a);
@@ -3176,12 +3593,7 @@ function writeHTMLResumeStatements(path5) {
3176
3593
  forEach(section.referencedHoists, serializeOwnersUntilBinding);
3177
3594
  forEach(section.referencedClosures, (closure) => {
3178
3595
  if (closure.sources) {
3179
- const serializeReason = getBindingSerializeReason(
3180
- closure.section,
3181
- closure
3182
- );
3183
3596
  serializeOwnersUntilBinding(closure);
3184
- serializeSectionIfNeeded(closure.section, serializeReason);
3185
3597
  if (isDynamicClosure(section, closure)) {
3186
3598
  const closureSignal = getSignal(closure.section, closure);
3187
3599
  let identifier = htmlDynamicClosureInstancesIdentifier.get(closureSignal);
@@ -3193,10 +3605,10 @@ function writeHTMLResumeStatements(path5) {
3193
3605
  )
3194
3606
  );
3195
3607
  getHTMLSectionStatements(closure.section).push(
3196
- import_compiler19.types.variableDeclaration("const", [
3197
- import_compiler19.types.variableDeclarator(
3608
+ import_compiler20.types.variableDeclaration("const", [
3609
+ import_compiler20.types.variableDeclarator(
3198
3610
  identifier,
3199
- import_compiler19.types.newExpression(import_compiler19.types.identifier("Set"), [])
3611
+ import_compiler20.types.newExpression(import_compiler20.types.identifier("Set"), [])
3200
3612
  )
3201
3613
  ])
3202
3614
  );
@@ -3210,7 +3622,7 @@ function writeHTMLResumeStatements(path5) {
3210
3622
  setBindingSerializedValue(
3211
3623
  section,
3212
3624
  closure,
3213
- import_compiler19.types.numericLiteral(getDynamicClosureIndex(closure, section)),
3625
+ import_compiler20.types.numericLiteral(getDynamicClosureIndex(closure, section)),
3214
3626
  getAccessorPrefix().ClosureSignalIndex
3215
3627
  );
3216
3628
  addWriteScopeBuilder(
@@ -3225,13 +3637,13 @@ function writeHTMLResumeStatements(path5) {
3225
3637
  for (const hoistedBinding of binding.hoists.values()) {
3226
3638
  if (hoistedBinding.downstreamExpressions.size) {
3227
3639
  getHTMLSectionStatements(hoistedBinding.section).push(
3228
- import_compiler19.types.variableDeclaration("const", [
3229
- import_compiler19.types.variableDeclarator(
3230
- import_compiler19.types.identifier(hoistedBinding.name),
3640
+ import_compiler20.types.variableDeclaration("const", [
3641
+ import_compiler20.types.variableDeclarator(
3642
+ import_compiler20.types.identifier(hoistedBinding.name),
3231
3643
  callRuntime(
3232
3644
  "hoist",
3233
3645
  getScopeIdIdentifier(hoistedBinding.section),
3234
- import_compiler19.types.stringLiteral(
3646
+ import_compiler20.types.stringLiteral(
3235
3647
  getResumeRegisterId(
3236
3648
  hoistedBinding.section,
3237
3649
  hoistedBinding,
@@ -3252,10 +3664,10 @@ function writeHTMLResumeStatements(path5) {
3252
3664
  );
3253
3665
  sectionDynamicSubscribers.add(currentSection);
3254
3666
  getHTMLSectionStatements(parentSection).push(
3255
- import_compiler19.types.variableDeclaration("const", [
3256
- import_compiler19.types.variableDeclarator(
3667
+ import_compiler20.types.variableDeclaration("const", [
3668
+ import_compiler20.types.variableDeclarator(
3257
3669
  subscribersIdentifier,
3258
- import_compiler19.types.newExpression(import_compiler19.types.identifier("Set"), [])
3670
+ import_compiler20.types.newExpression(import_compiler20.types.identifier("Set"), [])
3259
3671
  )
3260
3672
  ])
3261
3673
  );
@@ -3284,11 +3696,11 @@ function writeHTMLResumeStatements(path5) {
3284
3696
  if (allSignals[i].effect.length) {
3285
3697
  const signalRefs = allSignals[i].referencedBindings;
3286
3698
  body.push(
3287
- import_compiler19.types.expressionStatement(
3699
+ import_compiler20.types.expressionStatement(
3288
3700
  callRuntime(
3289
3701
  "writeEffect",
3290
3702
  scopeIdIdentifier,
3291
- import_compiler19.types.stringLiteral(getResumeRegisterId(section, signalRefs))
3703
+ import_compiler20.types.stringLiteral(getResumeRegisterId(section, signalRefs))
3292
3704
  )
3293
3705
  )
3294
3706
  );
@@ -3296,22 +3708,27 @@ function writeHTMLResumeStatements(path5) {
3296
3708
  }
3297
3709
  const serializedLookup = getSerializedAccessors(section);
3298
3710
  const serializedProperties = [];
3711
+ const sectionSerializeReason = nonAnalyzedForceSerializedSection.has(section) ? true : section.serializeReason;
3299
3712
  forEach(section.bindings, (binding) => {
3300
3713
  if (binding.type === 0 /* dom */) return;
3301
- const serializeReason = getBindingSerializeReason(section, binding);
3302
- if (!serializeReason) return;
3714
+ const reason = getBindingSerializeReason(section, binding);
3715
+ if (!reason) return;
3303
3716
  const accessor = getScopeAccessor(binding);
3304
3717
  serializedLookup.delete(accessor);
3305
3718
  serializedProperties.push(
3306
- toObjectProperty(accessor, getDeclaredBindingExpression(binding))
3719
+ toObjectProperty(
3720
+ accessor,
3721
+ sectionSerializeReason && (sectionSerializeReason === reason || sectionSerializeReason !== true && reason !== true && compareSerializeReasons(sectionSerializeReason, reason) === 0) ? getDeclaredBindingExpression(binding) : getExprIfSerialized(reason, getDeclaredBindingExpression(binding))
3722
+ )
3307
3723
  );
3308
3724
  });
3309
- for (const [key, { expression }] of serializedLookup) {
3310
- serializedProperties.push(toObjectProperty(key, expression));
3725
+ for (const [key, { expression, reason }] of serializedLookup) {
3726
+ serializedProperties.push(
3727
+ toObjectProperty(key, getExprIfSerialized(reason, expression))
3728
+ );
3311
3729
  }
3312
3730
  const writeScopeBuilder = getSectionWriteScopeBuilder(section);
3313
- const forceSerializeReason = serializeSectionReason(section);
3314
- if (writeScopeBuilder || serializedProperties.length || forceSerializeReason) {
3731
+ if (sectionSerializeReason) {
3315
3732
  for (const prop of serializedProperties) {
3316
3733
  if (prop.key.type === "Identifier" && prop.value.type === "Identifier" && prop.key.name === prop.value.name) {
3317
3734
  prop.shorthand = true;
@@ -3319,7 +3736,7 @@ function writeHTMLResumeStatements(path5) {
3319
3736
  }
3320
3737
  const writeScopeArgs = [
3321
3738
  scopeIdIdentifier,
3322
- import_compiler19.types.objectExpression(serializedProperties)
3739
+ import_compiler20.types.objectExpression(serializedProperties)
3323
3740
  ];
3324
3741
  if (!isOptimize()) {
3325
3742
  let debugVars;
@@ -3335,38 +3752,42 @@ function writeHTMLResumeStatements(path5) {
3335
3752
  }
3336
3753
  root = root.upstreamAlias;
3337
3754
  }
3338
- const locExpr = root.loc && import_compiler19.types.stringLiteral(
3755
+ const locExpr = root.loc && import_compiler20.types.stringLiteral(
3339
3756
  `${root.loc.start.line}:${root.loc.start.column + 1}`
3340
3757
  );
3341
3758
  (debugVars ||= []).push(
3342
3759
  toObjectProperty(
3343
3760
  getScopeAccessor(binding),
3344
- root !== binding ? import_compiler19.types.arrayExpression(
3345
- locExpr ? [import_compiler19.types.stringLiteral(root.name + access), locExpr] : [import_compiler19.types.stringLiteral(root.name + access)]
3346
- ) : locExpr || import_compiler19.types.numericLiteral(0)
3761
+ root !== binding ? import_compiler20.types.arrayExpression(
3762
+ locExpr ? [import_compiler20.types.stringLiteral(root.name + access), locExpr] : [import_compiler20.types.stringLiteral(root.name + access)]
3763
+ ) : locExpr || import_compiler20.types.numericLiteral(0)
3347
3764
  )
3348
3765
  );
3349
3766
  });
3350
3767
  writeScopeArgs.push(
3351
- import_compiler19.types.stringLiteral(path5.hub.file.opts.filenameRelative),
3352
- section.loc && section.loc.start.line != null ? import_compiler19.types.stringLiteral(
3768
+ import_compiler20.types.stringLiteral(path5.hub.file.opts.filenameRelative),
3769
+ section.loc && section.loc.start.line != null ? import_compiler20.types.stringLiteral(
3353
3770
  `${section.loc.start.line}:${section.loc.start.column + 1}`
3354
- ) : import_compiler19.types.numericLiteral(0)
3771
+ ) : import_compiler20.types.numericLiteral(0)
3355
3772
  );
3356
3773
  if (debugVars) {
3357
- writeScopeArgs.push(import_compiler19.types.objectExpression(debugVars));
3774
+ writeScopeArgs.push(import_compiler20.types.objectExpression(debugVars));
3358
3775
  }
3359
3776
  }
3360
- body.push(
3361
- import_compiler19.types.expressionStatement(
3362
- writeScopeBuilder ? writeScopeBuilder(callRuntime("writeScope", ...writeScopeArgs)) : callRuntime("writeScope", ...writeScopeArgs)
3363
- )
3364
- );
3777
+ let writeScopeCall = writeScopeBuilder ? writeScopeBuilder(callRuntime("writeScope", ...writeScopeArgs)) : callRuntime("writeScope", ...writeScopeArgs);
3778
+ if (sectionSerializeReason !== true) {
3779
+ writeScopeCall = import_compiler20.types.logicalExpression(
3780
+ "&&",
3781
+ getSerializeGuard(sectionSerializeReason),
3782
+ writeScopeCall
3783
+ );
3784
+ }
3785
+ body.push(import_compiler20.types.expressionStatement(writeScopeCall));
3365
3786
  }
3366
3787
  const resumeClosestBranch2 = !section.isBranch && (section.hasAbortSignal || !!section.referencedClosures || !!find(section.bindings, (binding) => binding.type === 1 /* let */));
3367
3788
  if (resumeClosestBranch2) {
3368
3789
  body.push(
3369
- import_compiler19.types.expressionStatement(
3790
+ import_compiler20.types.expressionStatement(
3370
3791
  callRuntime("resumeClosestBranch", scopeIdIdentifier)
3371
3792
  )
3372
3793
  );
@@ -3374,26 +3795,28 @@ function writeHTMLResumeStatements(path5) {
3374
3795
  const additionalStatements = getHTMLSectionStatements(section);
3375
3796
  if (body.length || additionalStatements.length) {
3376
3797
  body.unshift(
3377
- import_compiler19.types.variableDeclaration("const", [
3378
- import_compiler19.types.variableDeclarator(scopeIdIdentifier, callRuntime("nextScopeId"))
3798
+ import_compiler20.types.variableDeclaration("const", [
3799
+ import_compiler20.types.variableDeclarator(scopeIdIdentifier, callRuntime("nextScopeId"))
3379
3800
  ]),
3380
3801
  ...additionalStatements
3381
3802
  );
3382
3803
  }
3383
3804
  const returnIdentifier = getSectionReturnValueIdentifier(section);
3384
3805
  if (returnIdentifier !== void 0) {
3385
- body.push(import_compiler19.types.returnStatement(returnIdentifier));
3806
+ body.push(import_compiler20.types.returnStatement(returnIdentifier));
3386
3807
  }
3387
3808
  }
3388
3809
  function serializeOwners(from, to) {
3810
+ const ownerProp = getAccessorProp().Owner;
3389
3811
  let cur = from;
3390
3812
  while (cur !== to) {
3391
3813
  const parent = cur.parent;
3392
3814
  if (!parent) break;
3393
3815
  const serialized = getSerializedAccessors(cur);
3816
+ nonAnalyzedForceSerializedSection.add(cur);
3394
3817
  cur = parent;
3395
- if (!serialized.has("_")) {
3396
- serialized.set("_", {
3818
+ if (!serialized.has(ownerProp)) {
3819
+ serialized.set(ownerProp, {
3397
3820
  expression: callRuntime("ensureScopeWithId", getScopeIdIdentifier(cur)),
3398
3821
  reason: true
3399
3822
  });
@@ -3404,12 +3827,12 @@ function getSetup(section) {
3404
3827
  return getSignals(section).get(void 0)?.identifier;
3405
3828
  }
3406
3829
  function replaceRenderNode(node) {
3407
- return replaceAssignedNode(node) || replaceBindingReadNode(node) || replaceRegisteredFunctionNode(node);
3830
+ return replaceAssignedNode(node) || replaceBindingReadNode2(node) || replaceRegisteredFunctionNode2(node);
3408
3831
  }
3409
3832
  function replaceEffectNode(node) {
3410
- return replaceAssignedNode(node) || replaceBindingReadNode(node);
3833
+ return replaceAssignedNode(node) || replaceBindingReadNode2(node);
3411
3834
  }
3412
- function replaceBindingReadNode(node) {
3835
+ function replaceBindingReadNode2(node) {
3413
3836
  switch (node.type) {
3414
3837
  case "Identifier":
3415
3838
  case "MemberExpression": {
@@ -3429,14 +3852,14 @@ function replaceAssignedNode(node) {
3429
3852
  if (buildAssignment) {
3430
3853
  const replacement = buildAssignment(
3431
3854
  extra.section,
3432
- import_compiler19.types.binaryExpression(
3855
+ import_compiler20.types.binaryExpression(
3433
3856
  node.operator === "++" ? "+" : "-",
3434
3857
  node.argument,
3435
- import_compiler19.types.numericLiteral(1)
3858
+ import_compiler20.types.numericLiteral(1)
3436
3859
  )
3437
3860
  );
3438
3861
  if (!node.prefix) {
3439
- return import_compiler19.types.sequenceExpression([replacement, node.argument]);
3862
+ return import_compiler20.types.sequenceExpression([replacement, node.argument]);
3440
3863
  }
3441
3864
  return replacement;
3442
3865
  }
@@ -3455,7 +3878,7 @@ function replaceAssignedNode(node) {
3455
3878
  if (buildAssignment) {
3456
3879
  return buildAssignment(
3457
3880
  extra.section,
3458
- node.operator === "=" ? node.right : import_compiler19.types.binaryExpression(
3881
+ node.operator === "=" ? node.right : import_compiler20.types.binaryExpression(
3459
3882
  node.operator.slice(
3460
3883
  0,
3461
3884
  -1
@@ -3481,26 +3904,26 @@ function replaceAssignedNode(node) {
3481
3904
  );
3482
3905
  if (signal?.buildAssignment) {
3483
3906
  id.name = generateUid(id.name);
3484
- (params ||= []).push(import_compiler19.types.identifier(id.name));
3907
+ (params ||= []).push(import_compiler20.types.identifier(id.name));
3485
3908
  (assignments ||= []).push(
3486
- signal.buildAssignment(extra.section, import_compiler19.types.identifier(id.name))
3909
+ signal.buildAssignment(extra.section, import_compiler20.types.identifier(id.name))
3487
3910
  );
3488
3911
  }
3489
3912
  }
3490
3913
  });
3491
3914
  if (params && assignments) {
3492
3915
  const resultId = generateUid("result");
3493
- return import_compiler19.types.callExpression(
3494
- import_compiler19.types.arrowFunctionExpression(
3495
- [import_compiler19.types.identifier(resultId), ...params],
3496
- import_compiler19.types.sequenceExpression([
3497
- import_compiler19.types.assignmentExpression(
3916
+ return import_compiler20.types.callExpression(
3917
+ import_compiler20.types.arrowFunctionExpression(
3918
+ [import_compiler20.types.identifier(resultId), ...params],
3919
+ import_compiler20.types.sequenceExpression([
3920
+ import_compiler20.types.assignmentExpression(
3498
3921
  "=",
3499
3922
  node.left,
3500
- import_compiler19.types.identifier(resultId)
3923
+ import_compiler20.types.identifier(resultId)
3501
3924
  ),
3502
3925
  ...assignments,
3503
- import_compiler19.types.identifier(resultId)
3926
+ import_compiler20.types.identifier(resultId)
3504
3927
  ])
3505
3928
  ),
3506
3929
  [node.right]
@@ -3513,44 +3936,44 @@ function replaceAssignedNode(node) {
3513
3936
  }
3514
3937
  }
3515
3938
  var registeredFnsForProgram = /* @__PURE__ */ new WeakMap();
3516
- function replaceRegisteredFunctionNode(node) {
3939
+ function replaceRegisteredFunctionNode2(node) {
3517
3940
  switch (node.type) {
3518
3941
  case "ClassMethod": {
3519
- const replacement = getRegisteredFnExpression(node);
3520
- return replacement && import_compiler19.types.classProperty(node.key, replacement);
3942
+ const replacement = getRegisteredFnExpression2(node);
3943
+ return replacement && import_compiler20.types.classProperty(node.key, replacement);
3521
3944
  }
3522
3945
  case "ClassPrivateMethod": {
3523
- const replacement = getRegisteredFnExpression(node);
3524
- return replacement && import_compiler19.types.classPrivateProperty(node.key, replacement);
3946
+ const replacement = getRegisteredFnExpression2(node);
3947
+ return replacement && import_compiler20.types.classPrivateProperty(node.key, replacement);
3525
3948
  }
3526
3949
  case "ObjectMethod": {
3527
- const replacement = getRegisteredFnExpression(node);
3528
- return replacement && import_compiler19.types.objectProperty(node.key, replacement);
3950
+ const replacement = getRegisteredFnExpression2(node);
3951
+ return replacement && import_compiler20.types.objectProperty(node.key, replacement);
3529
3952
  }
3530
3953
  case "ArrowFunctionExpression":
3531
3954
  case "FunctionExpression": {
3532
- return getRegisteredFnExpression(node);
3955
+ return getRegisteredFnExpression2(node);
3533
3956
  }
3534
3957
  case "FunctionDeclaration": {
3535
- const replacement = getRegisteredFnExpression(node);
3958
+ const replacement = getRegisteredFnExpression2(node);
3536
3959
  if (replacement) {
3537
- return import_compiler19.types.variableDeclaration("const", [
3538
- import_compiler19.types.variableDeclarator(node.id, replacement)
3960
+ return import_compiler20.types.variableDeclaration("const", [
3961
+ import_compiler20.types.variableDeclarator(node.id, replacement)
3539
3962
  ]);
3540
3963
  }
3541
3964
  break;
3542
3965
  }
3543
3966
  }
3544
3967
  }
3545
- function getRegisteredFnExpression(node) {
3968
+ function getRegisteredFnExpression2(node) {
3546
3969
  const { extra } = node;
3547
3970
  if (isRegisteredFnExtra(extra)) {
3548
3971
  const id = extra.name;
3549
3972
  const referencesScope = extra.referencesScope;
3550
3973
  const referencedBindings = extra.referencedBindingsInFunction;
3551
- let registedFns = registeredFnsForProgram.get((0, import_babel_utils13.getProgram)().node);
3974
+ let registedFns = registeredFnsForProgram.get((0, import_babel_utils14.getProgram)().node);
3552
3975
  if (!registedFns) {
3553
- registeredFnsForProgram.set((0, import_babel_utils13.getProgram)().node, registedFns = []);
3976
+ registeredFnsForProgram.set((0, import_babel_utils14.getProgram)().node, registedFns = []);
3554
3977
  }
3555
3978
  registedFns.push({
3556
3979
  id,
@@ -3561,9 +3984,9 @@ function getRegisteredFnExpression(node) {
3561
3984
  referencedBindings
3562
3985
  });
3563
3986
  if (referencesScope || referencedBindings) {
3564
- return import_compiler19.types.callExpression(import_compiler19.types.identifier(id), [scopeIdentifier]);
3987
+ return import_compiler20.types.callExpression(import_compiler20.types.identifier(id), [scopeIdentifier]);
3565
3988
  } else {
3566
- return import_compiler19.types.identifier(id);
3989
+ return import_compiler20.types.identifier(id);
3567
3990
  }
3568
3991
  }
3569
3992
  }
@@ -3576,30 +3999,30 @@ var dom_default = {
3576
3999
  const section = getSectionForBody(program);
3577
4000
  const { walks, writes, setup } = getSectionMeta(section);
3578
4001
  const domExports = program.node.extra.domExports;
3579
- const templateIdentifier = import_compiler20.types.identifier(domExports.template);
3580
- const walksIdentifier = import_compiler20.types.identifier(domExports.walks);
3581
- const setupIdentifier = import_compiler20.types.identifier(domExports.setup);
4002
+ const templateIdentifier = import_compiler21.types.identifier(domExports.template);
4003
+ const walksIdentifier = import_compiler21.types.identifier(domExports.walks);
4004
+ const setupIdentifier = import_compiler21.types.identifier(domExports.setup);
3582
4005
  const inputBinding = program.node.params[0].extra?.binding;
3583
4006
  const programInputSignal = inputBinding && bindingHasDownstreamExpressions(inputBinding) ? initValue(inputBinding) : void 0;
3584
4007
  const styleFile = getStyleFile(program.hub.file);
3585
4008
  if (styleFile) {
3586
- (0, import_babel_utils14.importDefault)(program.hub.file, styleFile);
4009
+ (0, import_babel_utils15.importDefault)(program.hub.file, styleFile);
3587
4010
  }
3588
4011
  forEachSectionReverse((childSection) => {
3589
4012
  if (childSection !== section) {
3590
4013
  const tagParamsSignal = childSection.params && initValue(childSection.params);
3591
4014
  const { walks: walks2, writes: writes2, setup: setup2 } = getSectionMeta(childSection);
3592
- const identifier = import_compiler20.types.identifier(childSection.name);
3593
- const referencedClosures = childSection.referencedClosures ? import_compiler20.types.arrowFunctionExpression(
4015
+ const identifier = import_compiler21.types.identifier(childSection.name);
4016
+ const referencedClosures = childSection.referencedClosures ? import_compiler21.types.arrowFunctionExpression(
3594
4017
  [scopeIdentifier],
3595
4018
  toFirstExpressionOrBlock(
3596
- map(childSection.referencedClosures, (closure) => {
4019
+ toArray(childSection.referencedClosures, (closure) => {
3597
4020
  const closureSignal = getSignal(childSection, closure);
3598
- return import_compiler20.types.expressionStatement(
3599
- import_compiler20.types.callExpression(
3600
- isDynamicClosure(childSection, closure) ? closureSignal.identifier : import_compiler20.types.memberExpression(
4021
+ return import_compiler21.types.expressionStatement(
4022
+ import_compiler21.types.callExpression(
4023
+ isDynamicClosure(childSection, closure) ? closureSignal.identifier : import_compiler21.types.memberExpression(
3601
4024
  closureSignal.identifier,
3602
- import_compiler20.types.identifier("_")
4025
+ import_compiler21.types.identifier(getAccessorProp().Owner)
3603
4026
  ),
3604
4027
  [scopeIdentifier]
3605
4028
  )
@@ -3618,7 +4041,7 @@ var dom_default = {
3618
4041
  ])
3619
4042
  ) : callRuntime(
3620
4043
  isSerializedSection(childSection) ? "registerContent" : "createContent",
3621
- import_compiler20.types.stringLiteral(getResumeRegisterId(childSection, "renderer")),
4044
+ import_compiler21.types.stringLiteral(getResumeRegisterId(childSection, "renderer")),
3622
4045
  ...replaceNullishAndEmptyFunctionsWith0([
3623
4046
  writes2,
3624
4047
  walks2,
@@ -3630,8 +4053,8 @@ var dom_default = {
3630
4053
  );
3631
4054
  writeSignals(childSection);
3632
4055
  program.node.body.push(
3633
- import_compiler20.types.variableDeclaration("const", [
3634
- import_compiler20.types.variableDeclarator(identifier, renderer)
4056
+ import_compiler21.types.variableDeclaration("const", [
4057
+ import_compiler21.types.variableDeclarator(identifier, renderer)
3635
4058
  ])
3636
4059
  );
3637
4060
  }
@@ -3640,36 +4063,36 @@ var dom_default = {
3640
4063
  writeRegisteredFns();
3641
4064
  if (!setup) {
3642
4065
  program.node.body.unshift(
3643
- import_compiler20.types.exportNamedDeclaration(
3644
- import_compiler20.types.variableDeclaration("const", [
3645
- import_compiler20.types.variableDeclarator(
4066
+ import_compiler21.types.exportNamedDeclaration(
4067
+ import_compiler21.types.variableDeclaration("const", [
4068
+ import_compiler21.types.variableDeclarator(
3646
4069
  setupIdentifier,
3647
- import_compiler20.types.arrowFunctionExpression([], import_compiler20.types.blockStatement([]))
4070
+ import_compiler21.types.arrowFunctionExpression([], import_compiler21.types.blockStatement([]))
3648
4071
  )
3649
4072
  ])
3650
4073
  )
3651
4074
  );
3652
4075
  }
3653
4076
  program.node.body.unshift(
3654
- import_compiler20.types.exportNamedDeclaration(
3655
- import_compiler20.types.variableDeclaration("const", [
3656
- import_compiler20.types.variableDeclarator(
4077
+ import_compiler21.types.exportNamedDeclaration(
4078
+ import_compiler21.types.variableDeclaration("const", [
4079
+ import_compiler21.types.variableDeclarator(
3657
4080
  templateIdentifier,
3658
- writes || import_compiler20.types.stringLiteral("")
4081
+ writes || import_compiler21.types.stringLiteral("")
3659
4082
  )
3660
4083
  ])
3661
4084
  ),
3662
- import_compiler20.types.exportNamedDeclaration(
3663
- import_compiler20.types.variableDeclaration("const", [
3664
- import_compiler20.types.variableDeclarator(walksIdentifier, walks || import_compiler20.types.stringLiteral(""))
4085
+ import_compiler21.types.exportNamedDeclaration(
4086
+ import_compiler21.types.variableDeclaration("const", [
4087
+ import_compiler21.types.variableDeclarator(walksIdentifier, walks || import_compiler21.types.stringLiteral(""))
3665
4088
  ])
3666
4089
  )
3667
4090
  );
3668
4091
  program.node.body.push(
3669
- import_compiler20.types.exportDefaultDeclaration(
4092
+ import_compiler21.types.exportDefaultDeclaration(
3670
4093
  callRuntime(
3671
4094
  "createTemplate",
3672
- import_compiler20.types.stringLiteral(program.hub.file.metadata.marko.id),
4095
+ import_compiler21.types.stringLiteral(program.hub.file.metadata.marko.id),
3673
4096
  templateIdentifier,
3674
4097
  walksIdentifier,
3675
4098
  setupIdentifier,
@@ -3681,157 +4104,6 @@ var dom_default = {
3681
4104
  }
3682
4105
  };
3683
4106
 
3684
- // src/translator/visitors/program/html.ts
3685
- var import_compiler21 = require("@marko/compiler");
3686
- var import_babel_utils15 = require("@marko/compiler/babel-utils");
3687
-
3688
- // src/translator/util/is-static.ts
3689
- function isStatic(path5) {
3690
- return path5.isImportDeclaration() || path5.isExportDeclaration() || path5.isMarkoScriptlet({ static: true });
3691
- }
3692
-
3693
- // src/translator/visitors/program/html.ts
3694
- var templateContentIdentifierForProgram = /* @__PURE__ */ new WeakMap();
3695
- function getTemplateContentName() {
3696
- let name2 = templateContentIdentifierForProgram.get((0, import_babel_utils15.getProgram)());
3697
- if (!name2) {
3698
- templateContentIdentifierForProgram.set(
3699
- (0, import_babel_utils15.getProgram)(),
3700
- name2 = generateUid("content")
3701
- );
3702
- }
3703
- return name2;
3704
- }
3705
- var html_default = {
3706
- translate: {
3707
- exit(program) {
3708
- flushInto(program);
3709
- writeHTMLResumeStatements(program);
3710
- traverseReplace(program.node, "body", replaceNode);
3711
- const renderContent = [];
3712
- for (const child of program.get("body")) {
3713
- if (!isStatic(child)) {
3714
- renderContent.push(child.node);
3715
- child.remove();
3716
- } else if (child.isMarkoScriptlet()) {
3717
- if (child.node.target && child.node.target !== "server") {
3718
- child.remove();
3719
- } else {
3720
- child.replaceWithMultiple(child.node.body);
3721
- }
3722
- }
3723
- }
3724
- const contentId = templateContentIdentifierForProgram.get(program);
3725
- const contentFn = import_compiler21.types.arrowFunctionExpression(
3726
- [import_compiler21.types.identifier("input")],
3727
- import_compiler21.types.blockStatement(renderContent)
3728
- );
3729
- const exportDefault = import_compiler21.types.exportDefaultDeclaration(
3730
- callRuntime(
3731
- "createTemplate",
3732
- import_compiler21.types.stringLiteral(program.hub.file.metadata.marko.id),
3733
- contentId ? import_compiler21.types.identifier(contentId) : contentFn
3734
- )
3735
- );
3736
- if (contentId) {
3737
- program.node.body.push(
3738
- import_compiler21.types.variableDeclaration("const", [
3739
- import_compiler21.types.variableDeclarator(import_compiler21.types.identifier(contentId), contentFn)
3740
- ]),
3741
- exportDefault
3742
- );
3743
- } else {
3744
- program.node.body.push(exportDefault);
3745
- }
3746
- }
3747
- }
3748
- };
3749
- function replaceNode(node, container) {
3750
- return replaceBindingReadNode2(node) || replaceRegisteredFunctionNode2(node, container);
3751
- }
3752
- function replaceBindingReadNode2(node) {
3753
- switch (node.type) {
3754
- case "Identifier":
3755
- case "MemberExpression": {
3756
- const { extra } = node;
3757
- if (extra && !(extra.read && !extra.read.binding.declared || extra.binding && !extra.binding.declared)) {
3758
- return getReadReplacement(node);
3759
- }
3760
- }
3761
- }
3762
- }
3763
- function replaceRegisteredFunctionNode2(node, container) {
3764
- switch (node.type) {
3765
- case "ClassMethod": {
3766
- const replacement = getRegisteredFnExpression2(node);
3767
- return replacement && import_compiler21.types.classProperty(node.key, replacement);
3768
- }
3769
- case "ClassPrivateMethod": {
3770
- const replacement = getRegisteredFnExpression2(node);
3771
- return replacement && import_compiler21.types.classPrivateProperty(node.key, replacement);
3772
- }
3773
- case "ObjectMethod": {
3774
- const replacement = getRegisteredFnExpression2(node);
3775
- return replacement && import_compiler21.types.objectProperty(node.key, replacement);
3776
- }
3777
- case "FunctionDeclaration": {
3778
- const { extra } = node;
3779
- if (isRegisteredFnExtra(extra)) {
3780
- let registeredFnDeclarations = registeredFnDeclarationsByBody.get(
3781
- container
3782
- );
3783
- if (!registeredFnDeclarations) {
3784
- registeredFnDeclarationsByBody.set(
3785
- container,
3786
- registeredFnDeclarations = []
3787
- );
3788
- }
3789
- registeredFnDeclarations.push({
3790
- id: node.id.name,
3791
- registerId: extra.registerId
3792
- });
3793
- }
3794
- break;
3795
- }
3796
- case "ArrowFunctionExpression":
3797
- case "FunctionExpression": {
3798
- return getRegisteredFnExpression2(node);
3799
- }
3800
- case "BlockStatement":
3801
- case "MarkoScriptlet":
3802
- addRegisteredDeclarations(node.body);
3803
- break;
3804
- }
3805
- }
3806
- var registeredFnDeclarationsByBody = /* @__PURE__ */ new WeakMap();
3807
- function addRegisteredDeclarations(body) {
3808
- const registeredFnDeclarations = registeredFnDeclarationsByBody.get(body);
3809
- if (registeredFnDeclarations) {
3810
- for (const { id, registerId } of registeredFnDeclarations) {
3811
- body.push(
3812
- import_compiler21.types.expressionStatement(
3813
- callRuntime(
3814
- "register",
3815
- import_compiler21.types.identifier(id),
3816
- import_compiler21.types.stringLiteral(registerId)
3817
- )
3818
- )
3819
- );
3820
- }
3821
- }
3822
- }
3823
- function getRegisteredFnExpression2(node) {
3824
- const { extra } = node;
3825
- if (isRegisteredFnExtra(extra)) {
3826
- return callRuntime(
3827
- "register",
3828
- simplifyFunction(node),
3829
- import_compiler21.types.stringLiteral(extra.registerId),
3830
- (extra.referencedBindingsInFunction || extra.referencesScope) && getScopeIdIdentifier(extra.section)
3831
- );
3832
- }
3833
- }
3834
-
3835
4107
  // src/translator/visitors/program/index.ts
3836
4108
  var cleanIdentifier;
3837
4109
  var scopeIdentifier;
@@ -3851,18 +4123,27 @@ var program_default = {
3851
4123
  enter(program) {
3852
4124
  startSection(program);
3853
4125
  trackParamsReferences(program, 2 /* input */);
4126
+ const programExtra = program.node.extra ??= {};
3854
4127
  const inputBinding = program.node.params[0].extra?.binding;
3855
4128
  if (inputBinding) {
3856
4129
  inputBinding.nullable = false;
3857
4130
  }
3858
- (program.node.extra ??= {}).domExports = {
4131
+ programExtra.domExports = {
3859
4132
  template: generateUid("template"),
3860
4133
  walks: generateUid("walks"),
3861
4134
  setup: generateUid("setup"),
3862
- input: void 0,
4135
+ input: void 0
3863
4136
  // TODO look into recursive components with fine grained params.
3864
- closures: generateUid("closures")
3865
4137
  };
4138
+ for (const child of program.get("body")) {
4139
+ if (isCoreTagName(child, "return")) {
4140
+ const { value } = getKnownAttrValues(child.node);
4141
+ if (value) {
4142
+ programExtra.returnValueExpr = value.extra ??= {};
4143
+ }
4144
+ break;
4145
+ }
4146
+ }
3866
4147
  },
3867
4148
  exit(program) {
3868
4149
  finalizeReferences();
@@ -3925,6 +4206,17 @@ var program_default = {
3925
4206
  }
3926
4207
  }
3927
4208
  };
4209
+ function resolveSerializeReasonId(inputSerializeReasons, reason) {
4210
+ const id = findIndexSorted(
4211
+ compareSerializeReasons,
4212
+ inputSerializeReasons,
4213
+ reason
4214
+ );
4215
+ if (id === -1) {
4216
+ throw new Error("Unable to resolve serialize reason against input");
4217
+ }
4218
+ return id;
4219
+ }
3928
4220
  function resolveRelativeToEntry(entryFile, file, req) {
3929
4221
  return file === entryFile ? (0, import_babel_utils16.resolveRelativePath)(file, req) : (0, import_babel_utils16.resolveRelativePath)(
3930
4222
  entryFile,
@@ -3965,7 +4257,10 @@ function createScopeReadPattern(section, referencedBindings) {
3965
4257
  for (; i <= relativeDepth; i++) {
3966
4258
  const nestedPattern = import_compiler23.types.objectPattern([]);
3967
4259
  prev.properties.push(
3968
- import_compiler23.types.objectProperty(import_compiler23.types.identifier("_"), nestedPattern)
4260
+ import_compiler23.types.objectProperty(
4261
+ import_compiler23.types.identifier(getAccessorProp().Owner),
4262
+ nestedPattern
4263
+ )
3969
4264
  );
3970
4265
  nestedPatterns.push(nestedPattern);
3971
4266
  prev = nestedPattern;
@@ -3987,7 +4282,7 @@ function getScopeExpression(section, targetSection) {
3987
4282
  let scope = scopeIdentifier ?? import_compiler23.types.identifier("undefined");
3988
4283
  const diff = section.depth - targetSection.depth;
3989
4284
  for (let i = 0; i < diff; i++) {
3990
- scope = import_compiler23.types.memberExpression(scope, import_compiler23.types.identifier("_"));
4285
+ scope = import_compiler23.types.memberExpression(scope, import_compiler23.types.identifier(getAccessorProp().Owner));
3991
4286
  }
3992
4287
  if (diff < 0) {
3993
4288
  throw new Error("Unable to find scope for reference.");
@@ -4015,7 +4310,7 @@ function withPreviousLocation(newNode, originalNode) {
4015
4310
  var kIsInvoked = Symbol("hoist is invoked");
4016
4311
  var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
4017
4312
  var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
4018
- function createBinding(name2, type, section, upstreamAlias, upstreamExpression, property, loc = null, declared = false) {
4313
+ function createBinding(name2, type, section, upstreamAlias, property, loc = null, declared = false) {
4019
4314
  const id = getNextBindingId();
4020
4315
  const binding = {
4021
4316
  id,
@@ -4033,11 +4328,10 @@ function createBinding(name2, type, section, upstreamAlias, upstreamExpression,
4033
4328
  hoists: /* @__PURE__ */ new Map(),
4034
4329
  propertyAliases: /* @__PURE__ */ new Map(),
4035
4330
  upstreamAlias,
4036
- upstreamExpression,
4037
4331
  downstreamExpressions: /* @__PURE__ */ new Set(),
4038
4332
  scopeOffset: void 0,
4039
4333
  export: void 0,
4040
- nullable: !upstreamExpression?.confident || upstreamExpression.computed == null
4334
+ nullable: true
4041
4335
  };
4042
4336
  if (property) {
4043
4337
  if (declared) upstreamAlias.nullable = false;
@@ -4056,27 +4350,25 @@ function createBinding(name2, type, section, upstreamAlias, upstreamExpression,
4056
4350
  getBindings().add(binding);
4057
4351
  return binding;
4058
4352
  }
4059
- function trackVarReferences(tag, type, upstreamAlias, upstreamExpression) {
4353
+ function trackVarReferences(tag, type, upstreamAlias) {
4060
4354
  const tagVar = tag.node.var;
4061
4355
  if (tagVar) {
4062
4356
  const section = getOrCreateSection(tag);
4063
4357
  const canonicalUpstreamAlias = getCanonicalBinding(upstreamAlias);
4064
- if (upstreamAlias && upstreamExpression) upstreamExpression.pruned = true;
4065
4358
  createBindingsAndTrackReferences(
4066
4359
  tagVar,
4067
- type,
4360
+ upstreamAlias ? upstreamAlias.type : type,
4068
4361
  tag.scope,
4069
4362
  section,
4070
4363
  canonicalUpstreamAlias,
4071
- upstreamExpression,
4072
4364
  void 0
4073
4365
  );
4366
+ return tagVar.extra?.binding;
4074
4367
  }
4075
4368
  }
4076
- function trackParamsReferences(body, type, upstreamAlias, upstreamExpression) {
4369
+ function trackParamsReferences(body, type, upstreamAlias) {
4077
4370
  const params = body.node.params;
4078
4371
  if (body.node.body.length && params.length) {
4079
- if (upstreamAlias && upstreamExpression) upstreamExpression.pruned = true;
4080
4372
  const section = getOrCreateSection(body);
4081
4373
  const canonicalUpstreamAlias = getCanonicalBinding(upstreamAlias);
4082
4374
  const paramsBinding = canonicalUpstreamAlias || ((body.node.extra ??= {}).binding = createBinding(
@@ -4084,7 +4376,6 @@ function trackParamsReferences(body, type, upstreamAlias, upstreamExpression) {
4084
4376
  type,
4085
4377
  section,
4086
4378
  canonicalUpstreamAlias,
4087
- upstreamExpression,
4088
4379
  void 0
4089
4380
  ));
4090
4381
  section.params = paramsBinding;
@@ -4095,10 +4386,10 @@ function trackParamsReferences(body, type, upstreamAlias, upstreamExpression) {
4095
4386
  body.scope,
4096
4387
  section,
4097
4388
  paramsBinding,
4098
- upstreamExpression,
4099
4389
  i + ""
4100
4390
  );
4101
4391
  }
4392
+ return paramsBinding;
4102
4393
  }
4103
4394
  }
4104
4395
  function trackHoistedReference(referencePath, binding) {
@@ -4116,7 +4407,6 @@ function trackHoistedReference(referencePath, binding) {
4116
4407
  hoistSection,
4117
4408
  void 0,
4118
4409
  void 0,
4119
- void 0,
4120
4410
  binding.loc,
4121
4411
  true
4122
4412
  )
@@ -4141,9 +4431,8 @@ function trackHoistedReference(referencePath, binding) {
4141
4431
  hoistedBinding
4142
4432
  );
4143
4433
  }
4144
- function trackReferencesForBinding(babelBinding) {
4145
- const { identifier, referencePaths, constantViolations } = babelBinding;
4146
- const binding = identifier.extra.binding;
4434
+ function trackReferencesForBinding(babelBinding, binding) {
4435
+ const { referencePaths, constantViolations } = babelBinding;
4147
4436
  for (const referencePath of referencePaths) {
4148
4437
  const referenceSection = getOrCreateSection(referencePath);
4149
4438
  if (isSameOrChildSection(binding.section, referenceSection)) {
@@ -4184,20 +4473,21 @@ function setReferencesScope(path5) {
4184
4473
  (fnRoot.node.extra ??= {}).referencesScope = true;
4185
4474
  }
4186
4475
  }
4187
- function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, upstreamExpression, property) {
4476
+ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property) {
4188
4477
  switch (lVal.type) {
4189
4478
  case "Identifier":
4190
- (lVal.extra ??= {}).binding = createBinding(
4191
- lVal.name,
4192
- type,
4193
- section,
4194
- upstreamAlias,
4195
- upstreamExpression,
4196
- property,
4197
- lVal.loc,
4198
- true
4479
+ trackReferencesForBinding(
4480
+ scope.getBinding(lVal.name),
4481
+ (lVal.extra ??= {}).binding = createBinding(
4482
+ lVal.name,
4483
+ type,
4484
+ section,
4485
+ upstreamAlias,
4486
+ property,
4487
+ lVal.loc,
4488
+ true
4489
+ )
4199
4490
  );
4200
- trackReferencesForBinding(scope.getBinding(lVal.name));
4201
4491
  break;
4202
4492
  case "ObjectPattern": {
4203
4493
  const patternBinding = (property ? upstreamAlias.propertyAliases.get(property) : upstreamAlias) || ((lVal.extra ??= {}).binding = createBinding(
@@ -4205,7 +4495,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4205
4495
  type,
4206
4496
  section,
4207
4497
  upstreamAlias,
4208
- void 0,
4209
4498
  property,
4210
4499
  lVal.loc
4211
4500
  ));
@@ -4217,7 +4506,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4217
4506
  scope,
4218
4507
  section,
4219
4508
  patternBinding,
4220
- void 0,
4221
4509
  property
4222
4510
  );
4223
4511
  } else {
@@ -4235,7 +4523,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4235
4523
  scope,
4236
4524
  section,
4237
4525
  patternBinding,
4238
- void 0,
4239
4526
  key
4240
4527
  );
4241
4528
  }
@@ -4248,7 +4535,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4248
4535
  type,
4249
4536
  section,
4250
4537
  upstreamAlias,
4251
- void 0,
4252
4538
  property,
4253
4539
  lVal.loc
4254
4540
  ));
@@ -4263,7 +4549,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4263
4549
  scope,
4264
4550
  section,
4265
4551
  patternBinding,
4266
- void 0,
4267
4552
  property
4268
4553
  );
4269
4554
  } else {
@@ -4273,7 +4558,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4273
4558
  scope,
4274
4559
  section,
4275
4560
  patternBinding,
4276
- void 0,
4277
4561
  `${i}`
4278
4562
  );
4279
4563
  }
@@ -4288,7 +4572,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4288
4572
  scope,
4289
4573
  section,
4290
4574
  upstreamAlias,
4291
- void 0,
4292
4575
  property
4293
4576
  );
4294
4577
  break;
@@ -4318,7 +4601,6 @@ function trackReference(referencePath, binding) {
4318
4601
  reference.type,
4319
4602
  reference.section,
4320
4603
  reference,
4321
- void 0,
4322
4604
  prop
4323
4605
  );
4324
4606
  }
@@ -4342,8 +4624,13 @@ var [getMergedReferences] = createProgramState(
4342
4624
  () => /* @__PURE__ */ new Map()
4343
4625
  );
4344
4626
  function mergeReferences(section, target, nodes) {
4345
- (target.extra ??= {}).section = section;
4627
+ const targetExtra = target.extra ??= {};
4628
+ targetExtra.section = section;
4346
4629
  getMergedReferences().set(target, nodes);
4630
+ return targetExtra;
4631
+ }
4632
+ function compareSerializeReasons(a, b) {
4633
+ return Array.isArray(a) ? Array.isArray(b) ? compareIntersections(a, b) : -1 : Array.isArray(b) ? 1 : bindingUtil.compare(a, b);
4347
4634
  }
4348
4635
  function compareIntersections(a, b) {
4349
4636
  const len = a.length;
@@ -4449,29 +4736,20 @@ function finalizeReferences() {
4449
4736
  }
4450
4737
  }
4451
4738
  forEachSection((section) => {
4739
+ if (isSectionWithHoists(section)) {
4740
+ forceSectionSerialize(section);
4741
+ }
4452
4742
  if (section.parent && section.isBranch && section.sectionAccessor && section.upstreamExpression) {
4453
- const tagSection = section.parent;
4454
- const tagExtra = section.upstreamExpression;
4455
- const nodeBinding = section.sectionAccessor.binding;
4456
- if (isSectionWithHoists(section)) {
4457
- forcePropSerialize(tagSection, tagExtra, kBranchSerializeReason);
4458
- } else {
4459
- addPropSerializeReasonRef(
4460
- tagSection,
4461
- tagExtra,
4462
- kBranchSerializeReason,
4463
- getDirectClosures(section)
4464
- );
4465
- }
4466
- addPropSerializeReasonExpr(
4467
- tagSection,
4468
- tagExtra,
4469
- kBranchSerializeReason,
4470
- tagExtra
4743
+ addSectionSerializeReasonRef(section, getDirectClosures(section));
4744
+ addSectionSerializeReasonExpr(section, section.upstreamExpression);
4745
+ addBindingSerializeReasonExpr(
4746
+ section.parent,
4747
+ section.sectionAccessor.binding,
4748
+ section.upstreamExpression
4471
4749
  );
4472
- addBindingSerializeReasonExpr(tagSection, nodeBinding, tagExtra);
4473
4750
  }
4474
4751
  });
4752
+ forEachSection(applySerializeReasonExprs);
4475
4753
  forEachSection((section) => {
4476
4754
  const intersections = intersectionsBySection.get(section);
4477
4755
  if (intersections) {
@@ -4518,6 +4796,12 @@ function finalizeReferences() {
4518
4796
  }
4519
4797
  addBindingSerializeReason(closure.section, closure, serializeReason);
4520
4798
  }
4799
+ if (closure.sources) {
4800
+ addSectionSerializeReason(
4801
+ closure.section,
4802
+ getBindingSerializeReason(closure.section, closure)
4803
+ );
4804
+ }
4521
4805
  if (closure.serializeSources && isDynamicClosure(section, closure)) {
4522
4806
  addBindingSerializeReason(
4523
4807
  closure.section,
@@ -4534,19 +4818,26 @@ function finalizeReferences() {
4534
4818
  }
4535
4819
  });
4536
4820
  });
4821
+ let inputSerializeReasons;
4537
4822
  forEachSection((section) => {
4538
- const serializeReasonExprs2 = consumeSerializeReasonExprs(section);
4539
- if (serializeReasonExprs2) {
4540
- for (const [key, exprs] of serializeReasonExprs2) {
4541
- const reason = getSerializeSourcesForExprs(exprs);
4542
- if (reason) {
4543
- section.serializeReasons.set(
4544
- key,
4545
- mergeSerializeReasons(section.serializeReasons.get(key), reason)
4546
- );
4547
- }
4823
+ finalizeSectionSerializeReasons(section);
4824
+ if (section.serializeReason && section.serializeReason !== true) {
4825
+ inputSerializeReasons = inputSerializeReasons ? addSorted(
4826
+ compareSerializeReasons,
4827
+ inputSerializeReasons,
4828
+ section.serializeReason
4829
+ ) : [section.serializeReason];
4830
+ }
4831
+ for (const [, reason] of section.serializeReasons) {
4832
+ if (reason !== true) {
4833
+ inputSerializeReasons = inputSerializeReasons ? addSorted(compareSerializeReasons, inputSerializeReasons, reason) : [reason];
4548
4834
  }
4549
4835
  }
4836
+ });
4837
+ const programExtra = (0, import_babel_utils17.getProgram)().node.extra;
4838
+ programExtra.returnSerializeReason = programExtra.returnValueExpr && getSerializeSourcesForExpr(programExtra.returnValueExpr);
4839
+ programExtra.inputSerializeReasons = inputSerializeReasons;
4840
+ forEachSection((section) => {
4550
4841
  let intersectionIndex = 0;
4551
4842
  const intersections = intersectionsBySection.get(section) || [];
4552
4843
  const { id, bindings: bindings2 } = section;
@@ -4588,33 +4879,65 @@ function getMaxOwnSourceOffset(intersection, section) {
4588
4879
  return scopeOffset;
4589
4880
  }
4590
4881
  var intersectionMeta = /* @__PURE__ */ new WeakMap();
4882
+ function setBindingValueExpr(binding, valueExpr) {
4883
+ bindingValueExprs.set(binding, valueExpr || false);
4884
+ }
4885
+ var resolvedSources = /* @__PURE__ */ new WeakSet();
4886
+ var bindingValueExprs = /* @__PURE__ */ new WeakMap();
4591
4887
  function resolveBindingSources(binding) {
4592
- const derived = /* @__PURE__ */ new Set();
4593
- let onlyInputSources = true;
4594
- let sources;
4595
- crawl(binding);
4596
- binding.sources = sources;
4597
- binding.serializeSources = sources ? onlyInputSources ? sources : true : void 0;
4598
- function crawl(binding2) {
4599
- if (binding2.type === 4 /* derived */ || binding2.type === 3 /* param */) {
4600
- let alias;
4601
- let curBinding = binding2;
4602
- while (alias = curBinding.upstreamAlias) {
4603
- curBinding = alias;
4604
- }
4605
- if (curBinding.upstreamExpression) {
4606
- if (derived.has(curBinding)) return;
4607
- derived.add(curBinding);
4608
- forEach(curBinding.upstreamExpression.referencedBindings, crawl);
4609
- } else if (curBinding.type === 2 /* input */) {
4610
- sources = bindingUtil.add(sources, binding2);
4611
- } else {
4612
- onlyInputSources = false;
4613
- sources = bindingUtil.add(sources, curBinding);
4888
+ if (resolvedSources.has(binding)) return;
4889
+ resolvedSources.add(binding);
4890
+ switch (binding.type) {
4891
+ case 1 /* let */:
4892
+ binding.sources = binding;
4893
+ binding.serializeSources = true;
4894
+ return;
4895
+ case 2 /* input */:
4896
+ binding.sources = binding;
4897
+ binding.serializeSources = binding;
4898
+ return;
4899
+ }
4900
+ let alias;
4901
+ let source = binding;
4902
+ while (alias = source.upstreamAlias) {
4903
+ source = alias;
4904
+ }
4905
+ if (source === binding) {
4906
+ resolveDerivedSources(binding);
4907
+ return;
4908
+ }
4909
+ if (!resolvedSources.has(source)) {
4910
+ resolvedSources.add(source);
4911
+ resolveDerivedSources(source);
4912
+ }
4913
+ binding.sources = source.sources;
4914
+ binding.serializeSources = source.serializeSources;
4915
+ }
4916
+ function resolveDerivedSources(binding) {
4917
+ const exprs = bindingValueExprs.get(binding);
4918
+ bindingValueExprs.delete(binding);
4919
+ if (exprs === void 0 || exprs === true) {
4920
+ binding.serializeSources = true;
4921
+ binding.sources = binding;
4922
+ } else if (exprs) {
4923
+ const seen = /* @__PURE__ */ new Set();
4924
+ let onlyInputSources = true;
4925
+ let sources;
4926
+ forEach(exprs, (expr) => {
4927
+ if (isReferencedExtra(expr)) {
4928
+ forEach(expr.referencedBindings, (ref) => {
4929
+ if (!seen.has(ref)) {
4930
+ seen.add(ref);
4931
+ resolveBindingSources(ref);
4932
+ sources = bindingUtil.union(sources, ref.sources);
4933
+ onlyInputSources &&= ref.serializeSources !== true;
4934
+ }
4935
+ });
4614
4936
  }
4615
- } else {
4616
- onlyInputSources = false;
4617
- sources = bindingUtil.add(sources, binding2);
4937
+ });
4938
+ if (sources) {
4939
+ binding.sources = sources;
4940
+ binding.serializeSources = onlyInputSources ? sources : true;
4618
4941
  }
4619
4942
  }
4620
4943
  }
@@ -4843,22 +5166,16 @@ function isRegisteredFnExtra(extra) {
4843
5166
  var kDOMBinding = Symbol("await tag dom binding");
4844
5167
  var await_default = {
4845
5168
  analyze(tag) {
4846
- (0, import_babel_utils17.assertNoVar)(tag);
4847
- (0, import_babel_utils17.assertNoArgs)(tag);
5169
+ (0, import_babel_utils18.assertNoVar)(tag);
5170
+ (0, import_babel_utils18.assertNoArgs)(tag);
4848
5171
  assertNoSpreadAttrs(tag);
4849
- (0, import_babel_utils17.assertNoAttributeTags)(tag);
5172
+ (0, import_babel_utils18.assertNoAttributeTags)(tag);
4850
5173
  const { node } = tag;
4851
5174
  const tagBody = tag.get("body");
4852
5175
  const section = getOrCreateSection(tag);
4853
5176
  const [valueAttr] = node.attributes;
4854
5177
  const tagExtra = tag.node.extra ??= {};
4855
- tagExtra[kDOMBinding] = createBinding(
4856
- "#text",
4857
- 0 /* dom */,
4858
- section,
4859
- void 0,
4860
- tagExtra
4861
- );
5178
+ tagExtra[kDOMBinding] = createBinding("#text", 0 /* dom */, section);
4862
5179
  if (!valueAttr) {
4863
5180
  throw tag.get("name").buildCodeFrameError("The `await` tag requires a value.");
4864
5181
  }
@@ -4876,13 +5193,12 @@ var await_default = {
4876
5193
  );
4877
5194
  }
4878
5195
  const bodySection = startSection(tagBody);
5196
+ const valueExtra = evaluate(valueAttr.value);
4879
5197
  getOrCreateSection(tag);
4880
- trackParamsReferences(
4881
- tagBody,
4882
- 3 /* param */,
4883
- void 0,
4884
- evaluate(valueAttr.value)
4885
- );
5198
+ const paramsBinding = trackParamsReferences(tagBody, 3 /* param */);
5199
+ if (paramsBinding) {
5200
+ setBindingValueExpr(paramsBinding, valueExtra);
5201
+ }
4886
5202
  bodySection.upstreamExpression = valueAttr.value.extra;
4887
5203
  },
4888
5204
  translate: translateByTarget({
@@ -4970,7 +5286,7 @@ var await_default = {
4970
5286
 
4971
5287
  // src/translator/core/client.ts
4972
5288
  var import_compiler26 = require("@marko/compiler");
4973
- var import_babel_utils18 = require("@marko/compiler/babel-utils");
5289
+ var import_babel_utils19 = require("@marko/compiler/babel-utils");
4974
5290
  var client_default = {
4975
5291
  parse(tag) {
4976
5292
  const {
@@ -4980,7 +5296,7 @@ var client_default = {
4980
5296
  const rawValue = node.rawValue;
4981
5297
  const code = rawValue.replace(/^client\s*/, "").trim();
4982
5298
  const start = node.name.start + (rawValue.length - code.length);
4983
- let body = (0, import_babel_utils18.parseStatements)(file, code, start, start + code.length);
5299
+ let body = (0, import_babel_utils19.parseStatements)(file, code, start, start + code.length);
4984
5300
  if (body.length === 1 && import_compiler26.types.isBlockStatement(body[0])) {
4985
5301
  body = body[0].body;
4986
5302
  }
@@ -5001,7 +5317,7 @@ var client_default = {
5001
5317
 
5002
5318
  // src/translator/core/const.ts
5003
5319
  var import_compiler28 = require("@marko/compiler");
5004
- var import_babel_utils19 = require("@marko/compiler/babel-utils");
5320
+ var import_babel_utils20 = require("@marko/compiler/babel-utils");
5005
5321
 
5006
5322
  // src/translator/util/translate-var.ts
5007
5323
  var import_compiler27 = require("@marko/compiler");
@@ -5020,8 +5336,8 @@ function translateVar(tag, initialValue, kind = "const") {
5020
5336
  // src/translator/core/const.ts
5021
5337
  var const_default = {
5022
5338
  analyze(tag) {
5023
- (0, import_babel_utils19.assertNoArgs)(tag);
5024
- (0, import_babel_utils19.assertNoParams)(tag);
5339
+ (0, import_babel_utils20.assertNoArgs)(tag);
5340
+ (0, import_babel_utils20.assertNoParams)(tag);
5025
5341
  assertNoBodyContent(tag);
5026
5342
  const { node } = tag;
5027
5343
  const [valueAttr] = node.attributes;
@@ -5036,14 +5352,16 @@ var const_default = {
5036
5352
  "The `const` tag only supports the `value` attribute."
5037
5353
  );
5038
5354
  }
5355
+ const valueExtra = evaluate(valueAttr.value);
5039
5356
  const upstreamAlias = import_compiler28.types.isIdentifier(valueAttr.value) ? tag.scope.getBinding(valueAttr.value.name)?.identifier.extra?.binding : void 0;
5040
- trackVarReferences(
5041
- tag,
5042
- 4 /* derived */,
5043
- upstreamAlias,
5044
- evaluate(valueAttr.value)
5045
- // TODO could perform a more extensive "nullable" check.
5046
- );
5357
+ if (upstreamAlias) {
5358
+ valueExtra.pruned = true;
5359
+ }
5360
+ const binding = trackVarReferences(tag, 4 /* derived */, upstreamAlias);
5361
+ if (binding) {
5362
+ if (!valueExtra.nullable) binding.nullable = false;
5363
+ setBindingValueExpr(binding, valueExtra);
5364
+ }
5047
5365
  },
5048
5366
  translate: {
5049
5367
  exit(tag) {
@@ -5078,13 +5396,13 @@ var const_default = {
5078
5396
 
5079
5397
  // src/translator/core/debug.ts
5080
5398
  var import_compiler29 = require("@marko/compiler");
5081
- var import_babel_utils20 = require("@marko/compiler/babel-utils");
5399
+ var import_babel_utils21 = require("@marko/compiler/babel-utils");
5082
5400
  var debug_default = {
5083
5401
  analyze(tag) {
5084
5402
  const [valueAttr] = tag.node.attributes;
5085
- (0, import_babel_utils20.assertNoVar)(tag);
5086
- (0, import_babel_utils20.assertNoArgs)(tag);
5087
- (0, import_babel_utils20.assertNoParams)(tag);
5403
+ (0, import_babel_utils21.assertNoVar)(tag);
5404
+ (0, import_babel_utils21.assertNoArgs)(tag);
5405
+ (0, import_babel_utils21.assertNoParams)(tag);
5088
5406
  assertNoBodyContent(tag);
5089
5407
  if (tag.node.attributes.length > 1 || tag.node.attributes.length === 1 && (!import_compiler29.types.isMarkoAttribute(valueAttr) || !valueAttr.default && valueAttr.name !== "value")) {
5090
5408
  throw tag.get("name").buildCodeFrameError(
@@ -5121,11 +5439,11 @@ var debug_default = {
5121
5439
 
5122
5440
  // src/translator/core/define.ts
5123
5441
  var import_compiler35 = require("@marko/compiler");
5124
- var import_babel_utils26 = require("@marko/compiler/babel-utils");
5442
+ var import_babel_utils27 = require("@marko/compiler/babel-utils");
5125
5443
 
5126
5444
  // src/translator/util/nested-attribute-tags.ts
5127
5445
  var import_compiler30 = require("@marko/compiler");
5128
- var import_babel_utils21 = require("@marko/compiler/babel-utils");
5446
+ var import_babel_utils22 = require("@marko/compiler/babel-utils");
5129
5447
  var attrTagToIdentifierLookup = /* @__PURE__ */ new WeakMap();
5130
5448
  function getAttrTagIdentifier(meta) {
5131
5449
  let name2 = attrTagToIdentifierLookup.get(meta);
@@ -5145,13 +5463,13 @@ function analyzeAttributeTags(tag) {
5145
5463
  const sampleAttrTagsForControlFlow = /* @__PURE__ */ new Map();
5146
5464
  for (const child of attrTags2) {
5147
5465
  if (child.isMarkoTag()) {
5148
- if ((0, import_babel_utils21.isAttributeTag)(child)) {
5466
+ if ((0, import_babel_utils22.isAttributeTag)(child)) {
5149
5467
  const name2 = getTagName(child);
5150
5468
  lookup[name2] ||= createAttrTagMeta(name2, [name2]);
5151
5469
  (attrTagNodesByName[name2] ||= []).push(child);
5152
5470
  analyzeAttributeTags(child);
5153
5471
  } else {
5154
- const isRepeated = (0, import_babel_utils21.isLoopTag)(child);
5472
+ const isRepeated = (0, import_babel_utils22.isLoopTag)(child);
5155
5473
  let curGroup;
5156
5474
  for (const name2 of crawlAttrTags(child, attrTagNodesByName)) {
5157
5475
  const oldMeta = lookup[name2];
@@ -5206,7 +5524,7 @@ function crawlAttrTags(tag, attrTagNodesByName, attrTagNames = /* @__PURE__ */ n
5206
5524
  const attrTags2 = tag.node.body.attributeTags ? tag.get("body").get("body") : tag.get("attributeTags");
5207
5525
  for (const child of attrTags2) {
5208
5526
  if (child.isMarkoTag()) {
5209
- if ((0, import_babel_utils21.isAttributeTag)(child)) {
5527
+ if ((0, import_babel_utils22.isAttributeTag)(child)) {
5210
5528
  const tagName = getTagName(child);
5211
5529
  attrTagNames.add(tagName);
5212
5530
  (attrTagNodesByName[tagName] ||= []).push(child);
@@ -5247,19 +5565,19 @@ function getConditionRoot(tag) {
5247
5565
 
5248
5566
  // src/translator/util/translate-attrs.ts
5249
5567
  var import_compiler34 = require("@marko/compiler");
5250
- var import_babel_utils25 = require("@marko/compiler/babel-utils");
5568
+ var import_babel_utils26 = require("@marko/compiler/babel-utils");
5251
5569
 
5252
5570
  // src/translator/core/for.ts
5253
5571
  var import_compiler33 = require("@marko/compiler");
5254
- var import_babel_utils24 = require("@marko/compiler/babel-utils");
5572
+ var import_babel_utils25 = require("@marko/compiler/babel-utils");
5255
5573
 
5256
5574
  // src/translator/util/is-only-child-in-parent.ts
5257
5575
  var import_compiler32 = require("@marko/compiler");
5258
- var import_babel_utils23 = require("@marko/compiler/babel-utils");
5576
+ var import_babel_utils24 = require("@marko/compiler/babel-utils");
5259
5577
 
5260
5578
  // src/translator/visitors/tag/native-tag.ts
5261
5579
  var import_compiler31 = require("@marko/compiler");
5262
- var import_babel_utils22 = require("@marko/compiler/babel-utils");
5580
+ var import_babel_utils23 = require("@marko/compiler/babel-utils");
5263
5581
  var kNativeTagBinding = Symbol("native tag binding");
5264
5582
  var kSkipMark = Symbol("skip native tag mark");
5265
5583
  var kGetterId = Symbol("node getter id");
@@ -5361,9 +5679,9 @@ var native_tag_default = {
5361
5679
  },
5362
5680
  analyze: {
5363
5681
  enter(tag) {
5364
- (0, import_babel_utils22.assertNoArgs)(tag);
5365
- (0, import_babel_utils22.assertNoParams)(tag);
5366
- (0, import_babel_utils22.assertNoAttributeTags)(tag);
5682
+ (0, import_babel_utils23.assertNoArgs)(tag);
5683
+ (0, import_babel_utils23.assertNoParams)(tag);
5684
+ (0, import_babel_utils23.assertNoAttributeTags)(tag);
5367
5685
  const { node } = tag;
5368
5686
  if (node.var && !import_compiler31.types.isIdentifier(node.var)) {
5369
5687
  throw tag.get("var").buildCodeFrameError(
@@ -5416,7 +5734,7 @@ var native_tag_default = {
5416
5734
  0 /* dom */,
5417
5735
  tagSection
5418
5736
  );
5419
- (0, import_babel_utils22.getProgram)().node.extra.isInteractive ||= hasEventHandlers;
5737
+ (0, import_babel_utils23.getProgram)().node.extra.isInteractive ||= hasEventHandlers;
5420
5738
  if (spreadReferenceNodes) {
5421
5739
  if (relatedControllable && !relatedControllable.attrs.every(Boolean)) {
5422
5740
  for (const attr2 of relatedControllable.attrs) {
@@ -5438,6 +5756,7 @@ var native_tag_default = {
5438
5756
  );
5439
5757
  }
5440
5758
  if (node.var) {
5759
+ forceSectionSerialize(tagSection);
5441
5760
  forceBindingSerialize(tagSection, nodeBinding);
5442
5761
  const varBinding = tag.scope.getBinding(node.var.name);
5443
5762
  for (const referencePath of varBinding.referencePaths) {
@@ -5474,7 +5793,7 @@ var native_tag_default = {
5474
5793
  const nodeBinding = tagExtra[kNativeTagBinding];
5475
5794
  const isHTML = isOutputHTML();
5476
5795
  const name2 = tag.get("name");
5477
- const tagDef = (0, import_babel_utils22.getTagDef)(tag);
5796
+ const tagDef = (0, import_babel_utils23.getTagDef)(tag);
5478
5797
  const write2 = writeTo(tag);
5479
5798
  const tagSection = getSection(tag);
5480
5799
  if (isHTML && tagExtra.tagNameNullable) {
@@ -5491,7 +5810,6 @@ var native_tag_default = {
5491
5810
  serializeOwners(referenceSection, tagSection);
5492
5811
  }
5493
5812
  }
5494
- serializeSectionIfNeeded(tagSection, true);
5495
5813
  translateVar(
5496
5814
  tag,
5497
5815
  callRuntime(
@@ -5504,7 +5822,7 @@ var native_tag_default = {
5504
5822
  let getterFnIdentifier;
5505
5823
  if (getterId) {
5506
5824
  getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
5507
- (0, import_babel_utils22.getProgram)().node.body.push(
5825
+ (0, import_babel_utils23.getProgram)().node.body.push(
5508
5826
  import_compiler31.types.variableDeclaration("const", [
5509
5827
  import_compiler31.types.variableDeclarator(
5510
5828
  getterFnIdentifier,
@@ -5794,7 +6112,7 @@ var native_tag_default = {
5794
6112
  const tagExtra = tag.node.extra;
5795
6113
  const nodeBinding = tagExtra[kNativeTagBinding];
5796
6114
  const isHTML = isOutputHTML();
5797
- const openTagOnly = (0, import_babel_utils22.getTagDef)(tag)?.parseOptions?.openTagOnly;
6115
+ const openTagOnly = (0, import_babel_utils23.getTagDef)(tag)?.parseOptions?.openTagOnly;
5798
6116
  const selectArgs = isHTML && htmlSelectArgs.get(tag.node);
5799
6117
  const tagName = getTagName(tag);
5800
6118
  const tagSection = getSection(tag);
@@ -5822,12 +6140,11 @@ var native_tag_default = {
5822
6140
  } else {
5823
6141
  tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
5824
6142
  }
5825
- const serializeMarkerReason = nodeBinding && !tagExtra[kSkipMark] && getBindingSerializeReason(tagSection, nodeBinding);
5826
- const shouldMark = !!serializeMarkerReason;
6143
+ const markerSerializeReason = nodeBinding && !tagExtra[kSkipMark] && getBindingSerializeReason(tagSection, nodeBinding);
5827
6144
  if (!openTagOnly && !selectArgs) {
5828
6145
  writeTo(
5829
6146
  tag,
5830
- isHTML && !shouldMark && (tagName === "html" || tagName === "body")
6147
+ isHTML && !markerSerializeReason && (tagName === "html" || tagName === "body")
5831
6148
  )`</${tag.node.name}>`;
5832
6149
  }
5833
6150
  if (isHTML && tagExtra.tagNameNullable) {
@@ -5835,8 +6152,8 @@ var native_tag_default = {
5835
6152
  import_compiler31.types.ifStatement(tag.node.name, consumeHTML(tag))
5836
6153
  )[0].skip();
5837
6154
  }
5838
- if (shouldMark) {
5839
- markNode(tag, nodeBinding);
6155
+ if (markerSerializeReason) {
6156
+ markNode(tag, nodeBinding, markerSerializeReason);
5840
6157
  }
5841
6158
  exit2(tag);
5842
6159
  tag.remove();
@@ -5935,7 +6252,7 @@ function isOnlyChildInParent(tag, branchSize = 1) {
5935
6252
  return extra[kOnlyChildInParent];
5936
6253
  }
5937
6254
  const parentTag = getParentTag(tag);
5938
- if (parentTag && (0, import_babel_utils23.getTagDef)(parentTag)?.html) {
6255
+ if (parentTag && (0, import_babel_utils24.getTagDef)(parentTag)?.html) {
5939
6256
  return extra[kOnlyChildInParent] = tag.parent.body.length === branchSize;
5940
6257
  }
5941
6258
  return extra[kOnlyChildInParent] = false;
@@ -5961,11 +6278,10 @@ function getOptimizedOnlyChildNodeBinding(tag, section, branchSize = 1) {
5961
6278
  // src/translator/core/for.ts
5962
6279
  var for_default = {
5963
6280
  analyze(tag) {
5964
- const tagExtra = tag.node.extra ??= {};
5965
6281
  const isAttrTag = tag.node.body.attributeTags;
5966
6282
  let allowAttrs;
5967
- (0, import_babel_utils24.assertNoVar)(tag);
5968
- (0, import_babel_utils24.assertNoArgs)(tag);
6283
+ (0, import_babel_utils25.assertNoVar)(tag);
6284
+ (0, import_babel_utils25.assertNoArgs)(tag);
5969
6285
  assertNoSpreadAttrs(tag);
5970
6286
  switch (getForType(tag.node)) {
5971
6287
  case "of":
@@ -5985,7 +6301,7 @@ var for_default = {
5985
6301
  if (!isAttrTag) {
5986
6302
  allowAttrs.push("by");
5987
6303
  }
5988
- (0, import_babel_utils24.assertAllowedAttributes)(tag, allowAttrs);
6304
+ (0, import_babel_utils25.assertAllowedAttributes)(tag, allowAttrs);
5989
6305
  if (isAttrTag) return;
5990
6306
  const tagBody = tag.get("body");
5991
6307
  const bodySection = startSection(tagBody);
@@ -5995,8 +6311,15 @@ var for_default = {
5995
6311
  }
5996
6312
  const tagSection = getOrCreateSection(tag);
5997
6313
  const nodeBinding = getOptimizedOnlyChildNodeBinding(tag, tagSection);
5998
- trackParamsReferences(tagBody, 3 /* param */, void 0, tagExtra);
5999
- mergeReferences(tagSection, tag.node, getAllTagReferenceNodes(tag.node));
6314
+ const paramsBinding = trackParamsReferences(tagBody, 3 /* param */);
6315
+ const tagExtra = mergeReferences(
6316
+ tagSection,
6317
+ tag.node,
6318
+ getAllTagReferenceNodes(tag.node)
6319
+ );
6320
+ if (paramsBinding) {
6321
+ setBindingValueExpr(paramsBinding, tagExtra);
6322
+ }
6000
6323
  bodySection.sectionAccessor = {
6001
6324
  binding: nodeBinding,
6002
6325
  prefix: getAccessorPrefix().LoopScopeMap
@@ -6027,7 +6350,6 @@ var for_default = {
6027
6350
  const tagSection = getSection(tag);
6028
6351
  const bodySection = getSectionForBody(tagBody);
6029
6352
  const { node } = tag;
6030
- const tagExtra = node.extra;
6031
6353
  const onlyChildInParentOptimization = isOnlyChildInParent(tag);
6032
6354
  const nodeBinding = getOptimizedOnlyChildNodeBinding(tag, tagSection);
6033
6355
  const forAttrs = getKnownAttrValues(node);
@@ -6036,31 +6358,34 @@ var for_default = {
6036
6358
  const statements = [];
6037
6359
  const bodyStatements = node.body.body;
6038
6360
  const singleNodeOptimization = bodySection.content === null || bodySection.content.singleChild && bodySection.content.startType !== 4 /* Text */;
6039
- const branchSerializeReason = getPropSerializeReason(
6040
- tagSection,
6041
- tagExtra,
6042
- kBranchSerializeReason
6043
- );
6361
+ const branchSerializeReason = getSectionSerializeReason(bodySection);
6044
6362
  const markerSerializeReason = getBindingSerializeReason(
6045
6363
  tagSection,
6046
6364
  nodeBinding
6047
6365
  );
6048
- const serializeReason = branchSerializeReason || markerSerializeReason;
6049
6366
  if (markerSerializeReason && onlyChildInParentOptimization) {
6050
6367
  getParentTag(tag).node.extra[kSkipMark] = true;
6051
6368
  }
6052
6369
  flushInto(tag);
6053
6370
  writeHTMLResumeStatements(tagBody);
6054
6371
  const forTagArgs = getBaseArgsInForTag(forType, forAttrs);
6055
- const forTagHTMLRuntime = serializeReason ? forTypeToHTMLResumeRuntime(forType, singleNodeOptimization) : forTypeToRuntime(forType);
6372
+ const forTagHTMLRuntime = branchSerializeReason ? forTypeToHTMLResumeRuntime(forType, singleNodeOptimization) : forTypeToRuntime(forType);
6056
6373
  forTagArgs.push(
6057
6374
  import_compiler33.types.arrowFunctionExpression(params, import_compiler33.types.blockStatement(bodyStatements))
6058
6375
  );
6059
- if (serializeReason) {
6376
+ if (branchSerializeReason) {
6060
6377
  forTagArgs.push(
6061
6378
  forAttrs.by || import_compiler33.types.numericLiteral(0),
6062
6379
  getScopeIdIdentifier(tagSection),
6063
- getScopeAccessorLiteral(nodeBinding)
6380
+ getScopeAccessorLiteral(nodeBinding),
6381
+ branchSerializeReason !== true && markerSerializeReason && markerSerializeReason !== true && !bindingUtil.isSuperset(
6382
+ branchSerializeReason,
6383
+ markerSerializeReason
6384
+ ) ? import_compiler33.types.logicalExpression(
6385
+ "||",
6386
+ getSerializeGuard(branchSerializeReason),
6387
+ getSerializeGuard(markerSerializeReason)
6388
+ ) : getSerializeGuard(branchSerializeReason)
6064
6389
  );
6065
6390
  if (onlyChildInParentOptimization) {
6066
6391
  forTagArgs.push(import_compiler33.types.numericLiteral(1));
@@ -6315,7 +6640,7 @@ function translateAttrs(tag, templateExports, statements = [], contentKey = "con
6315
6640
  for (let i = 0; i < attrTags2.length; i++) {
6316
6641
  const child = attrTags2[i];
6317
6642
  if (child.isMarkoTag()) {
6318
- if ((0, import_babel_utils25.isAttributeTag)(child)) {
6643
+ if ((0, import_babel_utils26.isAttributeTag)(child)) {
6319
6644
  const attrTagMeta = attrTagLookup[getTagName(child)];
6320
6645
  if (attrTagMeta.dynamic) {
6321
6646
  i = addDynamicAttrTagStatements(
@@ -6413,7 +6738,7 @@ function getTranslatedBodyContentProperty(props) {
6413
6738
  function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements, templateExports, contentKey = "content") {
6414
6739
  const tag = attrTags2[index];
6415
6740
  if (tag.isMarkoTag()) {
6416
- if ((0, import_babel_utils25.isAttributeTag)(tag)) {
6741
+ if ((0, import_babel_utils26.isAttributeTag)(tag)) {
6417
6742
  const attrTagMeta = attrTagLookup[getTagName(tag)];
6418
6743
  if (usesExport(templateExports, attrTagMeta.name) && attrTagMeta.dynamic) {
6419
6744
  const translatedAttrTag = translateAttrs(
@@ -6618,7 +6943,7 @@ function buildContent(body) {
6618
6943
  }
6619
6944
  function getNonAttributeTagParent(tag) {
6620
6945
  let cur = tag;
6621
- while ((0, import_babel_utils25.isAttributeTag)(cur) || (0, import_babel_utils25.isTransparentTag)(cur)) {
6946
+ while ((0, import_babel_utils26.isAttributeTag)(cur) || (0, import_babel_utils26.isTransparentTag)(cur)) {
6622
6947
  cur = getParentTag(cur);
6623
6948
  }
6624
6949
  return cur;
@@ -6627,7 +6952,7 @@ function getNonAttributeTagParent(tag) {
6627
6952
  // src/translator/core/define.ts
6628
6953
  var define_default = {
6629
6954
  analyze(tag) {
6630
- (0, import_babel_utils26.assertNoArgs)(tag);
6955
+ (0, import_babel_utils27.assertNoArgs)(tag);
6631
6956
  if (!tag.node.var) {
6632
6957
  throw tag.get("name").buildCodeFrameError("The `define` tag requires a tag variable.");
6633
6958
  }
@@ -6696,17 +7021,17 @@ var define_default = {
6696
7021
 
6697
7022
  // src/translator/core/effect.ts
6698
7023
  var import_compiler36 = require("@marko/compiler");
6699
- var import_babel_utils27 = require("@marko/compiler/babel-utils");
7024
+ var import_babel_utils28 = require("@marko/compiler/babel-utils");
6700
7025
  var effect_default = {
6701
7026
  migrate: [
6702
7027
  (tag) => {
6703
- (0, import_babel_utils27.assertNoArgs)(tag);
6704
- (0, import_babel_utils27.assertNoParams)(tag);
7028
+ (0, import_babel_utils28.assertNoArgs)(tag);
7029
+ (0, import_babel_utils28.assertNoParams)(tag);
6705
7030
  assertNoBodyContent(tag);
6706
- (0, import_babel_utils27.assertNoAttributeTags)(tag);
7031
+ (0, import_babel_utils28.assertNoAttributeTags)(tag);
6707
7032
  assertNoSpreadAttrs(tag);
6708
- (0, import_babel_utils27.assertAllowedAttributes)(tag, ["value"]);
6709
- (0, import_babel_utils27.diagnosticDeprecate)(tag, {
7033
+ (0, import_babel_utils28.assertAllowedAttributes)(tag, ["value"]);
7034
+ (0, import_babel_utils28.diagnosticDeprecate)(tag, {
6710
7035
  label: "The 'effect' tag has been replaced by the 'script' tag.",
6711
7036
  fix() {
6712
7037
  const { node } = tag;
@@ -6729,12 +7054,12 @@ var effect_default = {
6729
7054
  };
6730
7055
 
6731
7056
  // src/translator/core/export.ts
6732
- var import_babel_utils28 = require("@marko/compiler/babel-utils");
7057
+ var import_babel_utils29 = require("@marko/compiler/babel-utils");
6733
7058
  var export_default = {
6734
7059
  parse(tag) {
6735
7060
  const { node } = tag;
6736
7061
  tag.replaceWith(
6737
- (0, import_babel_utils28.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end)[0]
7062
+ (0, import_babel_utils29.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end)[0]
6738
7063
  );
6739
7064
  },
6740
7065
  parseOptions: {
@@ -6750,14 +7075,14 @@ var export_default = {
6750
7075
 
6751
7076
  // src/translator/core/html-comment.ts
6752
7077
  var import_compiler37 = require("@marko/compiler");
6753
- var import_babel_utils29 = require("@marko/compiler/babel-utils");
7078
+ var import_babel_utils30 = require("@marko/compiler/babel-utils");
6754
7079
  var kNodeBinding = Symbol("comment tag binding");
6755
7080
  var kGetterId2 = Symbol("node getter id");
6756
7081
  var html_comment_default = {
6757
7082
  analyze(tag) {
6758
- (0, import_babel_utils29.assertNoArgs)(tag);
6759
- (0, import_babel_utils29.assertNoParams)(tag);
6760
- (0, import_babel_utils29.assertNoAttributes)(tag);
7083
+ (0, import_babel_utils30.assertNoArgs)(tag);
7084
+ (0, import_babel_utils30.assertNoParams)(tag);
7085
+ (0, import_babel_utils30.assertNoAttributes)(tag);
6761
7086
  const tagVar = tag.node.var;
6762
7087
  let needsBinding = false;
6763
7088
  let needsGetter = false;
@@ -6787,8 +7112,8 @@ var html_comment_default = {
6787
7112
  }
6788
7113
  }
6789
7114
  if (needsBinding) {
6790
- const tagExtra = tag.node.extra ??= {};
6791
7115
  const tagSection = getOrCreateSection(tag);
7116
+ const tagExtra = mergeReferences(tagSection, tag.node, referenceNodes);
6792
7117
  const nodeBinding = tagExtra[kNodeBinding] = createBinding(
6793
7118
  "#comment",
6794
7119
  0 /* dom */,
@@ -6797,7 +7122,6 @@ var html_comment_default = {
6797
7122
  if (needsGetter) {
6798
7123
  tagExtra[kGetterId2] = getRegisterUID(tagSection, "comment");
6799
7124
  }
6800
- mergeReferences(tagSection, tag.node, referenceNodes);
6801
7125
  if (tagVar) {
6802
7126
  forceBindingSerialize(tagSection, nodeBinding);
6803
7127
  } else {
@@ -6828,7 +7152,7 @@ var html_comment_default = {
6828
7152
  let getterFnIdentifier;
6829
7153
  if (getterId) {
6830
7154
  getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
6831
- (0, import_babel_utils29.getProgram)().node.body.push(
7155
+ (0, import_babel_utils30.getProgram)().node.body.push(
6832
7156
  import_compiler37.types.variableDeclaration("const", [
6833
7157
  import_compiler37.types.variableDeclarator(
6834
7158
  getterFnIdentifier,
@@ -6915,9 +7239,12 @@ var html_comment_default = {
6915
7239
  }
6916
7240
  exit2(tag);
6917
7241
  write2`-->`;
6918
- const serializeMarkerReason = nodeBinding && getBindingSerializeReason(tagSection, nodeBinding);
6919
- if (serializeMarkerReason) {
6920
- markNode(tag, nodeBinding);
7242
+ if (nodeBinding) {
7243
+ markNode(
7244
+ tag,
7245
+ nodeBinding,
7246
+ getBindingSerializeReason(tagSection, nodeBinding)
7247
+ );
6921
7248
  }
6922
7249
  tag.remove();
6923
7250
  }
@@ -6936,13 +7263,13 @@ var html_comment_default = {
6936
7263
 
6937
7264
  // src/translator/core/html-script.ts
6938
7265
  var import_compiler38 = require("@marko/compiler");
6939
- var import_babel_utils30 = require("@marko/compiler/babel-utils");
7266
+ var import_babel_utils31 = require("@marko/compiler/babel-utils");
6940
7267
  var kNodeBinding2 = Symbol("script tag node binding");
6941
7268
  var kGetterId3 = Symbol("node getter id");
6942
7269
  var html_script_default = {
6943
7270
  analyze(tag) {
6944
- (0, import_babel_utils30.assertNoArgs)(tag);
6945
- (0, import_babel_utils30.assertNoParams)(tag);
7271
+ (0, import_babel_utils31.assertNoArgs)(tag);
7272
+ (0, import_babel_utils31.assertNoParams)(tag);
6946
7273
  const { node } = tag;
6947
7274
  if (node.var && !import_compiler38.types.isIdentifier(node.var)) {
6948
7275
  throw tag.get("var").buildCodeFrameError(
@@ -7004,7 +7331,7 @@ var html_script_default = {
7004
7331
  0 /* dom */,
7005
7332
  tagSection
7006
7333
  );
7007
- (0, import_babel_utils30.getProgram)().node.extra.isInteractive ||= hasEventHandlers;
7334
+ (0, import_babel_utils31.getProgram)().node.extra.isInteractive ||= hasEventHandlers;
7008
7335
  if (spreadReferenceNodes) {
7009
7336
  mergeReferences(tagSection, tag.node, spreadReferenceNodes);
7010
7337
  }
@@ -7064,7 +7391,7 @@ var html_script_default = {
7064
7391
  let getterFnIdentifier;
7065
7392
  if (getterId) {
7066
7393
  getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
7067
- (0, import_babel_utils30.getProgram)().node.body.push(
7394
+ (0, import_babel_utils31.getProgram)().node.body.push(
7068
7395
  import_compiler38.types.variableDeclaration("const", [
7069
7396
  import_compiler38.types.variableDeclarator(
7070
7397
  getterFnIdentifier,
@@ -7272,12 +7599,12 @@ var html_script_default = {
7272
7599
  }
7273
7600
  }
7274
7601
  write2`</script>`;
7275
- const serializeMarkerReason = getBindingSerializeReason(
7276
- tagSection,
7277
- nodeBinding
7278
- );
7279
- if (serializeMarkerReason) {
7280
- markNode(tag, nodeBinding);
7602
+ if (nodeBinding) {
7603
+ markNode(
7604
+ tag,
7605
+ nodeBinding,
7606
+ getBindingSerializeReason(tagSection, nodeBinding)
7607
+ );
7281
7608
  }
7282
7609
  exit2(tag);
7283
7610
  tag.remove();
@@ -7343,13 +7670,13 @@ function getUsedAttrs2(tag) {
7343
7670
 
7344
7671
  // src/translator/core/html-style.ts
7345
7672
  var import_compiler39 = require("@marko/compiler");
7346
- var import_babel_utils31 = require("@marko/compiler/babel-utils");
7673
+ var import_babel_utils32 = require("@marko/compiler/babel-utils");
7347
7674
  var kNodeBinding3 = Symbol("style tag node binding");
7348
7675
  var kGetterId4 = Symbol("node getter id");
7349
7676
  var html_style_default = {
7350
7677
  analyze(tag) {
7351
- (0, import_babel_utils31.assertNoArgs)(tag);
7352
- (0, import_babel_utils31.assertNoParams)(tag);
7678
+ (0, import_babel_utils32.assertNoArgs)(tag);
7679
+ (0, import_babel_utils32.assertNoParams)(tag);
7353
7680
  const { node } = tag;
7354
7681
  if (node.var && !import_compiler39.types.isIdentifier(node.var)) {
7355
7682
  throw tag.get("var").buildCodeFrameError(
@@ -7411,7 +7738,7 @@ var html_style_default = {
7411
7738
  0 /* dom */,
7412
7739
  tagSection
7413
7740
  );
7414
- (0, import_babel_utils31.getProgram)().node.extra.isInteractive ||= hasEventHandlers;
7741
+ (0, import_babel_utils32.getProgram)().node.extra.isInteractive ||= hasEventHandlers;
7415
7742
  if (spreadReferenceNodes) {
7416
7743
  mergeReferences(tagSection, tag.node, spreadReferenceNodes);
7417
7744
  }
@@ -7471,7 +7798,7 @@ var html_style_default = {
7471
7798
  let getterFnIdentifier;
7472
7799
  if (getterId) {
7473
7800
  getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
7474
- (0, import_babel_utils31.getProgram)().node.body.push(
7801
+ (0, import_babel_utils32.getProgram)().node.body.push(
7475
7802
  import_compiler39.types.variableDeclaration("const", [
7476
7803
  import_compiler39.types.variableDeclarator(
7477
7804
  getterFnIdentifier,
@@ -7679,12 +8006,12 @@ var html_style_default = {
7679
8006
  }
7680
8007
  }
7681
8008
  write2`</style>`;
7682
- const serializeMarkerReason = getBindingSerializeReason(
7683
- tagSection,
7684
- nodeBinding
7685
- );
7686
- if (serializeMarkerReason) {
7687
- markNode(tag, nodeBinding);
8009
+ if (nodeBinding) {
8010
+ markNode(
8011
+ tag,
8012
+ nodeBinding,
8013
+ getBindingSerializeReason(tagSection, nodeBinding)
8014
+ );
7688
8015
  }
7689
8016
  exit2(tag);
7690
8017
  tag.remove();
@@ -7745,14 +8072,14 @@ function getUsedAttrs3(tag) {
7745
8072
 
7746
8073
  // src/translator/core/id.ts
7747
8074
  var import_compiler40 = require("@marko/compiler");
7748
- var import_babel_utils32 = require("@marko/compiler/babel-utils");
8075
+ var import_babel_utils33 = require("@marko/compiler/babel-utils");
7749
8076
  var id_default = {
7750
8077
  analyze(tag) {
7751
- (0, import_babel_utils32.assertNoArgs)(tag);
7752
- (0, import_babel_utils32.assertNoParams)(tag);
7753
- (0, import_babel_utils32.assertNoAttributes)(tag);
8078
+ (0, import_babel_utils33.assertNoArgs)(tag);
8079
+ (0, import_babel_utils33.assertNoParams)(tag);
8080
+ (0, import_babel_utils33.assertNoAttributes)(tag);
7754
8081
  assertNoBodyContent(tag);
7755
- (0, import_babel_utils32.assertNoAttributeTags)(tag);
8082
+ (0, import_babel_utils33.assertNoAttributeTags)(tag);
7756
8083
  const { node } = tag;
7757
8084
  if (!node.var) {
7758
8085
  throw tag.get("name").buildCodeFrameError("The `id` tag requires a tag variable.");
@@ -7760,7 +8087,10 @@ var id_default = {
7760
8087
  if (!import_compiler40.types.isIdentifier(node.var)) {
7761
8088
  throw tag.get("var").buildCodeFrameError("The `id` tag cannot be destructured");
7762
8089
  }
7763
- trackVarReferences(tag, 4 /* derived */);
8090
+ const binding = trackVarReferences(tag, 4 /* derived */);
8091
+ if (binding) {
8092
+ setBindingValueExpr(binding, false);
8093
+ }
7764
8094
  },
7765
8095
  translate: {
7766
8096
  exit(tag) {
@@ -7794,7 +8124,7 @@ var id_default = {
7794
8124
 
7795
8125
  // src/translator/core/if.ts
7796
8126
  var import_compiler42 = require("@marko/compiler");
7797
- var import_babel_utils33 = require("@marko/compiler/babel-utils");
8127
+ var import_babel_utils34 = require("@marko/compiler/babel-utils");
7798
8128
 
7799
8129
  // src/translator/util/to-first-statement-or-block.ts
7800
8130
  var import_compiler41 = require("@marko/compiler");
@@ -7879,27 +8209,39 @@ var IfTag = {
7879
8209
  ifTagSection
7880
8210
  );
7881
8211
  const onlyChildInParentOptimization = isOnlyChildInParent(ifTag);
7882
- const branchSerializeReason = getPropSerializeReason(
7883
- ifTagSection,
7884
- ifTagExtra,
7885
- kBranchSerializeReason
7886
- );
7887
8212
  const markerSerializeReason = getBindingSerializeReason(
7888
8213
  ifTagSection,
7889
8214
  nodeBinding
7890
8215
  );
7891
8216
  const nextTag = tag.getNextSibling();
8217
+ let branchSerializeReasons;
7892
8218
  let statement;
7893
8219
  if (markerSerializeReason && onlyChildInParentOptimization) {
7894
8220
  getParentTag(ifTag).node.extra[kSkipMark] = true;
7895
8221
  }
7896
8222
  for (let i = branches.length; i--; ) {
7897
- const [branchTag] = branches[i];
8223
+ const [branchTag, branchBody] = branches[i];
7898
8224
  const bodyStatements = branchTag.node.body.body;
7899
- if (branchSerializeReason) {
7900
- bodyStatements.push(
7901
- import_compiler42.types.returnStatement(import_compiler42.types.numericLiteral(i))
7902
- );
8225
+ if (branchBody) {
8226
+ const branchSerializeReason = getSectionSerializeReason(branchBody);
8227
+ if (branchSerializeReason) {
8228
+ if (branchSerializeReasons !== true) {
8229
+ if (branchSerializeReason === true) {
8230
+ branchSerializeReasons = true;
8231
+ } else if (branchSerializeReasons) {
8232
+ branchSerializeReasons = addSorted(
8233
+ compareSerializeReasons,
8234
+ branchSerializeReasons,
8235
+ branchSerializeReason
8236
+ );
8237
+ } else {
8238
+ branchSerializeReasons = [branchSerializeReason];
8239
+ }
8240
+ }
8241
+ bodyStatements.push(
8242
+ import_compiler42.types.returnStatement(import_compiler42.types.numericLiteral(i))
8243
+ );
8244
+ }
7903
8245
  }
7904
8246
  const [testAttr] = branchTag.node.attributes;
7905
8247
  const curStatement = toFirstStatementOrBlock(bodyStatements);
@@ -7914,7 +8256,8 @@ var IfTag = {
7914
8256
  }
7915
8257
  branchTag.remove();
7916
8258
  }
7917
- if (branchSerializeReason) {
8259
+ if (branchSerializeReasons) {
8260
+ const branchSerializeExpr = branchSerializeReasons === true ? !onlyChildInParentOptimization && !markerSerializeReason ? void 0 : getSerializeGuard(branchSerializeReasons) : getSerializeGuardForAny(branchSerializeReasons);
7918
8261
  const cbNode = import_compiler42.types.arrowFunctionExpression(
7919
8262
  [],
7920
8263
  import_compiler42.types.blockStatement([statement])
@@ -7925,14 +8268,16 @@ var IfTag = {
7925
8268
  cbNode,
7926
8269
  getScopeIdIdentifier(ifTagSection),
7927
8270
  getScopeAccessorLiteral(nodeBinding),
7928
- markerSerializeReason ? import_compiler42.types.numericLiteral(1) : onlyChildInParentOptimization ? import_compiler42.types.numericLiteral(0) : void 0,
8271
+ branchSerializeExpr,
8272
+ markerSerializeReason ? getSerializeGuard(markerSerializeReason) : onlyChildInParentOptimization ? import_compiler42.types.numericLiteral(0) : void 0,
7929
8273
  onlyChildInParentOptimization && import_compiler42.types.numericLiteral(1)
7930
8274
  ) : callRuntime(
7931
8275
  "resumeConditional",
7932
8276
  cbNode,
7933
8277
  getScopeIdIdentifier(ifTagSection),
7934
8278
  getScopeAccessorLiteral(nodeBinding),
7935
- markerSerializeReason ? import_compiler42.types.numericLiteral(1) : void 0
8279
+ branchSerializeExpr,
8280
+ getSerializeGuard(markerSerializeReason)
7936
8281
  )
7937
8282
  );
7938
8283
  }
@@ -8024,9 +8369,9 @@ var ElseTag = {
8024
8369
  ]
8025
8370
  };
8026
8371
  function assertValidCondition(tag) {
8027
- (0, import_babel_utils33.assertNoVar)(tag);
8028
- (0, import_babel_utils33.assertNoArgs)(tag);
8029
- (0, import_babel_utils33.assertNoParams)(tag);
8372
+ (0, import_babel_utils34.assertNoVar)(tag);
8373
+ (0, import_babel_utils34.assertNoArgs)(tag);
8374
+ (0, import_babel_utils34.assertNoParams)(tag);
8030
8375
  assertHasBody(tag);
8031
8376
  assertNoSpreadAttrs(tag);
8032
8377
  switch (getTagName(tag)) {
@@ -8114,6 +8459,13 @@ function getBranches(tag) {
8114
8459
  }
8115
8460
  return branches;
8116
8461
  }
8462
+ function getSerializeGuardForAny(reasons) {
8463
+ let expr = getSerializeGuard(reasons[0]);
8464
+ for (let i = 1; i < reasons.length; i++) {
8465
+ expr = import_compiler42.types.logicalExpression("||", expr, getSerializeGuard(reasons[i]));
8466
+ }
8467
+ return expr;
8468
+ }
8117
8469
  function isLastBranch(tag) {
8118
8470
  const branches = getBranches(tag);
8119
8471
  return branches[branches.length - 1][0] === tag;
@@ -8123,12 +8475,12 @@ function isRoot(tag) {
8123
8475
  }
8124
8476
 
8125
8477
  // src/translator/core/import.ts
8126
- var import_babel_utils34 = require("@marko/compiler/babel-utils");
8478
+ var import_babel_utils35 = require("@marko/compiler/babel-utils");
8127
8479
  var import_default = {
8128
8480
  parse(tag) {
8129
8481
  const { node } = tag;
8130
8482
  tag.replaceWith(
8131
- (0, import_babel_utils34.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end)[0]
8483
+ (0, import_babel_utils35.parseStatements)(tag.hub.file, node.rawValue, node.start, node.end)[0]
8132
8484
  );
8133
8485
  },
8134
8486
  parseOptions: {
@@ -8147,7 +8499,7 @@ var import_default = {
8147
8499
 
8148
8500
  // src/translator/core/let.ts
8149
8501
  var import_compiler43 = require("@marko/compiler");
8150
- var import_babel_utils35 = require("@marko/compiler/babel-utils");
8502
+ var import_babel_utils36 = require("@marko/compiler/babel-utils");
8151
8503
  var let_default = {
8152
8504
  analyze(tag) {
8153
8505
  const { node } = tag;
@@ -8176,8 +8528,8 @@ var let_default = {
8176
8528
  }
8177
8529
  }
8178
8530
  }
8179
- (0, import_babel_utils35.assertNoArgs)(tag);
8180
- (0, import_babel_utils35.assertNoParams)(tag);
8531
+ (0, import_babel_utils36.assertNoArgs)(tag);
8532
+ (0, import_babel_utils36.assertNoParams)(tag);
8181
8533
  assertNoBodyContent(tag);
8182
8534
  assertNoSpreadAttrs(tag);
8183
8535
  if (!tagVar) {
@@ -8186,16 +8538,26 @@ var let_default = {
8186
8538
  if (!import_compiler43.types.isIdentifier(tagVar)) {
8187
8539
  throw tag.get("var").buildCodeFrameError("The `let` tag variable cannot be destructured.");
8188
8540
  }
8189
- if (valueChangeAttr && (0, import_babel_utils35.computeNode)(valueChangeAttr.value)) {
8541
+ if (valueChangeAttr && (0, import_babel_utils36.computeNode)(valueChangeAttr.value)) {
8190
8542
  throw tag.get("attributes").find((attr2) => attr2.node === valueChangeAttr).get("value").buildCodeFrameError(
8191
8543
  "The `let` tag `valueChange` attribute must be a function."
8192
8544
  );
8193
8545
  }
8194
- mergeReferences(getOrCreateSection(tag), tag.node, [
8195
- valueAttr?.value,
8196
- valueChangeAttr?.value
8197
- ]);
8198
- trackVarReferences(tag, 1 /* let */, void 0, tag.node.extra);
8546
+ const binding = trackVarReferences(tag, 1 /* let */);
8547
+ setBindingValueExpr(
8548
+ binding,
8549
+ mergeReferences(getOrCreateSection(tag), tag.node, [
8550
+ valueAttr?.value,
8551
+ valueChangeAttr?.value
8552
+ ])
8553
+ );
8554
+ if (valueChangeAttr) {
8555
+ forceBindingSerialize(
8556
+ getSection(tag),
8557
+ binding,
8558
+ getAccessorPrefix().TagVariableChange
8559
+ );
8560
+ }
8199
8561
  },
8200
8562
  translate: {
8201
8563
  exit(tag) {
@@ -8223,10 +8585,11 @@ var let_default = {
8223
8585
  } else {
8224
8586
  translateVar(tag, valueAttr.value, "let");
8225
8587
  if (valueChangeAttr) {
8226
- setSerializedValue(
8588
+ setBindingSerializedValue(
8227
8589
  section,
8228
- getAccessorPrefix().TagVariableChange + getScopeAccessor(binding),
8229
- valueChangeAttr.value
8590
+ binding,
8591
+ valueChangeAttr.value,
8592
+ getAccessorPrefix().TagVariableChange
8230
8593
  );
8231
8594
  }
8232
8595
  }
@@ -8248,23 +8611,25 @@ var let_default = {
8248
8611
 
8249
8612
  // src/translator/core/lifecycle.ts
8250
8613
  var import_compiler44 = require("@marko/compiler");
8251
- var import_babel_utils36 = require("@marko/compiler/babel-utils");
8614
+ var import_babel_utils37 = require("@marko/compiler/babel-utils");
8252
8615
  var kRef = Symbol("lifecycle attrs reference");
8253
8616
  var lifecycle_default = {
8254
8617
  analyze(tag) {
8255
- (0, import_babel_utils36.assertNoArgs)(tag);
8256
- (0, import_babel_utils36.assertNoVar)(tag);
8257
- (0, import_babel_utils36.assertNoParams)(tag);
8618
+ (0, import_babel_utils37.assertNoArgs)(tag);
8619
+ (0, import_babel_utils37.assertNoVar)(tag);
8620
+ (0, import_babel_utils37.assertNoParams)(tag);
8258
8621
  assertNoBodyContent(tag);
8259
8622
  const { node } = tag;
8260
- const tagExtra = node.extra ??= {};
8261
8623
  const section = getOrCreateSection(tag);
8624
+ const tagExtra = mergeReferences(
8625
+ section,
8626
+ tag.node,
8627
+ getAllTagReferenceNodes(tag.node)
8628
+ );
8262
8629
  tagExtra[kRef] = createBinding(
8263
8630
  generateUid("lifecycle"),
8264
8631
  4 /* derived */,
8265
- section,
8266
- void 0,
8267
- tagExtra
8632
+ section
8268
8633
  );
8269
8634
  if (node.attributes.length === 0) {
8270
8635
  throw tag.get("name").buildCodeFrameError(
@@ -8279,8 +8644,7 @@ var lifecycle_default = {
8279
8644
  }
8280
8645
  (attr2.value.extra ??= {}).isEffect = true;
8281
8646
  }
8282
- ((0, import_babel_utils36.getProgram)().node.extra ??= {}).isInteractive = true;
8283
- mergeReferences(section, tag.node, getAllTagReferenceNodes(tag.node));
8647
+ ((0, import_babel_utils37.getProgram)().node.extra ??= {}).isInteractive = true;
8284
8648
  },
8285
8649
  translate: {
8286
8650
  exit(tag) {
@@ -8328,13 +8692,13 @@ var lifecycle_default = {
8328
8692
 
8329
8693
  // src/translator/core/log.ts
8330
8694
  var import_compiler45 = require("@marko/compiler");
8331
- var import_babel_utils37 = require("@marko/compiler/babel-utils");
8695
+ var import_babel_utils38 = require("@marko/compiler/babel-utils");
8332
8696
  var log_default = {
8333
8697
  analyze(tag) {
8334
8698
  const [valueAttr] = tag.node.attributes;
8335
- (0, import_babel_utils37.assertNoArgs)(tag);
8336
- (0, import_babel_utils37.assertNoVar)(tag);
8337
- (0, import_babel_utils37.assertNoParams)(tag);
8699
+ (0, import_babel_utils38.assertNoArgs)(tag);
8700
+ (0, import_babel_utils38.assertNoVar)(tag);
8701
+ (0, import_babel_utils38.assertNoParams)(tag);
8338
8702
  assertNoBodyContent(tag);
8339
8703
  if (!valueAttr) {
8340
8704
  throw tag.get("name").buildCodeFrameError("The `log` tag requires a value.");
@@ -8380,7 +8744,7 @@ var log_default = {
8380
8744
 
8381
8745
  // src/translator/core/script.ts
8382
8746
  var import_compiler46 = require("@marko/compiler");
8383
- var import_babel_utils38 = require("@marko/compiler/babel-utils");
8747
+ var import_babel_utils39 = require("@marko/compiler/babel-utils");
8384
8748
  var htmlScriptTagAlternateMsg = " For a native html `script` tag use the `html-script` core tag instead.";
8385
8749
  var script_default = {
8386
8750
  parse(tag) {
@@ -8400,7 +8764,7 @@ var script_default = {
8400
8764
  }
8401
8765
  const start = body[0]?.start;
8402
8766
  const end = body[body.length - 1]?.end;
8403
- const bodyStatements = (0, import_babel_utils38.parseStatements)(tag.hub.file, code, start, end);
8767
+ const bodyStatements = (0, import_babel_utils39.parseStatements)(tag.hub.file, code, start, end);
8404
8768
  const valueFn = import_compiler46.types.arrowFunctionExpression(
8405
8769
  [],
8406
8770
  import_compiler46.types.blockStatement(bodyStatements),
@@ -8412,10 +8776,10 @@ var script_default = {
8412
8776
  },
8413
8777
  analyze(tag) {
8414
8778
  const { node } = tag;
8415
- (0, import_babel_utils38.assertNoArgs)(tag);
8416
- (0, import_babel_utils38.assertNoParams)(tag);
8779
+ (0, import_babel_utils39.assertNoArgs)(tag);
8780
+ (0, import_babel_utils39.assertNoParams)(tag);
8417
8781
  assertNoBodyContent(tag);
8418
- (0, import_babel_utils38.assertNoAttributeTags)(tag);
8782
+ (0, import_babel_utils39.assertNoAttributeTags)(tag);
8419
8783
  if (node.var) {
8420
8784
  throw tag.hub.buildError(
8421
8785
  node.var,
@@ -8430,7 +8794,7 @@ var script_default = {
8430
8794
  }
8431
8795
  seenValueAttr = true;
8432
8796
  (attr2.value.extra ??= {}).isEffect = true;
8433
- ((0, import_babel_utils38.getProgram)().node.extra ??= {}).isInteractive = true;
8797
+ ((0, import_babel_utils39.getProgram)().node.extra ??= {}).isInteractive = true;
8434
8798
  } else {
8435
8799
  throw tag.hub.buildError(
8436
8800
  attr2,
@@ -8519,7 +8883,7 @@ function isAwaitExpression(node) {
8519
8883
 
8520
8884
  // src/translator/core/server.ts
8521
8885
  var import_compiler47 = require("@marko/compiler");
8522
- var import_babel_utils39 = require("@marko/compiler/babel-utils");
8886
+ var import_babel_utils40 = require("@marko/compiler/babel-utils");
8523
8887
  var server_default = {
8524
8888
  parse(tag) {
8525
8889
  const {
@@ -8529,7 +8893,7 @@ var server_default = {
8529
8893
  const rawValue = node.rawValue;
8530
8894
  const code = rawValue.replace(/^server\s*/, "").trim();
8531
8895
  const start = node.name.start + (rawValue.length - code.length);
8532
- let body = (0, import_babel_utils39.parseStatements)(file, code, start, start + code.length);
8896
+ let body = (0, import_babel_utils40.parseStatements)(file, code, start, start + code.length);
8533
8897
  if (body.length === 1 && import_compiler47.types.isBlockStatement(body[0])) {
8534
8898
  body = body[0].body;
8535
8899
  }
@@ -8550,7 +8914,7 @@ var server_default = {
8550
8914
 
8551
8915
  // src/translator/core/static.ts
8552
8916
  var import_compiler48 = require("@marko/compiler");
8553
- var import_babel_utils40 = require("@marko/compiler/babel-utils");
8917
+ var import_babel_utils41 = require("@marko/compiler/babel-utils");
8554
8918
  var static_default = {
8555
8919
  parse(tag) {
8556
8920
  const {
@@ -8560,7 +8924,7 @@ var static_default = {
8560
8924
  const rawValue = node.rawValue;
8561
8925
  const code = rawValue.replace(/^static\s*/, "").trim();
8562
8926
  const start = node.name.start + (rawValue.length - code.length);
8563
- let body = (0, import_babel_utils40.parseStatements)(file, code, start, start + code.length);
8927
+ let body = (0, import_babel_utils41.parseStatements)(file, code, start, start + code.length);
8564
8928
  if (body.length === 1 && import_compiler48.types.isBlockStatement(body[0])) {
8565
8929
  body = body[0].body;
8566
8930
  }
@@ -8581,16 +8945,16 @@ var static_default = {
8581
8945
 
8582
8946
  // src/translator/core/style.ts
8583
8947
  var import_compiler49 = require("@marko/compiler");
8584
- var import_babel_utils41 = require("@marko/compiler/babel-utils");
8948
+ var import_babel_utils42 = require("@marko/compiler/babel-utils");
8585
8949
  var import_magic_string = __toESM(require("magic-string"));
8586
8950
  var import_path3 = __toESM(require("path"));
8587
8951
  var STYLE_EXT_REG = /^style((?:\.[a-zA-Z0-9$_-]+)+)?/;
8588
8952
  var htmlStyleTagAlternateMsg = " For a native html `style` tag use the `html-style` core tag instead.";
8589
8953
  var style_default = {
8590
8954
  analyze(tag) {
8591
- (0, import_babel_utils41.assertNoArgs)(tag);
8592
- (0, import_babel_utils41.assertNoParams)(tag);
8593
- (0, import_babel_utils41.assertNoAttributeTags)(tag);
8955
+ (0, import_babel_utils42.assertNoArgs)(tag);
8956
+ (0, import_babel_utils42.assertNoParams)(tag);
8957
+ (0, import_babel_utils42.assertNoAttributeTags)(tag);
8594
8958
  const { node } = tag;
8595
8959
  const ext = STYLE_EXT_REG.exec(node.rawValue || "")?.[1]?.slice(1);
8596
8960
  for (const attr2 of node.attributes) {
@@ -8629,49 +8993,49 @@ var style_default = {
8629
8993
  }
8630
8994
  const markoText = node.body.body[0];
8631
8995
  const { resolveVirtualDependency } = getMarkoOpts();
8632
- const start = (0, import_babel_utils41.getStart)(file, markoText);
8633
- const end = (0, import_babel_utils41.getEnd)(file, markoText);
8996
+ const start = (0, import_babel_utils42.getStart)(file, markoText);
8997
+ const end = (0, import_babel_utils42.getEnd)(file, markoText);
8634
8998
  let code = markoText.value;
8635
- let map2;
8999
+ let map;
8636
9000
  if (resolveVirtualDependency && sourceMaps && start !== null && end !== null) {
8637
9001
  const magicString = new import_magic_string.default(file.code, { filename });
8638
9002
  magicString.remove(0, start);
8639
9003
  magicString.remove(end, file.code.length);
8640
- map2 = magicString.generateMap({
9004
+ map = magicString.generateMap({
8641
9005
  source: filename,
8642
9006
  includeContent: true
8643
9007
  });
8644
9008
  if (sourceMaps === "inline" || sourceMaps === "both") {
8645
9009
  code += `
8646
- /*# sourceMappingURL=${map2.toUrl()}*/`;
9010
+ /*# sourceMappingURL=${map.toUrl()}*/`;
8647
9011
  if (sourceMaps === "inline") {
8648
- map2 = void 0;
9012
+ map = void 0;
8649
9013
  }
8650
9014
  }
8651
9015
  }
8652
9016
  const importPath = resolveVirtualDependency?.(filename, {
8653
9017
  virtualPath: `./${import_path3.default.basename(filename) + ext}`,
8654
9018
  code,
8655
- map: map2
9019
+ map
8656
9020
  });
8657
9021
  if (importPath) {
8658
9022
  if (!node.var) {
8659
- (0, import_babel_utils41.getProgram)().node.body.push(
9023
+ (0, import_babel_utils42.getProgram)().node.body.push(
8660
9024
  import_compiler49.types.importDeclaration([], import_compiler49.types.stringLiteral(importPath))
8661
9025
  );
8662
9026
  } else if (import_compiler49.types.isIdentifier(node.var)) {
8663
- (0, import_babel_utils41.getProgram)().node.body.push(
9027
+ (0, import_babel_utils42.getProgram)().node.body.push(
8664
9028
  import_compiler49.types.importDeclaration(
8665
9029
  [import_compiler49.types.importDefaultSpecifier(node.var)],
8666
9030
  import_compiler49.types.stringLiteral(importPath)
8667
9031
  )
8668
9032
  );
8669
9033
  } else {
8670
- (0, import_babel_utils41.getProgram)().node.body.push(
9034
+ (0, import_babel_utils42.getProgram)().node.body.push(
8671
9035
  import_compiler49.types.variableDeclaration("const", [
8672
9036
  import_compiler49.types.variableDeclarator(
8673
9037
  node.var,
8674
- (0, import_babel_utils41.importDefault)(file, importPath, "style")
9038
+ (0, import_babel_utils42.importDefault)(file, importPath, "style")
8675
9039
  )
8676
9040
  ])
8677
9041
  );
@@ -8690,32 +9054,27 @@ var style_default = {
8690
9054
 
8691
9055
  // src/translator/core/try.ts
8692
9056
  var import_compiler50 = require("@marko/compiler");
8693
- var import_babel_utils42 = require("@marko/compiler/babel-utils");
9057
+ var import_babel_utils43 = require("@marko/compiler/babel-utils");
8694
9058
  var kDOMBinding2 = Symbol("try tag dom binding");
8695
9059
  var try_default = {
8696
9060
  analyze(tag) {
8697
- (0, import_babel_utils42.assertNoVar)(tag);
8698
- (0, import_babel_utils42.assertNoArgs)(tag);
8699
- (0, import_babel_utils42.assertNoParams)(tag);
8700
- (0, import_babel_utils42.assertNoAttributes)(tag);
9061
+ (0, import_babel_utils43.assertNoVar)(tag);
9062
+ (0, import_babel_utils43.assertNoArgs)(tag);
9063
+ (0, import_babel_utils43.assertNoParams)(tag);
9064
+ (0, import_babel_utils43.assertNoAttributes)(tag);
8701
9065
  assertNoSpreadAttrs(tag);
8702
9066
  analyzeAttributeTags(tag);
8703
- const { node } = tag;
8704
9067
  const section = getOrCreateSection(tag);
8705
- const tagExtra = tag.node.extra ??= {};
8706
- const tagBody = tag.get("body");
8707
- tagExtra[kDOMBinding2] = createBinding(
8708
- "#text",
8709
- 0 /* dom */,
9068
+ const tagExtra = mergeReferences(
8710
9069
  section,
8711
- void 0,
8712
- tagExtra
9070
+ tag.node,
9071
+ getAllTagReferenceNodes(tag.node)
8713
9072
  );
8714
- if (!node.body.body.length) {
9073
+ tagExtra[kDOMBinding2] = createBinding("#text", 0 /* dom */, section);
9074
+ if (!tag.node.body.body.length) {
8715
9075
  throw tag.get("name").buildCodeFrameError("The `try` tag requires body content.");
8716
9076
  }
8717
- startSection(tagBody);
8718
- mergeReferences(section, tag.node, getAllTagReferenceNodes(tag.node));
9077
+ startSection(tag.get("body"));
8719
9078
  },
8720
9079
  translate: translateByTarget({
8721
9080
  html: {
@@ -8802,7 +9161,7 @@ var try_default = {
8802
9161
  translatedAttrs.statements
8803
9162
  );
8804
9163
  }
8805
- (0, import_babel_utils42.getProgram)().node.body.push(
9164
+ (0, import_babel_utils43.getProgram)().node.body.push(
8806
9165
  import_compiler50.types.expressionStatement(callRuntime("enableCatch"))
8807
9166
  );
8808
9167
  addValue(
@@ -8902,7 +9261,7 @@ var document_type_default = {
8902
9261
 
8903
9262
  // src/translator/visitors/function.ts
8904
9263
  var import_compiler51 = require("@marko/compiler");
8905
- var import_babel_utils43 = require("@marko/compiler/babel-utils");
9264
+ var import_babel_utils44 = require("@marko/compiler/babel-utils");
8906
9265
  var function_default = {
8907
9266
  analyze(fn) {
8908
9267
  if (fn !== getFnRoot(fn)) {
@@ -8912,7 +9271,7 @@ var function_default = {
8912
9271
  if (markoRoot && (markoRoot.isMarkoPlaceholder() || markoRoot.isMarkoScriptlet() && markoRoot.node.target === "server")) {
8913
9272
  return;
8914
9273
  }
8915
- if (isMarkoAttribute(markoRoot) && ((0, import_babel_utils43.isNativeTag)(markoRoot.parentPath) && /^on[A-Z-]/.test(markoRoot.node.name) || isCoreTagName(markoRoot.parentPath, "script") || isCoreTagName(markoRoot.parentPath, "lifecycle") || isCoreTagName(markoRoot.parentPath, "for"))) {
9274
+ if (isMarkoAttribute(markoRoot) && ((0, import_babel_utils44.isNativeTag)(markoRoot.parentPath) && /^on[A-Z-]/.test(markoRoot.node.name) || isCoreTagName(markoRoot.parentPath, "script") || isCoreTagName(markoRoot.parentPath, "lifecycle") || isCoreTagName(markoRoot.parentPath, "for"))) {
8916
9275
  return;
8917
9276
  }
8918
9277
  const { node } = fn;
@@ -8921,14 +9280,14 @@ var function_default = {
8921
9280
  const {
8922
9281
  markoOpts,
8923
9282
  opts: { filename }
8924
- } = (0, import_babel_utils43.getFile)();
9283
+ } = (0, import_babel_utils44.getFile)();
8925
9284
  const name2 = extra.name = generateUid(
8926
9285
  fn.node.id?.name || (isMarkoAttribute(markoRoot) ? markoRoot.node.default ? import_compiler51.types.toIdentifier(
8927
9286
  markoRoot.parentPath.has("var") ? markoRoot.parentPath.get("var") : markoRoot.parentPath.get("name")
8928
9287
  ) : markoRoot.node.name : import_compiler51.types.isVariableDeclarator(fn.parent) && import_compiler51.types.isIdentifier(fn.parent.id) ? fn.parent.id.name : import_compiler51.types.isObjectMethod(node) && import_compiler51.types.isIdentifier(node.key) ? node.key.name : "anonymous")
8929
9288
  );
8930
9289
  extra.section = section;
8931
- extra.registerId = (0, import_babel_utils43.getTemplateId)(
9290
+ extra.registerId = (0, import_babel_utils44.getTemplateId)(
8932
9291
  markoOpts,
8933
9292
  filename,
8934
9293
  `${section.id}/${name2.slice(1)}`
@@ -8940,13 +9299,13 @@ function isMarkoAttribute(path5) {
8940
9299
  }
8941
9300
 
8942
9301
  // src/translator/visitors/import-declaration.ts
8943
- var import_babel_utils44 = require("@marko/compiler/babel-utils");
9302
+ var import_babel_utils45 = require("@marko/compiler/babel-utils");
8944
9303
  var import_declaration_default = {
8945
9304
  analyze(importDecl) {
8946
9305
  const { node } = importDecl;
8947
9306
  const { source } = node;
8948
9307
  const { value } = source;
8949
- const tagImport = (0, import_babel_utils44.resolveTagImport)(importDecl, value);
9308
+ const tagImport = (0, import_babel_utils45.resolveTagImport)(importDecl, value);
8950
9309
  if (tagImport) {
8951
9310
  node.extra ??= {};
8952
9311
  node.extra.tagImport = tagImport;
@@ -8987,7 +9346,7 @@ function isNonHTMLText(placeholder) {
8987
9346
  }
8988
9347
 
8989
9348
  // src/translator/visitors/placeholder.ts
8990
- var kBinding = Symbol("placeholder node binding");
9349
+ var kNodeBinding4 = Symbol("placeholder node binding");
8991
9350
  var kSiblingText = Symbol("placeholder has sibling text");
8992
9351
  var placeholder_default = {
8993
9352
  analyze(placeholder) {
@@ -8997,15 +9356,13 @@ var placeholder_default = {
8997
9356
  const { confident, computed } = valueExtra;
8998
9357
  if (!(confident && (node.escape || isVoid2(computed)))) {
8999
9358
  const section = getOrCreateSection(placeholder);
9000
- const binding = (node.extra ??= {})[kBinding] = createBinding(
9359
+ const nodeBinding = (node.extra ??= {})[kNodeBinding4] = createBinding(
9001
9360
  "#text",
9002
9361
  0 /* dom */,
9003
- section,
9004
- void 0,
9005
- valueExtra
9362
+ section
9006
9363
  );
9007
9364
  analyzeSiblingText(placeholder);
9008
- addBindingSerializeReasonExpr(section, binding, valueExtra);
9365
+ addBindingSerializeReasonExpr(section, nodeBinding, valueExtra);
9009
9366
  }
9010
9367
  },
9011
9368
  translate: {
@@ -9022,7 +9379,7 @@ var placeholder_default = {
9022
9379
  const isHTML = isOutputHTML();
9023
9380
  const write2 = writeTo(placeholder);
9024
9381
  const extra = node.extra || {};
9025
- const nodeBinding = extra[kBinding];
9382
+ const nodeBinding = extra[kNodeBinding4];
9026
9383
  const canWriteHTML = isHTML || confident && node.escape;
9027
9384
  const method = canWriteHTML ? node.escape ? "escapeXML" : "toString" : node.escape ? "data" : "html";
9028
9385
  const section = getSection(placeholder);
@@ -9033,7 +9390,11 @@ var placeholder_default = {
9033
9390
  } else {
9034
9391
  if (siblingText === 1 /* Before */) {
9035
9392
  if (isHTML && markerSerializeReason) {
9036
- write2`<!>`;
9393
+ if (markerSerializeReason === true) {
9394
+ write2`<!>`;
9395
+ } else {
9396
+ write2`${callRuntime("commentSeparator", getSerializeGuard(markerSerializeReason))}`;
9397
+ }
9037
9398
  }
9038
9399
  visit(placeholder, 37 /* Replace */);
9039
9400
  } else if (siblingText === 2 /* After */) {
@@ -9044,8 +9405,8 @@ var placeholder_default = {
9044
9405
  }
9045
9406
  if (isHTML) {
9046
9407
  write2`${callRuntime(method, value)}`;
9047
- if (markerSerializeReason) {
9048
- markNode(placeholder, nodeBinding);
9408
+ if (nodeBinding) {
9409
+ markNode(placeholder, nodeBinding, markerSerializeReason);
9049
9410
  }
9050
9411
  } else {
9051
9412
  addStatement(
@@ -9242,7 +9603,7 @@ var scriptlet_default = {
9242
9603
  }
9243
9604
  if (isHTML) {
9244
9605
  } else {
9245
- traverseReplace(node, "body", replaceRegisteredFunctionNode);
9606
+ traverseReplace(node, "body", replaceRegisteredFunctionNode2);
9246
9607
  scriptlet.replaceWithMultiple(node.body);
9247
9608
  }
9248
9609
  }
@@ -9251,20 +9612,20 @@ var scriptlet_default = {
9251
9612
 
9252
9613
  // src/translator/visitors/tag/index.ts
9253
9614
  var import_compiler58 = require("@marko/compiler");
9254
- var import_babel_utils48 = require("@marko/compiler/babel-utils");
9615
+ var import_babel_utils49 = require("@marko/compiler/babel-utils");
9255
9616
 
9256
9617
  // src/translator/visitors/tag/attribute-tag.ts
9257
9618
  var import_compiler55 = require("@marko/compiler");
9258
- var import_babel_utils45 = require("@marko/compiler/babel-utils");
9619
+ var import_babel_utils46 = require("@marko/compiler/babel-utils");
9259
9620
  var attribute_tag_default = {
9260
9621
  analyze: {
9261
9622
  enter(tag) {
9262
- (0, import_babel_utils45.assertNoVar)(tag);
9263
- (0, import_babel_utils45.assertNoArgs)(tag);
9623
+ (0, import_babel_utils46.assertNoVar)(tag);
9624
+ (0, import_babel_utils46.assertNoArgs)(tag);
9264
9625
  const body = tag.get("body");
9265
9626
  startSection(body);
9266
9627
  trackParamsReferences(body, 3 /* param */);
9267
- if (!(0, import_babel_utils45.findParentTag)(tag)) {
9628
+ if (!(0, import_babel_utils46.findParentTag)(tag)) {
9268
9629
  throw tag.get("name").buildCodeFrameError("@tags must be nested within another tag.");
9269
9630
  }
9270
9631
  }
@@ -9286,16 +9647,19 @@ var attribute_tag_default = {
9286
9647
 
9287
9648
  // src/translator/visitors/tag/custom-tag.ts
9288
9649
  var import_compiler56 = require("@marko/compiler");
9289
- var import_babel_utils46 = require("@marko/compiler/babel-utils");
9650
+ var import_babel_utils47 = require("@marko/compiler/babel-utils");
9290
9651
  var import_path4 = __toESM(require("path"));
9291
9652
  var kChildScopeBinding = Symbol("custom tag child scope");
9292
9653
  var kChildOffsetScopeBinding = Symbol("custom tag scope offset");
9654
+ var kChildInputSerializePropIds = Symbol(
9655
+ "custom tag child serialize reasons"
9656
+ );
9293
9657
  var custom_tag_default = {
9294
9658
  analyze: {
9295
9659
  enter(tag) {
9296
- (0, import_babel_utils46.assertAttributesOrSingleArg)(tag);
9660
+ (0, import_babel_utils47.assertAttributesOrSingleArg)(tag);
9297
9661
  analyzeAttributeTags(tag);
9298
- const templateFile = (0, import_babel_utils46.getTagTemplate)(tag);
9662
+ const templateFile = (0, import_babel_utils47.getTagTemplate)(tag);
9299
9663
  if (!templateFile) {
9300
9664
  const tagName = getTagName(tag);
9301
9665
  if (tagName && tag.scope.hasBinding(tagName)) {
@@ -9311,42 +9675,75 @@ var custom_tag_default = {
9311
9675
  const childScopeBinding = tagExtra[kChildScopeBinding] = createBinding(
9312
9676
  "#childScope",
9313
9677
  0 /* dom */,
9314
- section,
9315
- void 0,
9316
- tagExtra
9678
+ section
9317
9679
  );
9318
9680
  const attrExprs = /* @__PURE__ */ new Set([tagExtra]);
9319
- const hasVar = !!tag.node.var;
9320
- if (hasVar) {
9321
- trackVarReferences(tag, 4 /* derived */);
9322
- tag.node.var.extra.binding.scopeOffset = tagExtra[kChildOffsetScopeBinding] = createBinding(
9323
- "#scopeOffset",
9324
- 0 /* dom */,
9325
- section,
9326
- void 0,
9327
- tagExtra
9328
- );
9329
- }
9330
9681
  startSection(tagBody);
9331
9682
  trackParamsReferences(tagBody, 3 /* param */);
9332
- const childFile = (0, import_babel_utils46.loadFileForTag)(tag);
9683
+ const childFile = (0, import_babel_utils47.loadFileForTag)(tag);
9684
+ if (!childFile) {
9685
+ throw tag.get("name").buildCodeFrameError("Unable to resolve file for tag.");
9686
+ }
9687
+ const varBinding = trackVarReferences(tag, 4 /* derived */);
9688
+ if (varBinding) {
9689
+ varBinding.scopeOffset = tagExtra[kChildOffsetScopeBinding] = createBinding("#scopeOffset", 0 /* dom */, section);
9690
+ }
9333
9691
  if (childFile.opts.filename === tag.hub.file.opts.filename) {
9334
9692
  mergeReferences(section, tag.node, getAllTagReferenceNodes(tag.node));
9693
+ if (varBinding) {
9694
+ const varSerializeReason = (0, import_babel_utils47.getProgram)().node.extra.returnValueExpr;
9695
+ setBindingValueExpr(varBinding, varSerializeReason);
9696
+ addBindingSerializeReasonExpr(
9697
+ section,
9698
+ childScopeBinding,
9699
+ varSerializeReason
9700
+ );
9701
+ }
9335
9702
  } else {
9336
- const childProgramExtra = childFile.ast.program.extra;
9703
+ const childProgram = childFile.ast.program;
9704
+ const childExtra = childProgram.extra;
9705
+ const childInputBinding = childProgram.params[0].extra?.binding;
9706
+ const inputExpr = {};
9337
9707
  analyzeAttrs(
9338
9708
  tagExtra,
9339
9709
  section,
9340
9710
  tag,
9341
- childProgramExtra?.domExports.input,
9342
- attrExprs
9711
+ childExtra?.domExports.input,
9712
+ attrExprs,
9713
+ inputExpr
9343
9714
  );
9344
- (0, import_babel_utils46.getProgram)().node.extra.hasInteractiveChild = childProgramExtra?.isInteractive || childProgramExtra?.hasInteractiveChild || false;
9715
+ if (varBinding) {
9716
+ const varSerializeReason = mapChildReasonToLocalReason(
9717
+ childExtra.returnSerializeReason,
9718
+ childInputBinding,
9719
+ inputExpr
9720
+ );
9721
+ setBindingValueExpr(varBinding, varSerializeReason);
9722
+ addBindingSerializeReasonExpr(
9723
+ section,
9724
+ childScopeBinding,
9725
+ varSerializeReason
9726
+ );
9727
+ }
9728
+ if (childExtra.inputSerializeReasons) {
9729
+ const childInputSerializePropIds = tagExtra[kChildInputSerializePropIds] = [];
9730
+ for (const reason of childExtra.inputSerializeReasons) {
9731
+ const propId = Symbol();
9732
+ childInputSerializePropIds.push(propId);
9733
+ addBindingSerializeReasonExpr(
9734
+ section,
9735
+ childScopeBinding,
9736
+ mapChildReasonToLocalReason(reason, childInputBinding, inputExpr),
9737
+ propId
9738
+ );
9739
+ }
9740
+ }
9741
+ (0, import_babel_utils47.getProgram)().node.extra.hasInteractiveChild = childExtra?.isInteractive || childExtra?.hasInteractiveChild || false;
9345
9742
  }
9346
9743
  addBindingSerializeReasonExpr(
9347
9744
  section,
9348
9745
  childScopeBinding,
9349
- hasVar || fromIter(attrExprs)
9746
+ fromIter(attrExprs)
9350
9747
  );
9351
9748
  }
9352
9749
  },
@@ -9375,13 +9772,15 @@ function translateHTML(tag) {
9375
9772
  writeHTMLResumeStatements(tagBody);
9376
9773
  if (import_compiler56.types.isStringLiteral(node.name)) {
9377
9774
  const relativePath = getTagRelativePath(tag);
9378
- tagIdentifier = isCircularRequest(tag.hub.file, relativePath) ? import_compiler56.types.identifier(getTemplateContentName()) : (0, import_babel_utils46.importDefault)(tag.hub.file, relativePath, getTagName(tag));
9775
+ tagIdentifier = isCircularRequest(tag.hub.file, relativePath) ? import_compiler56.types.identifier(getTemplateContentName()) : (0, import_babel_utils47.importDefault)(tag.hub.file, relativePath, getTagName(tag));
9379
9776
  } else {
9380
9777
  tagIdentifier = node.name;
9381
9778
  }
9382
9779
  const tagVar = node.var;
9383
9780
  const section = getSection(tag);
9384
- const inputExport = (0, import_babel_utils46.loadFileForTag)(tag)?.ast.program.extra?.domExports?.input;
9781
+ const childProgram = (0, import_babel_utils47.loadFileForTag)(tag).ast.program;
9782
+ const childExtra = childProgram.extra;
9783
+ const inputExport = childExtra.domExports?.input;
9385
9784
  const { properties, statements } = inputExport ? translateAttrs(tag, inputExport.props) : {
9386
9785
  properties: [],
9387
9786
  statements: []
@@ -9391,11 +9790,46 @@ function translateHTML(tag) {
9391
9790
  section,
9392
9791
  childScopeBinding
9393
9792
  );
9793
+ const childSerializeReasonIds = tagExtra[kChildInputSerializePropIds];
9794
+ let childSerializeReasonExpr;
9795
+ if (childSerializeReasonIds) {
9796
+ if (childSerializeReasonIds.length === 1) {
9797
+ childSerializeReasonExpr = getSerializeGuard(
9798
+ getBindingSerializeReason(
9799
+ section,
9800
+ childScopeBinding,
9801
+ childSerializeReasonIds[0]
9802
+ )
9803
+ );
9804
+ } else {
9805
+ const props = [];
9806
+ let hasDynamicReasons = false;
9807
+ let hasSkippedReasons = false;
9808
+ for (let i = 0; i < childSerializeReasonIds.length; i++) {
9809
+ const reason = getBindingSerializeReason(
9810
+ section,
9811
+ childScopeBinding,
9812
+ childSerializeReasonIds[i]
9813
+ );
9814
+ if (reason) {
9815
+ hasDynamicReasons ||= reason !== true;
9816
+ props.push(
9817
+ import_compiler56.types.objectProperty(import_compiler56.types.numericLiteral(i), getSerializeGuard(reason))
9818
+ );
9819
+ } else {
9820
+ hasSkippedReasons = true;
9821
+ }
9822
+ }
9823
+ if (props.length) {
9824
+ childSerializeReasonExpr = hasDynamicReasons || hasSkippedReasons ? import_compiler56.types.objectExpression(props) : import_compiler56.types.numericLiteral(1);
9825
+ }
9826
+ }
9827
+ }
9394
9828
  if (childScopeSerializeReason) {
9395
9829
  const peekScopeId = generateUidIdentifier(childScopeBinding?.name);
9396
9830
  tag.insertBefore(
9397
9831
  import_compiler56.types.variableDeclaration("const", [
9398
- import_compiler56.types.variableDeclarator(peekScopeId, callRuntime("peekNextScope"))
9832
+ import_compiler56.types.variableDeclarator(peekScopeId, callRuntime("peekNextScopeId"))
9399
9833
  ])
9400
9834
  );
9401
9835
  setBindingSerializedValue(
@@ -9443,7 +9877,8 @@ function translateHTML(tag) {
9443
9877
  }
9444
9878
  let renderTagExpr = callExpression(
9445
9879
  tagIdentifier,
9446
- propsToExpression(properties)
9880
+ propsToExpression(properties),
9881
+ childSerializeReasonExpr
9447
9882
  );
9448
9883
  if (tagVar) {
9449
9884
  translateVar(tag, import_compiler56.types.unaryExpression("void", import_compiler56.types.numericLiteral(0)), "let");
@@ -9459,12 +9894,19 @@ function translateHTML(tag) {
9459
9894
  } else if (tagVar) {
9460
9895
  translateVar(
9461
9896
  tag,
9462
- callExpression(tagIdentifier, propsToExpression(properties))
9897
+ callExpression(
9898
+ tagIdentifier,
9899
+ propsToExpression(properties),
9900
+ childSerializeReasonExpr
9901
+ )
9463
9902
  );
9464
- serializeSectionIfNeeded(section, true);
9465
9903
  } else {
9466
9904
  statements.push(
9467
- callStatement(tagIdentifier, propsToExpression(properties))
9905
+ callStatement(
9906
+ tagIdentifier,
9907
+ propsToExpression(properties),
9908
+ childSerializeReasonExpr
9909
+ )
9468
9910
  );
9469
9911
  }
9470
9912
  for (const replacement of tag.replaceWithMultiple(statements)) {
@@ -9480,7 +9922,7 @@ function translateDOM(tag) {
9480
9922
  const { file } = tag.hub;
9481
9923
  const tagName = import_compiler56.types.isIdentifier(node.name) ? node.name.name : import_compiler56.types.isStringLiteral(node.name) ? node.name.value : "tag";
9482
9924
  const relativePath = getTagRelativePath(tag);
9483
- const childFile = (0, import_babel_utils46.loadFileForTag)(tag);
9925
+ const childFile = (0, import_babel_utils47.loadFileForTag)(tag);
9484
9926
  const childExports = childFile.ast.program.extra.domExports;
9485
9927
  const tagIdentifier = importOrSelfReferenceName(
9486
9928
  file,
@@ -9498,10 +9940,10 @@ function translateDOM(tag) {
9498
9940
  attrTagCallsByTag: void 0
9499
9941
  });
9500
9942
  }
9501
- write2`${(0, import_babel_utils46.importNamed)(file, relativePath, childExports.template, `${tagName}_template`)}`;
9943
+ write2`${(0, import_babel_utils47.importNamed)(file, relativePath, childExports.template, `${tagName}_template`)}`;
9502
9944
  injectWalks(
9503
9945
  tag,
9504
- (0, import_babel_utils46.importNamed)(file, relativePath, childExports.walks, `${tagName}_walks`)
9946
+ (0, import_babel_utils47.importNamed)(file, relativePath, childExports.walks, `${tagName}_walks`)
9505
9947
  );
9506
9948
  if (node.var) {
9507
9949
  const source = initValue(
@@ -9548,8 +9990,8 @@ function getTagRelativePath(tag) {
9548
9990
  } = tag;
9549
9991
  let relativePath;
9550
9992
  if (import_compiler56.types.isStringLiteral(node.name)) {
9551
- const template = (0, import_babel_utils46.getTagTemplate)(tag);
9552
- relativePath = template && (0, import_babel_utils46.resolveRelativePath)(file, template);
9993
+ const template = (0, import_babel_utils47.getTagTemplate)(tag);
9994
+ relativePath = template && (0, import_babel_utils47.resolveRelativePath)(file, template);
9553
9995
  } else if (node.extra?.tagNameImported) {
9554
9996
  relativePath = node.extra.tagNameImported;
9555
9997
  }
@@ -9564,19 +10006,20 @@ function getTagRelativePath(tag) {
9564
10006
  }
9565
10007
  return relativePath;
9566
10008
  }
9567
- function analyzeAttrs(rootTagExtra, section, tag, templateExport, rootAttrExprs) {
10009
+ function analyzeAttrs(rootTagExtra, section, tag, templateExport, rootAttrExprs, inputExpr) {
9568
10010
  if (!templateExport) {
9569
10011
  dropReferences(getAllTagReferenceNodes(tag.node));
9570
10012
  return;
9571
10013
  }
9572
10014
  if (!templateExport.props || tag.node.arguments?.length) {
9573
- mergeReferences(section, tag.node, getAllTagReferenceNodes(tag.node));
10015
+ inputExpr.value = mergeReferences(
10016
+ section,
10017
+ tag.node,
10018
+ getAllTagReferenceNodes(tag.node)
10019
+ );
9574
10020
  return;
9575
10021
  }
9576
- const bodySection = getSectionForBody(tag.get("body"));
9577
- if (bodySection) {
9578
- bodySection.downstreamBinding = (templateExport.props.content || templateExport.props).binding;
9579
- }
10022
+ const known = inputExpr.known = {};
9580
10023
  const attrTagLookup = analyzeAttributeTags(tag);
9581
10024
  const seen = /* @__PURE__ */ new Set();
9582
10025
  if (attrTagLookup) {
@@ -9599,7 +10042,7 @@ function analyzeAttrs(rootTagExtra, section, tag, templateExport, rootAttrExprs)
9599
10042
  const attrTags2 = tag.node.body.attributeTags ? tag.get("body").get("body") : tag.get("attributeTags");
9600
10043
  for (const child of attrTags2) {
9601
10044
  if (child.isMarkoTag()) {
9602
- if ((0, import_babel_utils46.isAttributeTag)(child)) {
10045
+ if ((0, import_babel_utils47.isAttributeTag)(child)) {
9603
10046
  const attrTagMeta = attrTagLookup[getTagName(child)];
9604
10047
  const childAttrExports = templateExport.props[attrTagMeta.name];
9605
10048
  if (childAttrExports) {
@@ -9609,7 +10052,8 @@ function analyzeAttrs(rootTagExtra, section, tag, templateExport, rootAttrExprs)
9609
10052
  section,
9610
10053
  child,
9611
10054
  childAttrExports,
9612
- rootAttrExprs
10055
+ rootAttrExprs,
10056
+ known[attrTagMeta.name] = {}
9613
10057
  );
9614
10058
  } else {
9615
10059
  analyzeDynamicChildGroup(attrTagMeta.group, child);
@@ -9634,12 +10078,27 @@ function analyzeAttrs(rootTagExtra, section, tag, templateExport, rootAttrExprs)
9634
10078
  }
9635
10079
  }
9636
10080
  }
9637
- for (const {
9638
- firstTag: { node },
9639
- referenceNodes
9640
- } of nodeReferencesByGroup.values()) {
9641
- mergeReferences(section, node, referenceNodes);
9642
- rootAttrExprs.add(node.extra);
10081
+ for (const [
10082
+ group,
10083
+ {
10084
+ firstTag: { node },
10085
+ referenceNodes
10086
+ }
10087
+ ] of nodeReferencesByGroup) {
10088
+ const groupExtra = mergeReferences(section, node, referenceNodes);
10089
+ const groupKnownValue = { value: groupExtra };
10090
+ rootAttrExprs.add(groupExtra);
10091
+ for (const name2 of group) {
10092
+ known[attrTagLookup[name2].name] = groupKnownValue;
10093
+ }
10094
+ }
10095
+ }
10096
+ if (!seen.has("content")) {
10097
+ const bodySection = getSectionForBody(tag.get("body"));
10098
+ if (bodySection) {
10099
+ seen.add("content");
10100
+ known.content = { value: void 0 };
10101
+ bodySection.downstreamBinding = (templateExport.props.content || templateExport.props).binding;
9643
10102
  }
9644
10103
  }
9645
10104
  const { attributes } = tag.node;
@@ -9658,11 +10117,13 @@ function analyzeAttrs(rootTagExtra, section, tag, templateExport, rootAttrExprs)
9658
10117
  } else if (import_compiler56.types.isMarkoSpreadAttribute(attr2)) {
9659
10118
  spreadReferenceNodes = [attr2.value];
9660
10119
  } else {
9661
- rootAttrExprs.add(attr2.value.extra ??= {});
10120
+ const attrValueExtra = attr2.value.extra ??= {};
10121
+ known[attr2.name] = { value: attrValueExtra };
10122
+ rootAttrExprs.add(attrValueExtra);
9662
10123
  }
9663
10124
  }
9664
10125
  if (spreadReferenceNodes) {
9665
- mergeReferences(section, tag.node, spreadReferenceNodes);
10126
+ inputExpr.value = mergeReferences(section, tag.node, spreadReferenceNodes);
9666
10127
  }
9667
10128
  }
9668
10129
  function writeAttrsToExports(tag, templateExport, importAlias, info) {
@@ -9703,7 +10164,7 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
9703
10164
  );
9704
10165
  }
9705
10166
  let translatedProps = propsToExpression(translatedAttrs.properties);
9706
- if ((0, import_babel_utils46.isAttributeTag)(tag)) {
10167
+ if ((0, import_babel_utils47.isAttributeTag)(tag)) {
9707
10168
  const attrTagName = getTagName(tag);
9708
10169
  const parentTag = tag.parentPath;
9709
10170
  const repeated = analyzeAttributeTags(parentTag)?.[attrTagName]?.repeated;
@@ -9775,7 +10236,7 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
9775
10236
  for (let i = 0; i < attrTags2.length; i++) {
9776
10237
  const child = attrTags2[i];
9777
10238
  if (child.isMarkoTag()) {
9778
- if ((0, import_babel_utils46.isAttributeTag)(child)) {
10239
+ if ((0, import_babel_utils47.isAttributeTag)(child)) {
9779
10240
  const attrTagMeta = attrTagLookup[getTagName(child)];
9780
10241
  const childAttrExport = templateExport.props[attrTagMeta.name];
9781
10242
  if (childAttrExport) {
@@ -9832,7 +10293,7 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
9832
10293
  if (bodySection && !seen.has("content")) {
9833
10294
  seen.add("content");
9834
10295
  if (templateExport.props.content) {
9835
- const contentExportIdentifier = (0, import_babel_utils46.importNamed)(
10296
+ const contentExportIdentifier = (0, import_babel_utils47.importNamed)(
9836
10297
  tag.hub.file,
9837
10298
  info.relativePath,
9838
10299
  templateExport.props.content.id,
@@ -9921,7 +10382,37 @@ function importOrSelfReferenceName(file, request, name2, nameHint) {
9921
10382
  if (isCircularRequest(file, request)) {
9922
10383
  return import_compiler56.types.identifier(name2);
9923
10384
  }
9924
- return (0, import_babel_utils46.importNamed)(file, request, name2, nameHint);
10385
+ return (0, import_babel_utils47.importNamed)(file, request, name2, nameHint);
10386
+ }
10387
+ function mapChildReasonToLocalReason(childReason, childInputBinding, inputExpr) {
10388
+ if (childReason) {
10389
+ if (childReason === true) return true;
10390
+ return filterMap(
10391
+ childReason,
10392
+ (inputBinding) => resolveChildInputExpr(childInputBinding, inputBinding, inputExpr)
10393
+ );
10394
+ }
10395
+ }
10396
+ function resolveChildInputExpr(inputBinding, propBinding, expr) {
10397
+ if (expr) {
10398
+ let curExpr = expr;
10399
+ if (inputBinding !== propBinding) {
10400
+ const props = [propBinding.property];
10401
+ let curBinding = propBinding;
10402
+ while (inputBinding !== (curBinding = curBinding.upstreamAlias)) {
10403
+ props.push(curBinding.property);
10404
+ }
10405
+ for (let i = props.length; i--; ) {
10406
+ const nestedExpr = curExpr.known?.[props[i]];
10407
+ if (nestedExpr) {
10408
+ curExpr = nestedExpr;
10409
+ } else {
10410
+ break;
10411
+ }
10412
+ }
10413
+ }
10414
+ return curExpr.value;
10415
+ }
9925
10416
  }
9926
10417
  function isCircularRequest(file, request) {
9927
10418
  const { filename } = file.opts;
@@ -9948,42 +10439,33 @@ function always() {
9948
10439
 
9949
10440
  // src/translator/visitors/tag/dynamic-tag.ts
9950
10441
  var import_compiler57 = require("@marko/compiler");
9951
- var import_babel_utils47 = require("@marko/compiler/babel-utils");
10442
+ var import_babel_utils48 = require("@marko/compiler/babel-utils");
9952
10443
  var kDOMBinding3 = Symbol("dynamic tag dom binding");
9953
10444
  var kChildOffsetScopeBinding2 = Symbol("custom tag scope offset");
9954
10445
  var dynamic_tag_default = {
9955
10446
  analyze: {
9956
10447
  enter(tag) {
9957
- (0, import_babel_utils47.assertAttributesOrArgs)(tag);
10448
+ (0, import_babel_utils48.assertAttributesOrArgs)(tag);
9958
10449
  analyzeAttributeTags(tag);
9959
10450
  const tagSection = getOrCreateSection(tag);
9960
- const tagExtra = tag.node.extra ??= {};
10451
+ const tagExtra = mergeReferences(tagSection, tag.node, [
10452
+ tag.node.name,
10453
+ ...getAllTagReferenceNodes(tag.node)
10454
+ ]);
9961
10455
  const tagBody = tag.get("body");
9962
10456
  const isClassAPI = tagExtra.featureType === "class";
9963
10457
  const hasVar = !!tag.node.var;
9964
10458
  const nodeBinding = tagExtra[kDOMBinding3] = createBinding(
9965
10459
  "#text",
9966
10460
  0 /* dom */,
9967
- tagSection,
9968
- void 0,
9969
- tagExtra
10461
+ tagSection
9970
10462
  );
9971
10463
  if (hasVar) {
9972
10464
  trackVarReferences(tag, 4 /* derived */);
9973
- tag.node.var.extra.binding.scopeOffset = tagExtra[kChildOffsetScopeBinding2] = createBinding(
9974
- "#scopeOffset",
9975
- 0 /* dom */,
9976
- tagSection,
9977
- void 0,
9978
- tagExtra
9979
- );
10465
+ tag.node.var.extra.binding.scopeOffset = tagExtra[kChildOffsetScopeBinding2] = createBinding("#scopeOffset", 0 /* dom */, tagSection);
9980
10466
  }
9981
10467
  startSection(tagBody);
9982
10468
  trackParamsReferences(tagBody, 3 /* param */);
9983
- mergeReferences(tagSection, tag.node, [
9984
- tag.node.name,
9985
- ...getAllTagReferenceNodes(tag.node)
9986
- ]);
9987
10469
  addBindingSerializeReasonExpr(
9988
10470
  tagSection,
9989
10471
  nodeBinding,
@@ -10010,7 +10492,7 @@ var dynamic_tag_default = {
10010
10492
  const isClassAPI = tagExtra.featureType === "class";
10011
10493
  let tagExpression = node.name;
10012
10494
  if (import_compiler57.types.isStringLiteral(tagExpression)) {
10013
- tagExpression = (0, import_babel_utils47.importDefault)(
10495
+ tagExpression = (0, import_babel_utils48.importDefault)(
10014
10496
  tag.hub.file,
10015
10497
  getTagRelativePath(tag),
10016
10498
  tagExpression.value
@@ -10018,15 +10500,15 @@ var dynamic_tag_default = {
10018
10500
  }
10019
10501
  if (isClassAPI) {
10020
10502
  if (isOutputHTML()) {
10021
- (0, import_babel_utils47.getProgram)().node.body.push(
10503
+ (0, import_babel_utils48.getProgram)().node.body.push(
10022
10504
  import_compiler57.types.markoScriptlet(
10023
10505
  [
10024
10506
  import_compiler57.types.expressionStatement(
10025
10507
  import_compiler57.types.callExpression(
10026
- (0, import_babel_utils47.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"),
10508
+ (0, import_babel_utils48.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"),
10027
10509
  [
10028
10510
  import_compiler57.types.identifier(tagExpression.name),
10029
- import_compiler57.types.stringLiteral((0, import_babel_utils47.loadFileForTag)(tag).metadata.marko.id)
10511
+ import_compiler57.types.stringLiteral((0, import_babel_utils48.loadFileForTag)(tag).metadata.marko.id)
10030
10512
  ]
10031
10513
  )
10032
10514
  )
@@ -10035,11 +10517,11 @@ var dynamic_tag_default = {
10035
10517
  )
10036
10518
  );
10037
10519
  } else {
10038
- (0, import_babel_utils47.getProgram)().node.body.push(
10520
+ (0, import_babel_utils48.getProgram)().node.body.push(
10039
10521
  import_compiler57.types.expressionStatement(
10040
10522
  callRuntime(
10041
10523
  "register",
10042
- import_compiler57.types.stringLiteral((0, import_babel_utils47.loadFileForTag)(tag).metadata.marko.id),
10524
+ import_compiler57.types.stringLiteral((0, import_babel_utils48.loadFileForTag)(tag).metadata.marko.id),
10043
10525
  import_compiler57.types.identifier(tagExpression.name)
10044
10526
  )
10045
10527
  )
@@ -10084,7 +10566,7 @@ var dynamic_tag_default = {
10084
10566
  import_compiler57.types.arrayExpression(args),
10085
10567
  import_compiler57.types.numericLiteral(0),
10086
10568
  import_compiler57.types.numericLiteral(1),
10087
- serializeReason ? import_compiler57.types.numericLiteral(1) : void 0
10569
+ getSerializeGuard(serializeReason)
10088
10570
  ) : callRuntime(
10089
10571
  "dynamicTag",
10090
10572
  getScopeIdIdentifier(tagSection),
@@ -10093,15 +10575,17 @@ var dynamic_tag_default = {
10093
10575
  args[0],
10094
10576
  args[1] || (serializeReason ? import_compiler57.types.numericLiteral(0) : void 0),
10095
10577
  serializeReason ? import_compiler57.types.numericLiteral(0) : void 0,
10096
- serializeReason ? import_compiler57.types.numericLiteral(1) : void 0
10578
+ getSerializeGuard(serializeReason)
10097
10579
  );
10098
10580
  if (node.var) {
10099
- const dynamicScopeIdentifier = generateUidIdentifier("dynamicScope");
10581
+ const dynamicScopeIdentifier = generateUidIdentifier(
10582
+ tag.get("name").toString() + "_scope"
10583
+ );
10100
10584
  statements.push(
10101
10585
  import_compiler57.types.variableDeclaration("const", [
10102
10586
  import_compiler57.types.variableDeclarator(
10103
10587
  dynamicScopeIdentifier,
10104
- callRuntime("peekNextScope")
10588
+ callRuntime("peekNextScopeId")
10105
10589
  )
10106
10590
  ])
10107
10591
  );
@@ -10219,7 +10703,7 @@ var tag_default = {
10219
10703
  },
10220
10704
  analyze: {
10221
10705
  enter(tag) {
10222
- const tagDef = (0, import_babel_utils48.getTagDef)(tag);
10706
+ const tagDef = (0, import_babel_utils49.getTagDef)(tag);
10223
10707
  const type = analyzeTagNameType(tag);
10224
10708
  const hook = tagDef?.analyzer?.hook;
10225
10709
  if (hook) {
@@ -10243,7 +10727,7 @@ var tag_default = {
10243
10727
  }
10244
10728
  },
10245
10729
  exit(tag) {
10246
- const hook = (0, import_babel_utils48.getTagDef)(tag)?.analyzer?.hook;
10730
+ const hook = (0, import_babel_utils49.getTagDef)(tag)?.analyzer?.hook;
10247
10731
  if (hook) {
10248
10732
  exit(hook, tag);
10249
10733
  return;
@@ -10252,7 +10736,7 @@ var tag_default = {
10252
10736
  },
10253
10737
  translate: {
10254
10738
  enter(tag) {
10255
- const tagDef = (0, import_babel_utils48.getTagDef)(tag);
10739
+ const tagDef = (0, import_babel_utils49.getTagDef)(tag);
10256
10740
  const extra = tag.node.extra;
10257
10741
  if (tagDef?.translator) {
10258
10742
  if (tagDef.translator.path) {
@@ -10269,7 +10753,7 @@ var tag_default = {
10269
10753
  );
10270
10754
  }
10271
10755
  if (attr2.node.modifier) {
10272
- if ((0, import_babel_utils48.isNativeTag)(attr2.parentPath)) {
10756
+ if ((0, import_babel_utils49.isNativeTag)(attr2.parentPath)) {
10273
10757
  attr2.node.name += `:${attr2.node.modifier}`;
10274
10758
  } else {
10275
10759
  throw attr2.buildCodeFrameError(
@@ -10305,7 +10789,7 @@ var tag_default = {
10305
10789
  }
10306
10790
  },
10307
10791
  exit(tag) {
10308
- const translator = (0, import_babel_utils48.getTagDef)(tag)?.translator;
10792
+ const translator = (0, import_babel_utils49.getTagDef)(tag)?.translator;
10309
10793
  if (translator) {
10310
10794
  exit(translator.hook, tag);
10311
10795
  return;