marko 6.0.126 → 6.0.128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dom.js CHANGED
@@ -550,7 +550,7 @@ function init(runtimeId = "M") {
550
550
  let renders = self[runtimeId], defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc), resumeRender, initRuntime = (renders2) => {
551
551
  defineRuntime({
552
552
  value: resumeRender = ((renderId) => {
553
- let render = resumeRender[renderId] = renders2[renderId] || renders2(renderId), walk2 = render.w, scopeLookup = render.s = {}, serializeContext = {
553
+ let render = resumeRender[renderId] = renders2[renderId] || renders2(renderId), walk2 = render.w, scopeLookup = render.s = {}, getScope = (id) => scopeLookup[id] ||= { L: +id }, serializeContext = {
554
554
  _: registeredValues
555
555
  }, visitBranches = branchesEnabled && /* @__PURE__ */ ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
556
556
  for (visitType !== "[" /* BranchStart */ && (visitScope["J" /* Getter */ + nextToken(
@@ -561,9 +561,7 @@ function init(runtimeId = "M") {
561
561
  /* read optional first branchId */
562
562
  )); branchId = +lastToken; ) {
563
563
  if ((endedBranches ||= []).push(
564
- branch = scopeLookup[branchId] ||= {
565
- L: branchId
566
- }
564
+ branch = getScope(branchId)
567
565
  ), setParentBranch(branch, branch.F), (branch.O = render.p?.[branchId]) && (branch.O.m = render.m), singleNode) {
568
566
  for (; startVisit.previousSibling && ~visits.indexOf(
569
567
  startVisit = startVisit.previousSibling
@@ -586,21 +584,16 @@ function init(runtimeId = "M") {
586
584
  for (let serialized of resumes = render.r || [])
587
585
  if (typeof serialized == "string")
588
586
  for (lastTokenIndex = 0, visitText = serialized; nextToken(); )
589
- /\D/.test(lastToken) ? lastEffect = registeredValues[lastToken] : effects.push(
590
- lastEffect,
591
- scopeLookup[lastToken] ||= {
592
- L: +lastToken
593
- }
594
- );
587
+ /\D/.test(lastToken) ? lastEffect = registeredValues[lastToken] : effects.push(lastEffect, getScope(lastToken));
595
588
  else
596
589
  for (let scope of serialized(serializeContext))
597
- $global ? typeof scope == "number" ? lastScopeId += scope : (scopeLookup[scope.L = ++lastScopeId] = scope, scope.$ = $global, branchesEnabled && (scope.F = scopeLookup[scope.G])) : ($global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId);
590
+ $global ? typeof scope == "number" ? lastScopeId += scope : (scopeLookup[scope.L = ++lastScopeId] = scope, scope.$ = $global, branchesEnabled && (scope.F = getScope(
591
+ scope.G
592
+ ))) : ($global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId);
598
593
  for (visit of visits = render.v)
599
- lastTokenIndex = render.i.length, visitText = visit.data, visitType = visitText[lastTokenIndex++], visitScope = scopeLookup[+nextToken(
594
+ lastTokenIndex = render.i.length, visitText = visit.data, visitType = visitText[lastTokenIndex++], visitScope = getScope(nextToken(
600
595
  /* read scope id */
601
- )] ||= {
602
- L: +lastToken
603
- }, visitType === "*" /* Node */ ? visitScope["J" /* Getter */ + nextToken()] = /* @__PURE__ */ ((node) => () => node)(visitScope[lastToken] = visit.previousSibling) : branchesEnabled && visitBranches();
596
+ )), visitType === "*" /* Node */ ? visitScope["J" /* Getter */ + nextToken()] = /* @__PURE__ */ ((node) => () => node)(visitScope[lastToken] = visit.previousSibling) : branchesEnabled && visitBranches();
604
597
  return visits.length = resumes.length = 0, effects;
605
598
  }, render.w = () => {
606
599
  walk2(), runResumeEffects(render);
@@ -1385,7 +1378,7 @@ function loop(forEach) {
1385
1378
  scope,
1386
1379
  parentNode
1387
1380
  );
1388
- params?.(branch, args), newScopesByKey.set(key, branch), newScopes.push(branch);
1381
+ branch.M = key, params?.(branch, args), newScopesByKey.set(key, branch), newScopes.push(branch);
1389
1382
  });
1390
1383
  let afterReference = null;
1391
1384
  referenceNode !== parentNode && (oldScopes.length ? (afterReference = oldScopes[oldScopes.length - 1].K.nextSibling, newScopes.length || parentNode.insertBefore(referenceNode, afterReference)) : newScopes.length && (afterReference = referenceNode.nextSibling, referenceNode.remove())), reconcile(parentNode, oldScopes, newScopes, afterReference);
package/dist/dom.mjs CHANGED
@@ -447,7 +447,7 @@ function init(runtimeId = "M") {
447
447
  let renders = self[runtimeId], defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc), resumeRender, initRuntime = (renders2) => {
448
448
  defineRuntime({
449
449
  value: resumeRender = ((renderId) => {
450
- let render = resumeRender[renderId] = renders2[renderId] || renders2(renderId), walk2 = render.w, scopeLookup = render.s = {}, serializeContext = {
450
+ let render = resumeRender[renderId] = renders2[renderId] || renders2(renderId), walk2 = render.w, scopeLookup = render.s = {}, getScope = (id) => scopeLookup[id] ||= { L: +id }, serializeContext = {
451
451
  _: registeredValues
452
452
  }, visitBranches = branchesEnabled && /* @__PURE__ */ ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
453
453
  for (visitType !== "[" /* BranchStart */ && (visitScope["J" /* Getter */ + nextToken(
@@ -458,9 +458,7 @@ function init(runtimeId = "M") {
458
458
  /* read optional first branchId */
459
459
  )); branchId = +lastToken; ) {
460
460
  if ((endedBranches ||= []).push(
461
- branch = scopeLookup[branchId] ||= {
462
- L: branchId
463
- }
461
+ branch = getScope(branchId)
464
462
  ), setParentBranch(branch, branch.F), (branch.O = render.p?.[branchId]) && (branch.O.m = render.m), singleNode) {
465
463
  for (; startVisit.previousSibling && ~visits.indexOf(
466
464
  startVisit = startVisit.previousSibling
@@ -483,21 +481,16 @@ function init(runtimeId = "M") {
483
481
  for (let serialized of resumes = render.r || [])
484
482
  if (typeof serialized == "string")
485
483
  for (lastTokenIndex = 0, visitText = serialized; nextToken(); )
486
- /\D/.test(lastToken) ? lastEffect = registeredValues[lastToken] : effects.push(
487
- lastEffect,
488
- scopeLookup[lastToken] ||= {
489
- L: +lastToken
490
- }
491
- );
484
+ /\D/.test(lastToken) ? lastEffect = registeredValues[lastToken] : effects.push(lastEffect, getScope(lastToken));
492
485
  else
493
486
  for (let scope of serialized(serializeContext))
494
- $global ? typeof scope == "number" ? lastScopeId += scope : (scopeLookup[scope.L = ++lastScopeId] = scope, scope.$ = $global, branchesEnabled && (scope.F = scopeLookup[scope.G])) : ($global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId);
487
+ $global ? typeof scope == "number" ? lastScopeId += scope : (scopeLookup[scope.L = ++lastScopeId] = scope, scope.$ = $global, branchesEnabled && (scope.F = getScope(
488
+ scope.G
489
+ ))) : ($global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId);
495
490
  for (visit of visits = render.v)
496
- lastTokenIndex = render.i.length, visitText = visit.data, visitType = visitText[lastTokenIndex++], visitScope = scopeLookup[+nextToken(
491
+ lastTokenIndex = render.i.length, visitText = visit.data, visitType = visitText[lastTokenIndex++], visitScope = getScope(nextToken(
497
492
  /* read scope id */
498
- )] ||= {
499
- L: +lastToken
500
- }, visitType === "*" /* Node */ ? visitScope["J" /* Getter */ + nextToken()] = /* @__PURE__ */ ((node) => () => node)(visitScope[lastToken] = visit.previousSibling) : branchesEnabled && visitBranches();
493
+ )), visitType === "*" /* Node */ ? visitScope["J" /* Getter */ + nextToken()] = /* @__PURE__ */ ((node) => () => node)(visitScope[lastToken] = visit.previousSibling) : branchesEnabled && visitBranches();
501
494
  return visits.length = resumes.length = 0, effects;
502
495
  }, render.w = () => {
503
496
  walk2(), runResumeEffects(render);
@@ -1282,7 +1275,7 @@ function loop(forEach) {
1282
1275
  scope,
1283
1276
  parentNode
1284
1277
  );
1285
- params?.(branch, args), newScopesByKey.set(key, branch), newScopes.push(branch);
1278
+ branch.M = key, params?.(branch, args), newScopesByKey.set(key, branch), newScopes.push(branch);
1286
1279
  });
1287
1280
  let afterReference = null;
1288
1281
  referenceNode !== parentNode && (oldScopes.length ? (afterReference = oldScopes[oldScopes.length - 1].K.nextSibling, newScopes.length || parentNode.insertBefore(referenceNode, afterReference)) : newScopes.length && (afterReference = referenceNode.nextSibling, referenceNode.remove())), reconcile(parentNode, oldScopes, newScopes, afterReference);
@@ -5,8 +5,10 @@ import type { ServerRenderer } from "./template";
5
5
  export type PartialScope = Record<Accessor, unknown>;
6
6
  type ScopeInternals = PartialScope & {
7
7
  [K_SCOPE_ID]?: number;
8
+ [K_SCOPE_REFERENCED]?: 1;
8
9
  };
9
10
  declare const K_SCOPE_ID: unique symbol;
11
+ declare const K_SCOPE_REFERENCED: unique symbol;
10
12
  declare enum Mark {
11
13
  Placeholder = "!^",
12
14
  PlaceholderEnd = "!",
@@ -52,7 +54,7 @@ declare let writeScope: (scopeId: number, partialScope: PartialScope) => ScopeIn
52
54
  export declare function writeScopeToState(state: State, scopeId: number, partialScope: PartialScope): ScopeInternals;
53
55
  export { writeScope as _scope };
54
56
  export declare function _existing_scope(scopeId: number): ScopeInternals;
55
- export declare function _scope_with_id(scopeId: number): PartialScope;
57
+ export declare function _scope_with_id(scopeId: number): ScopeInternals;
56
58
  export declare function $global(): $Global & {
57
59
  renderId: string;
58
60
  runtimeId: string;
package/dist/html.js CHANGED
@@ -1131,7 +1131,7 @@ function compareRegisteredReferences(a, b) {
1131
1131
 
1132
1132
  // src/html/writer.ts
1133
1133
  var $chunk, NOOP = () => {
1134
- }, K_SCOPE_ID = Symbol("Scope ID");
1134
+ }, K_SCOPE_ID = Symbol("Scope ID"), K_SCOPE_REFERENCED = Symbol("Scope Referenced");
1135
1135
  function getChunk() {
1136
1136
  return $chunk;
1137
1137
  }
@@ -1246,7 +1246,7 @@ function withIsAsync(cb, value) {
1246
1246
  return withContext(kIsAsync, !0, cb, value);
1247
1247
  }
1248
1248
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1249
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1249
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1250
1250
  if (serializeBranch !== 0) {
1251
1251
  let loopScopes;
1252
1252
  if (0)
@@ -1256,9 +1256,9 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1256
1256
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1257
1257
  state.mark("[" /* BranchStart */, flushBranchIds)
1258
1258
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1259
- cb(item, index), resumeMarker ? writeScope(branchId, {
1260
- M: item === index ? void 0 : itemKey
1261
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1259
+ cb(item, index);
1260
+ let branchScope = writeScope(branchId, {});
1261
+ resumeKeys && itemKey !== index && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1262
1262
  });
1263
1263
  }), loopScopes && writeScope(scopeId, {
1264
1264
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1269,14 +1269,14 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1269
1269
  scopeId,
1270
1270
  accessor,
1271
1271
  serializeStateful,
1272
- resumeMarker,
1272
+ serializeMarker,
1273
1273
  parentEndTag,
1274
1274
  singleNode,
1275
1275
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1276
1276
  );
1277
1277
  }
1278
1278
  function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1279
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1279
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1280
1280
  if (serializeBranch !== 0) {
1281
1281
  let loopScopes;
1282
1282
  if (0)
@@ -1286,9 +1286,9 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
1286
1286
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1287
1287
  state.mark("[" /* BranchStart */, flushBranchIds)
1288
1288
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1289
- cb(key, value), resumeMarker ? writeScope(branchId, {
1290
- M: itemKey
1291
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1289
+ cb(key, value);
1290
+ let branchScope = writeScope(branchId, {});
1291
+ resumeKeys && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1292
1292
  });
1293
1293
  }), loopScopes && writeScope(scopeId, {
1294
1294
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1299,14 +1299,14 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
1299
1299
  scopeId,
1300
1300
  accessor,
1301
1301
  serializeStateful,
1302
- resumeMarker,
1302
+ serializeMarker,
1303
1303
  parentEndTag,
1304
1304
  singleNode,
1305
1305
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1306
1306
  );
1307
1307
  }
1308
1308
  function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1309
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1309
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1310
1310
  if (serializeBranch !== 0) {
1311
1311
  let loopScopes;
1312
1312
  if (0)
@@ -1316,9 +1316,9 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
1316
1316
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1317
1317
  state.mark("[" /* BranchStart */, flushBranchIds)
1318
1318
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1319
- cb(i), resumeMarker ? writeScope(branchId, {
1320
- M: itemKey === i ? void 0 : itemKey
1321
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1319
+ cb(i);
1320
+ let branchScope = writeScope(branchId, {});
1321
+ resumeKeys && itemKey !== i && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1322
1322
  });
1323
1323
  }), loopScopes && writeScope(scopeId, {
1324
1324
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1329,14 +1329,14 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
1329
1329
  scopeId,
1330
1330
  accessor,
1331
1331
  serializeStateful,
1332
- resumeMarker,
1332
+ serializeMarker,
1333
1333
  parentEndTag,
1334
1334
  singleNode,
1335
1335
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1336
1336
  );
1337
1337
  }
1338
1338
  function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1339
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1339
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1340
1340
  if (serializeBranch !== 0) {
1341
1341
  let loopScopes;
1342
1342
  if (0)
@@ -1346,9 +1346,9 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
1346
1346
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1347
1347
  state.mark("[" /* BranchStart */, flushBranchIds)
1348
1348
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1349
- cb(i), resumeMarker ? writeScope(branchId, {
1350
- M: itemKey === i ? void 0 : itemKey
1351
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1349
+ cb(i);
1350
+ let branchScope = writeScope(branchId, {});
1351
+ resumeKeys && itemKey !== i && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1352
1352
  });
1353
1353
  }), loopScopes && writeScope(scopeId, {
1354
1354
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1359,14 +1359,14 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
1359
1359
  scopeId,
1360
1360
  accessor,
1361
1361
  serializeStateful,
1362
- resumeMarker,
1362
+ serializeMarker,
1363
1363
  parentEndTag,
1364
1364
  singleNode,
1365
1365
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1366
1366
  );
1367
1367
  }
1368
1368
  function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1369
- let { state } = $chunk.boundary, resumeBranch = serializeBranch !== 0, resumeMarker = serializeMarker !== 0, branchId = _peek_scope_id();
1369
+ let { state } = $chunk.boundary, resumeBranch = serializeBranch !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), branchId = _peek_scope_id();
1370
1370
  resumeMarker && resumeBranch && !singleNode && $chunk.writeHTML(state.mark("[" /* BranchStart */, ""));
1371
1371
  let branchIndex = resumeBranch ? withBranchId(branchId, cb) : cb(), shouldWriteBranch = resumeBranch && branchIndex !== void 0;
1372
1372
  shouldWriteBranch && (branchIndex || !resumeMarker) && writeScope(scopeId, {
@@ -1375,20 +1375,20 @@ function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeS
1375
1375
  // It may make sense to pass in another arg for this.
1376
1376
  ["D" /* ConditionalRenderer */ + accessor]: branchIndex || void 0,
1377
1377
  // we convert 0 to undefined since the runtime defaults branch to 0.
1378
- ["A" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
1378
+ ["A" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : referenceScope(writeScope(branchId, {}))
1379
1379
  }), writeBranchEnd(
1380
1380
  scopeId,
1381
1381
  accessor,
1382
1382
  serializeStateful,
1383
- resumeMarker,
1383
+ serializeMarker,
1384
1384
  parentEndTag,
1385
1385
  singleNode,
1386
1386
  shouldWriteBranch ? " " + branchId : ""
1387
1387
  );
1388
1388
  }
1389
- function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, parentEndTag, singleNode, branchIds) {
1389
+ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
1390
1390
  let endTag = parentEndTag || "";
1391
- if (resumeMarker)
1391
+ if (serializeMarker !== 0)
1392
1392
  if (!parentEndTag || serializeStateful !== 0) {
1393
1393
  let { state } = $chunk.boundary, mark = singleNode ? state.mark(
1394
1394
  parentEndTag ? "}" /* BranchEndSingleNodeOnlyChildInParent */ : "|" /* BranchEndSingleNode */,
@@ -1403,6 +1403,12 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, pare
1403
1403
  else
1404
1404
  $chunk.writeHTML(endTag);
1405
1405
  }
1406
+ function scopeHasReference(scope) {
1407
+ return !!scope[K_SCOPE_REFERENCED];
1408
+ }
1409
+ function referenceScope(scope) {
1410
+ return scope[K_SCOPE_REFERENCED] = 1, scope;
1411
+ }
1406
1412
  var writeScope = (scopeId, partialScope) => writeScopeToState($chunk.boundary.state, scopeId, partialScope);
1407
1413
  function writeScopeToState(state, scopeId, partialScope) {
1408
1414
  let { scopes } = state, scope = scopes.get(scopeId);
@@ -1413,7 +1419,7 @@ function _existing_scope(scopeId) {
1413
1419
  }
1414
1420
  function _scope_with_id(scopeId) {
1415
1421
  let { state } = $chunk.boundary, scope = state.scopes.get(scopeId);
1416
- return scope || (scope = { [K_SCOPE_ID]: scopeId }, state.scopes.set(scopeId, scope)), scope;
1422
+ return scope || (scope = { [K_SCOPE_ID]: scopeId }, state.scopes.set(scopeId, scope)), referenceScope(scope);
1417
1423
  }
1418
1424
  function $global() {
1419
1425
  return $chunk.boundary.state.$global;
@@ -1696,16 +1702,19 @@ var Boundary = class extends AbortController {
1696
1702
  function flushSerializer(boundary) {
1697
1703
  let { state } = boundary, { writeScopes, serializer } = state, { flushed } = serializer;
1698
1704
  if (writeScopes || flushed) {
1699
- let serializeData = [], { lastSerializedScopeId } = state;
1700
- state.hasGlobals || (state.hasGlobals = !0, serializeData.push(getFilteredGlobals(state.$global)));
1705
+ let shouldSerialize = !1, serializeData = [], { lastSerializedScopeId } = state;
1706
+ state.hasGlobals || (state.hasGlobals = !0, serializeData.push(getFilteredGlobals(state.$global)), shouldSerialize = !0);
1701
1707
  for (let key in writeScopes) {
1702
- let scope = writeScopes[key], scopeId = getScopeId(scope), scopeIdDelta = scopeId - lastSerializedScopeId;
1703
- lastSerializedScopeId = scopeId + 1, scopeIdDelta && serializeData.push(scopeIdDelta), serializeData.push(scope);
1708
+ let scope = writeScopes[key];
1709
+ if (scopeHasReference(scope) || Object.getOwnPropertyNames(scope).length) {
1710
+ let scopeId = getScopeId(scope), scopeIdDelta = scopeId - lastSerializedScopeId;
1711
+ lastSerializedScopeId = scopeId + 1, scopeIdDelta && serializeData.push(scopeIdDelta), serializeData.push(scope), shouldSerialize = !0;
1712
+ }
1704
1713
  }
1705
- state.resumes = concatSequence(
1714
+ shouldSerialize && (state.resumes = concatSequence(
1706
1715
  state.resumes,
1707
1716
  serializer.stringify(serializeData, boundary)
1708
- ), state.lastSerializedScopeId = lastSerializedScopeId, state.writeScopes = null, flushed && (state.walkOnNextFlush = !0);
1717
+ )), state.lastSerializedScopeId = lastSerializedScopeId, state.writeScopes = null, flushed && (state.walkOnNextFlush = !0);
1709
1718
  }
1710
1719
  }
1711
1720
  function _trailers(html) {
@@ -1755,7 +1764,7 @@ function getFilteredGlobals($global2) {
1755
1764
  return filtered;
1756
1765
  }
1757
1766
  function _subscribe(subscribers, scope) {
1758
- return $chunk.boundary.state.serializer.writeCall(scope, subscribers, "add"), scope;
1767
+ return $chunk.boundary.state.serializer.writeCall(scope, subscribers, "add"), referenceScope(scope);
1759
1768
  }
1760
1769
 
1761
1770
  // src/html/attrs.ts
package/dist/html.mjs CHANGED
@@ -1041,7 +1041,7 @@ function compareRegisteredReferences(a, b) {
1041
1041
 
1042
1042
  // src/html/writer.ts
1043
1043
  var $chunk, NOOP = () => {
1044
- }, K_SCOPE_ID = Symbol("Scope ID");
1044
+ }, K_SCOPE_ID = Symbol("Scope ID"), K_SCOPE_REFERENCED = Symbol("Scope Referenced");
1045
1045
  function getChunk() {
1046
1046
  return $chunk;
1047
1047
  }
@@ -1156,7 +1156,7 @@ function withIsAsync(cb, value) {
1156
1156
  return withContext(kIsAsync, !0, cb, value);
1157
1157
  }
1158
1158
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1159
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1159
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1160
1160
  if (serializeBranch !== 0) {
1161
1161
  let loopScopes;
1162
1162
  if (0)
@@ -1166,9 +1166,9 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1166
1166
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1167
1167
  state.mark("[" /* BranchStart */, flushBranchIds)
1168
1168
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1169
- cb(item, index), resumeMarker ? writeScope(branchId, {
1170
- M: item === index ? void 0 : itemKey
1171
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1169
+ cb(item, index);
1170
+ let branchScope = writeScope(branchId, {});
1171
+ resumeKeys && itemKey !== index && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1172
1172
  });
1173
1173
  }), loopScopes && writeScope(scopeId, {
1174
1174
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1179,14 +1179,14 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1179
1179
  scopeId,
1180
1180
  accessor,
1181
1181
  serializeStateful,
1182
- resumeMarker,
1182
+ serializeMarker,
1183
1183
  parentEndTag,
1184
1184
  singleNode,
1185
1185
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1186
1186
  );
1187
1187
  }
1188
1188
  function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1189
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1189
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1190
1190
  if (serializeBranch !== 0) {
1191
1191
  let loopScopes;
1192
1192
  if (0)
@@ -1196,9 +1196,9 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
1196
1196
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1197
1197
  state.mark("[" /* BranchStart */, flushBranchIds)
1198
1198
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1199
- cb(key, value), resumeMarker ? writeScope(branchId, {
1200
- M: itemKey
1201
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1199
+ cb(key, value);
1200
+ let branchScope = writeScope(branchId, {});
1201
+ resumeKeys && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1202
1202
  });
1203
1203
  }), loopScopes && writeScope(scopeId, {
1204
1204
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1209,14 +1209,14 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
1209
1209
  scopeId,
1210
1210
  accessor,
1211
1211
  serializeStateful,
1212
- resumeMarker,
1212
+ serializeMarker,
1213
1213
  parentEndTag,
1214
1214
  singleNode,
1215
1215
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1216
1216
  );
1217
1217
  }
1218
1218
  function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1219
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1219
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1220
1220
  if (serializeBranch !== 0) {
1221
1221
  let loopScopes;
1222
1222
  if (0)
@@ -1226,9 +1226,9 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
1226
1226
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1227
1227
  state.mark("[" /* BranchStart */, flushBranchIds)
1228
1228
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1229
- cb(i), resumeMarker ? writeScope(branchId, {
1230
- M: itemKey === i ? void 0 : itemKey
1231
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1229
+ cb(i);
1230
+ let branchScope = writeScope(branchId, {});
1231
+ resumeKeys && itemKey !== i && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1232
1232
  });
1233
1233
  }), loopScopes && writeScope(scopeId, {
1234
1234
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1239,14 +1239,14 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
1239
1239
  scopeId,
1240
1240
  accessor,
1241
1241
  serializeStateful,
1242
- resumeMarker,
1242
+ serializeMarker,
1243
1243
  parentEndTag,
1244
1244
  singleNode,
1245
1245
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1246
1246
  );
1247
1247
  }
1248
1248
  function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1249
- let { state } = $chunk.boundary, resumeMarker = serializeMarker !== 0, flushBranchIds = "";
1249
+ let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "";
1250
1250
  if (serializeBranch !== 0) {
1251
1251
  let loopScopes;
1252
1252
  if (0)
@@ -1256,9 +1256,9 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
1256
1256
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(
1257
1257
  state.mark("[" /* BranchStart */, flushBranchIds)
1258
1258
  ), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1259
- cb(i), resumeMarker ? writeScope(branchId, {
1260
- M: itemKey === i ? void 0 : itemKey
1261
- }) : loopScopes = push(loopScopes, writeScope(branchId, {}));
1259
+ cb(i);
1260
+ let branchScope = writeScope(branchId, {});
1261
+ resumeKeys && itemKey !== i && (branchScope.M = itemKey), resumeMarker || (loopScopes = push(loopScopes, referenceScope(branchScope)));
1262
1262
  });
1263
1263
  }), loopScopes && writeScope(scopeId, {
1264
1264
  ["A" /* BranchScopes */ + accessor]: loopScopes
@@ -1269,14 +1269,14 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
1269
1269
  scopeId,
1270
1270
  accessor,
1271
1271
  serializeStateful,
1272
- resumeMarker,
1272
+ serializeMarker,
1273
1273
  parentEndTag,
1274
1274
  singleNode,
1275
1275
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
1276
1276
  );
1277
1277
  }
1278
1278
  function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1279
- let { state } = $chunk.boundary, resumeBranch = serializeBranch !== 0, resumeMarker = serializeMarker !== 0, branchId = _peek_scope_id();
1279
+ let { state } = $chunk.boundary, resumeBranch = serializeBranch !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), branchId = _peek_scope_id();
1280
1280
  resumeMarker && resumeBranch && !singleNode && $chunk.writeHTML(state.mark("[" /* BranchStart */, ""));
1281
1281
  let branchIndex = resumeBranch ? withBranchId(branchId, cb) : cb(), shouldWriteBranch = resumeBranch && branchIndex !== void 0;
1282
1282
  shouldWriteBranch && (branchIndex || !resumeMarker) && writeScope(scopeId, {
@@ -1285,20 +1285,20 @@ function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeS
1285
1285
  // It may make sense to pass in another arg for this.
1286
1286
  ["D" /* ConditionalRenderer */ + accessor]: branchIndex || void 0,
1287
1287
  // we convert 0 to undefined since the runtime defaults branch to 0.
1288
- ["A" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
1288
+ ["A" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : referenceScope(writeScope(branchId, {}))
1289
1289
  }), writeBranchEnd(
1290
1290
  scopeId,
1291
1291
  accessor,
1292
1292
  serializeStateful,
1293
- resumeMarker,
1293
+ serializeMarker,
1294
1294
  parentEndTag,
1295
1295
  singleNode,
1296
1296
  shouldWriteBranch ? " " + branchId : ""
1297
1297
  );
1298
1298
  }
1299
- function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, parentEndTag, singleNode, branchIds) {
1299
+ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
1300
1300
  let endTag = parentEndTag || "";
1301
- if (resumeMarker)
1301
+ if (serializeMarker !== 0)
1302
1302
  if (!parentEndTag || serializeStateful !== 0) {
1303
1303
  let { state } = $chunk.boundary, mark = singleNode ? state.mark(
1304
1304
  parentEndTag ? "}" /* BranchEndSingleNodeOnlyChildInParent */ : "|" /* BranchEndSingleNode */,
@@ -1313,6 +1313,12 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, pare
1313
1313
  else
1314
1314
  $chunk.writeHTML(endTag);
1315
1315
  }
1316
+ function scopeHasReference(scope) {
1317
+ return !!scope[K_SCOPE_REFERENCED];
1318
+ }
1319
+ function referenceScope(scope) {
1320
+ return scope[K_SCOPE_REFERENCED] = 1, scope;
1321
+ }
1316
1322
  var writeScope = (scopeId, partialScope) => writeScopeToState($chunk.boundary.state, scopeId, partialScope);
1317
1323
  function writeScopeToState(state, scopeId, partialScope) {
1318
1324
  let { scopes } = state, scope = scopes.get(scopeId);
@@ -1323,7 +1329,7 @@ function _existing_scope(scopeId) {
1323
1329
  }
1324
1330
  function _scope_with_id(scopeId) {
1325
1331
  let { state } = $chunk.boundary, scope = state.scopes.get(scopeId);
1326
- return scope || (scope = { [K_SCOPE_ID]: scopeId }, state.scopes.set(scopeId, scope)), scope;
1332
+ return scope || (scope = { [K_SCOPE_ID]: scopeId }, state.scopes.set(scopeId, scope)), referenceScope(scope);
1327
1333
  }
1328
1334
  function $global() {
1329
1335
  return $chunk.boundary.state.$global;
@@ -1606,16 +1612,19 @@ var Boundary = class extends AbortController {
1606
1612
  function flushSerializer(boundary) {
1607
1613
  let { state } = boundary, { writeScopes, serializer } = state, { flushed } = serializer;
1608
1614
  if (writeScopes || flushed) {
1609
- let serializeData = [], { lastSerializedScopeId } = state;
1610
- state.hasGlobals || (state.hasGlobals = !0, serializeData.push(getFilteredGlobals(state.$global)));
1615
+ let shouldSerialize = !1, serializeData = [], { lastSerializedScopeId } = state;
1616
+ state.hasGlobals || (state.hasGlobals = !0, serializeData.push(getFilteredGlobals(state.$global)), shouldSerialize = !0);
1611
1617
  for (let key in writeScopes) {
1612
- let scope = writeScopes[key], scopeId = getScopeId(scope), scopeIdDelta = scopeId - lastSerializedScopeId;
1613
- lastSerializedScopeId = scopeId + 1, scopeIdDelta && serializeData.push(scopeIdDelta), serializeData.push(scope);
1618
+ let scope = writeScopes[key];
1619
+ if (scopeHasReference(scope) || Object.getOwnPropertyNames(scope).length) {
1620
+ let scopeId = getScopeId(scope), scopeIdDelta = scopeId - lastSerializedScopeId;
1621
+ lastSerializedScopeId = scopeId + 1, scopeIdDelta && serializeData.push(scopeIdDelta), serializeData.push(scope), shouldSerialize = !0;
1622
+ }
1614
1623
  }
1615
- state.resumes = concatSequence(
1624
+ shouldSerialize && (state.resumes = concatSequence(
1616
1625
  state.resumes,
1617
1626
  serializer.stringify(serializeData, boundary)
1618
- ), state.lastSerializedScopeId = lastSerializedScopeId, state.writeScopes = null, flushed && (state.walkOnNextFlush = !0);
1627
+ )), state.lastSerializedScopeId = lastSerializedScopeId, state.writeScopes = null, flushed && (state.walkOnNextFlush = !0);
1619
1628
  }
1620
1629
  }
1621
1630
  function _trailers(html) {
@@ -1665,7 +1674,7 @@ function getFilteredGlobals($global2) {
1665
1674
  return filtered;
1666
1675
  }
1667
1676
  function _subscribe(subscribers, scope) {
1668
- return $chunk.boundary.state.serializer.writeCall(scope, subscribers, "add"), scope;
1677
+ return $chunk.boundary.state.serializer.writeCall(scope, subscribers, "add"), referenceScope(scope);
1669
1678
  }
1670
1679
 
1671
1680
  // src/html/attrs.ts