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/debug/dom.js CHANGED
@@ -881,6 +881,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
881
881
  const render = resumeRender[renderId] = renders2[renderId] || renders2(renderId);
882
882
  const walk2 = render.w;
883
883
  const scopeLookup = render.s = {};
884
+ const getScope = (id) => scopeLookup[id] ||= { ["#Id" /* Id */]: +id };
884
885
  const serializeContext = {
885
886
  _: registeredValues
886
887
  };
@@ -900,9 +901,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
900
901
  }
901
902
  while (branchId = +lastToken) {
902
903
  (endedBranches ||= []).push(
903
- branch = scopeLookup[branchId] ||= {
904
- ["#Id" /* Id */]: branchId
905
- }
904
+ branch = getScope(branchId)
906
905
  );
907
906
  setParentBranch(branch, branch["#ClosestBranch" /* ClosestBranch */]);
908
907
  if (branch["#AwaitCounter" /* AwaitCounter */] = render.p?.[branchId]) {
@@ -975,12 +974,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
975
974
  if (/\D/.test(lastToken)) {
976
975
  lastEffect = registeredValues[lastToken];
977
976
  } else {
978
- effects.push(
979
- lastEffect,
980
- scopeLookup[lastToken] ||= {
981
- ["#Id" /* Id */]: +lastToken
982
- }
983
- );
977
+ effects.push(lastEffect, getScope(lastToken));
984
978
  }
985
979
  }
986
980
  } else {
@@ -995,7 +989,9 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
995
989
  scopeLookup[scope["#Id" /* Id */] = ++lastScopeId] = scope;
996
990
  scope["$global" /* Global */] = $global;
997
991
  if (branchesEnabled) {
998
- scope["#ClosestBranch" /* ClosestBranch */] = scopeLookup[scope["#ClosestBranchId" /* ClosestBranchId */]];
992
+ scope["#ClosestBranch" /* ClosestBranch */] = getScope(
993
+ scope["#ClosestBranchId" /* ClosestBranchId */]
994
+ );
999
995
  }
1000
996
  }
1001
997
  }
@@ -1005,11 +1001,9 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
1005
1001
  lastTokenIndex = render.i.length;
1006
1002
  visitText = visit.data;
1007
1003
  visitType = visitText[lastTokenIndex++];
1008
- visitScope = scopeLookup[+nextToken(
1004
+ visitScope = getScope(nextToken(
1009
1005
  /* read scope id */
1010
- )] ||= {
1011
- ["#Id" /* Id */]: +lastToken
1012
- };
1006
+ ));
1013
1007
  if (visitType === "*" /* Node */) {
1014
1008
  visitScope["Getter:" /* Getter */ + nextToken()] = /* @__PURE__ */ ((node) => () => node)(visitScope[lastToken] = visit.previousSibling);
1015
1009
  } else if (branchesEnabled) {
@@ -2204,6 +2198,7 @@ function loop(forEach) {
2204
2198
  scope,
2205
2199
  parentNode
2206
2200
  );
2201
+ branch["#LoopKey" /* LoopKey */] = key;
2207
2202
  params?.(branch, args);
2208
2203
  newScopesByKey.set(key, branch);
2209
2204
  newScopes.push(branch);
@@ -775,6 +775,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
775
775
  const render = resumeRender[renderId] = renders2[renderId] || renders2(renderId);
776
776
  const walk2 = render.w;
777
777
  const scopeLookup = render.s = {};
778
+ const getScope = (id) => scopeLookup[id] ||= { ["#Id" /* Id */]: +id };
778
779
  const serializeContext = {
779
780
  _: registeredValues
780
781
  };
@@ -794,9 +795,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
794
795
  }
795
796
  while (branchId = +lastToken) {
796
797
  (endedBranches ||= []).push(
797
- branch = scopeLookup[branchId] ||= {
798
- ["#Id" /* Id */]: branchId
799
- }
798
+ branch = getScope(branchId)
800
799
  );
801
800
  setParentBranch(branch, branch["#ClosestBranch" /* ClosestBranch */]);
802
801
  if (branch["#AwaitCounter" /* AwaitCounter */] = render.p?.[branchId]) {
@@ -869,12 +868,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
869
868
  if (/\D/.test(lastToken)) {
870
869
  lastEffect = registeredValues[lastToken];
871
870
  } else {
872
- effects.push(
873
- lastEffect,
874
- scopeLookup[lastToken] ||= {
875
- ["#Id" /* Id */]: +lastToken
876
- }
877
- );
871
+ effects.push(lastEffect, getScope(lastToken));
878
872
  }
879
873
  }
880
874
  } else {
@@ -889,7 +883,9 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
889
883
  scopeLookup[scope["#Id" /* Id */] = ++lastScopeId] = scope;
890
884
  scope["$global" /* Global */] = $global;
891
885
  if (branchesEnabled) {
892
- scope["#ClosestBranch" /* ClosestBranch */] = scopeLookup[scope["#ClosestBranchId" /* ClosestBranchId */]];
886
+ scope["#ClosestBranch" /* ClosestBranch */] = getScope(
887
+ scope["#ClosestBranchId" /* ClosestBranchId */]
888
+ );
893
889
  }
894
890
  }
895
891
  }
@@ -899,11 +895,9 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
899
895
  lastTokenIndex = render.i.length;
900
896
  visitText = visit.data;
901
897
  visitType = visitText[lastTokenIndex++];
902
- visitScope = scopeLookup[+nextToken(
898
+ visitScope = getScope(nextToken(
903
899
  /* read scope id */
904
- )] ||= {
905
- ["#Id" /* Id */]: +lastToken
906
- };
900
+ ));
907
901
  if (visitType === "*" /* Node */) {
908
902
  visitScope["Getter:" /* Getter */ + nextToken()] = /* @__PURE__ */ ((node) => () => node)(visitScope[lastToken] = visit.previousSibling);
909
903
  } else if (branchesEnabled) {
@@ -2098,6 +2092,7 @@ function loop(forEach) {
2098
2092
  scope,
2099
2093
  parentNode
2100
2094
  );
2095
+ branch["#LoopKey" /* LoopKey */] = key;
2101
2096
  params?.(branch, args);
2102
2097
  newScopesByKey.set(key, branch);
2103
2098
  newScopes.push(branch);
@@ -1773,6 +1773,7 @@ var $chunk;
1773
1773
  var NOOP = () => {
1774
1774
  };
1775
1775
  var K_SCOPE_ID = Symbol("Scope ID");
1776
+ var K_SCOPE_REFERENCED = Symbol("Scope Referenced");
1776
1777
  function getChunk() {
1777
1778
  return $chunk;
1778
1779
  }
@@ -1927,7 +1928,8 @@ function withIsAsync(cb, value) {
1927
1928
  }
1928
1929
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1929
1930
  const { state } = $chunk.boundary;
1930
- const resumeMarker = serializeMarker !== 0;
1931
+ const resumeKeys = serializeMarker !== 0;
1932
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1931
1933
  let flushBranchIds = "";
1932
1934
  if (serializeBranch !== 0) {
1933
1935
  let loopScopes;
@@ -1960,12 +1962,12 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1960
1962
  }
1961
1963
  withBranchId(branchId, () => {
1962
1964
  cb(item, index);
1963
- if (resumeMarker) {
1964
- writeScope(branchId, {
1965
- ["#LoopKey" /* LoopKey */]: item === index ? void 0 : itemKey
1966
- });
1967
- } else {
1968
- loopScopes = push(loopScopes, writeScope(branchId, {}));
1965
+ const branchScope = writeScope(branchId, {});
1966
+ if (resumeKeys && itemKey !== index) {
1967
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
1968
+ }
1969
+ if (!resumeMarker) {
1970
+ loopScopes = push(loopScopes, referenceScope(branchScope));
1969
1971
  }
1970
1972
  });
1971
1973
  });
@@ -1981,7 +1983,7 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1981
1983
  scopeId,
1982
1984
  accessor,
1983
1985
  serializeStateful,
1984
- resumeMarker,
1986
+ serializeMarker,
1985
1987
  parentEndTag,
1986
1988
  singleNode,
1987
1989
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -1989,7 +1991,8 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1989
1991
  }
1990
1992
  function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1991
1993
  const { state } = $chunk.boundary;
1992
- const resumeMarker = serializeMarker !== 0;
1994
+ const resumeKeys = serializeMarker !== 0;
1995
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1993
1996
  let flushBranchIds = "";
1994
1997
  if (serializeBranch !== 0) {
1995
1998
  let loopScopes;
@@ -2022,12 +2025,12 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
2022
2025
  }
2023
2026
  withBranchId(branchId, () => {
2024
2027
  cb(key, value);
2025
- if (resumeMarker) {
2026
- writeScope(branchId, {
2027
- ["#LoopKey" /* LoopKey */]: itemKey
2028
- });
2029
- } else {
2030
- loopScopes = push(loopScopes, writeScope(branchId, {}));
2028
+ const branchScope = writeScope(branchId, {});
2029
+ if (resumeKeys) {
2030
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
2031
+ }
2032
+ if (!resumeMarker) {
2033
+ loopScopes = push(loopScopes, referenceScope(branchScope));
2031
2034
  }
2032
2035
  });
2033
2036
  });
@@ -2043,7 +2046,7 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
2043
2046
  scopeId,
2044
2047
  accessor,
2045
2048
  serializeStateful,
2046
- resumeMarker,
2049
+ serializeMarker,
2047
2050
  parentEndTag,
2048
2051
  singleNode,
2049
2052
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -2051,7 +2054,8 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
2051
2054
  }
2052
2055
  function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2053
2056
  const { state } = $chunk.boundary;
2054
- const resumeMarker = serializeMarker !== 0;
2057
+ const resumeKeys = serializeMarker !== 0;
2058
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
2055
2059
  let flushBranchIds = "";
2056
2060
  if (serializeBranch !== 0) {
2057
2061
  let loopScopes;
@@ -2084,12 +2088,12 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
2084
2088
  }
2085
2089
  withBranchId(branchId, () => {
2086
2090
  cb(i);
2087
- if (resumeMarker) {
2088
- writeScope(branchId, {
2089
- ["#LoopKey" /* LoopKey */]: itemKey === i ? void 0 : itemKey
2090
- });
2091
- } else {
2092
- loopScopes = push(loopScopes, writeScope(branchId, {}));
2091
+ const branchScope = writeScope(branchId, {});
2092
+ if (resumeKeys && itemKey !== i) {
2093
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
2094
+ }
2095
+ if (!resumeMarker) {
2096
+ loopScopes = push(loopScopes, referenceScope(branchScope));
2093
2097
  }
2094
2098
  });
2095
2099
  });
@@ -2105,7 +2109,7 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
2105
2109
  scopeId,
2106
2110
  accessor,
2107
2111
  serializeStateful,
2108
- resumeMarker,
2112
+ serializeMarker,
2109
2113
  parentEndTag,
2110
2114
  singleNode,
2111
2115
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -2113,7 +2117,8 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
2113
2117
  }
2114
2118
  function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2115
2119
  const { state } = $chunk.boundary;
2116
- const resumeMarker = serializeMarker !== 0;
2120
+ const resumeKeys = serializeMarker !== 0;
2121
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
2117
2122
  let flushBranchIds = "";
2118
2123
  if (serializeBranch !== 0) {
2119
2124
  let loopScopes;
@@ -2146,12 +2151,12 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
2146
2151
  }
2147
2152
  withBranchId(branchId, () => {
2148
2153
  cb(i);
2149
- if (resumeMarker) {
2150
- writeScope(branchId, {
2151
- ["#LoopKey" /* LoopKey */]: itemKey === i ? void 0 : itemKey
2152
- });
2153
- } else {
2154
- loopScopes = push(loopScopes, writeScope(branchId, {}));
2154
+ const branchScope = writeScope(branchId, {});
2155
+ if (resumeKeys && itemKey !== i) {
2156
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
2157
+ }
2158
+ if (!resumeMarker) {
2159
+ loopScopes = push(loopScopes, referenceScope(branchScope));
2155
2160
  }
2156
2161
  });
2157
2162
  });
@@ -2167,7 +2172,7 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
2167
2172
  scopeId,
2168
2173
  accessor,
2169
2174
  serializeStateful,
2170
- resumeMarker,
2175
+ serializeMarker,
2171
2176
  parentEndTag,
2172
2177
  singleNode,
2173
2178
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -2176,7 +2181,7 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
2176
2181
  function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2177
2182
  const { state } = $chunk.boundary;
2178
2183
  const resumeBranch = serializeBranch !== 0;
2179
- const resumeMarker = serializeMarker !== 0;
2184
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
2180
2185
  const branchId = _peek_scope_id();
2181
2186
  if (resumeMarker && resumeBranch && !singleNode) {
2182
2187
  $chunk.writeHTML(state.mark("[" /* BranchStart */, ""));
@@ -2190,22 +2195,22 @@ function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeS
2190
2195
  // It may make sense to pass in another arg for this.
2191
2196
  ["ConditionalRenderer:" /* ConditionalRenderer */ + accessor]: branchIndex || void 0,
2192
2197
  // we convert 0 to undefined since the runtime defaults branch to 0.
2193
- ["BranchScopes:" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
2198
+ ["BranchScopes:" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : referenceScope(writeScope(branchId, {}))
2194
2199
  });
2195
2200
  }
2196
2201
  writeBranchEnd(
2197
2202
  scopeId,
2198
2203
  accessor,
2199
2204
  serializeStateful,
2200
- resumeMarker,
2205
+ serializeMarker,
2201
2206
  parentEndTag,
2202
2207
  singleNode,
2203
2208
  shouldWriteBranch ? " " + branchId : ""
2204
2209
  );
2205
2210
  }
2206
- function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, parentEndTag, singleNode, branchIds) {
2211
+ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
2207
2212
  const endTag = parentEndTag || "";
2208
- if (resumeMarker) {
2213
+ if (serializeMarker !== 0) {
2209
2214
  if (!parentEndTag || serializeStateful !== 0) {
2210
2215
  const { state } = $chunk.boundary;
2211
2216
  const mark = singleNode ? state.mark(
@@ -2223,6 +2228,13 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, pare
2223
2228
  $chunk.writeHTML(endTag);
2224
2229
  }
2225
2230
  }
2231
+ function scopeHasReference(scope) {
2232
+ return !!scope[K_SCOPE_REFERENCED];
2233
+ }
2234
+ function referenceScope(scope) {
2235
+ scope[K_SCOPE_REFERENCED] = 1;
2236
+ return scope;
2237
+ }
2226
2238
  var writeScope = (scopeId, partialScope) => {
2227
2239
  return writeScopeToState($chunk.boundary.state, scopeId, partialScope);
2228
2240
  };
@@ -2263,7 +2275,7 @@ function _scope_with_id(scopeId) {
2263
2275
  scope = { [K_SCOPE_ID]: scopeId };
2264
2276
  state.scopes.set(scopeId, scope);
2265
2277
  }
2266
- return scope;
2278
+ return referenceScope(scope);
2267
2279
  }
2268
2280
  function $global() {
2269
2281
  return $chunk.boundary.state.$global;
@@ -2755,24 +2767,31 @@ function flushSerializer(boundary) {
2755
2767
  const { writeScopes, serializer } = state;
2756
2768
  const { flushed } = serializer;
2757
2769
  if (writeScopes || flushed) {
2770
+ let shouldSerialize = false;
2758
2771
  const serializeData = [];
2759
2772
  let { lastSerializedScopeId } = state;
2760
2773
  if (!state.hasGlobals) {
2761
2774
  state.hasGlobals = true;
2762
2775
  serializeData.push(getFilteredGlobals(state.$global));
2776
+ shouldSerialize = true;
2763
2777
  }
2764
2778
  for (const key in writeScopes) {
2765
2779
  const scope = writeScopes[key];
2766
- const scopeId = getScopeId(scope);
2767
- const scopeIdDelta = scopeId - lastSerializedScopeId;
2768
- lastSerializedScopeId = scopeId + 1;
2769
- if (scopeIdDelta) serializeData.push(scopeIdDelta);
2770
- serializeData.push(scope);
2771
- }
2772
- state.resumes = concatSequence(
2773
- state.resumes,
2774
- serializer.stringify(serializeData, boundary)
2775
- );
2780
+ if (scopeHasReference(scope) || Object.getOwnPropertyNames(scope).length) {
2781
+ const scopeId = getScopeId(scope);
2782
+ const scopeIdDelta = scopeId - lastSerializedScopeId;
2783
+ lastSerializedScopeId = scopeId + 1;
2784
+ if (scopeIdDelta) serializeData.push(scopeIdDelta);
2785
+ serializeData.push(scope);
2786
+ shouldSerialize = true;
2787
+ }
2788
+ }
2789
+ if (shouldSerialize) {
2790
+ state.resumes = concatSequence(
2791
+ state.resumes,
2792
+ serializer.stringify(serializeData, boundary)
2793
+ );
2794
+ }
2776
2795
  state.lastSerializedScopeId = lastSerializedScopeId;
2777
2796
  state.writeScopes = null;
2778
2797
  if (flushed) {
@@ -2849,7 +2868,7 @@ function getFilteredGlobals($global2) {
2849
2868
  }
2850
2869
  function _subscribe(subscribers, scope) {
2851
2870
  $chunk.boundary.state.serializer.writeCall(scope, subscribers, "add");
2852
- return scope;
2871
+ return referenceScope(scope);
2853
2872
  }
2854
2873
 
2855
2874
  // src/html/attrs.ts
@@ -1680,6 +1680,7 @@ var $chunk;
1680
1680
  var NOOP = () => {
1681
1681
  };
1682
1682
  var K_SCOPE_ID = Symbol("Scope ID");
1683
+ var K_SCOPE_REFERENCED = Symbol("Scope Referenced");
1683
1684
  function getChunk() {
1684
1685
  return $chunk;
1685
1686
  }
@@ -1834,7 +1835,8 @@ function withIsAsync(cb, value) {
1834
1835
  }
1835
1836
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1836
1837
  const { state } = $chunk.boundary;
1837
- const resumeMarker = serializeMarker !== 0;
1838
+ const resumeKeys = serializeMarker !== 0;
1839
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1838
1840
  let flushBranchIds = "";
1839
1841
  if (serializeBranch !== 0) {
1840
1842
  let loopScopes;
@@ -1867,12 +1869,12 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1867
1869
  }
1868
1870
  withBranchId(branchId, () => {
1869
1871
  cb(item, index);
1870
- if (resumeMarker) {
1871
- writeScope(branchId, {
1872
- ["#LoopKey" /* LoopKey */]: item === index ? void 0 : itemKey
1873
- });
1874
- } else {
1875
- loopScopes = push(loopScopes, writeScope(branchId, {}));
1872
+ const branchScope = writeScope(branchId, {});
1873
+ if (resumeKeys && itemKey !== index) {
1874
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
1875
+ }
1876
+ if (!resumeMarker) {
1877
+ loopScopes = push(loopScopes, referenceScope(branchScope));
1876
1878
  }
1877
1879
  });
1878
1880
  });
@@ -1888,7 +1890,7 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1888
1890
  scopeId,
1889
1891
  accessor,
1890
1892
  serializeStateful,
1891
- resumeMarker,
1893
+ serializeMarker,
1892
1894
  parentEndTag,
1893
1895
  singleNode,
1894
1896
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -1896,7 +1898,8 @@ function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMark
1896
1898
  }
1897
1899
  function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1898
1900
  const { state } = $chunk.boundary;
1899
- const resumeMarker = serializeMarker !== 0;
1901
+ const resumeKeys = serializeMarker !== 0;
1902
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1900
1903
  let flushBranchIds = "";
1901
1904
  if (serializeBranch !== 0) {
1902
1905
  let loopScopes;
@@ -1929,12 +1932,12 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
1929
1932
  }
1930
1933
  withBranchId(branchId, () => {
1931
1934
  cb(key, value);
1932
- if (resumeMarker) {
1933
- writeScope(branchId, {
1934
- ["#LoopKey" /* LoopKey */]: itemKey
1935
- });
1936
- } else {
1937
- loopScopes = push(loopScopes, writeScope(branchId, {}));
1935
+ const branchScope = writeScope(branchId, {});
1936
+ if (resumeKeys) {
1937
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
1938
+ }
1939
+ if (!resumeMarker) {
1940
+ loopScopes = push(loopScopes, referenceScope(branchScope));
1938
1941
  }
1939
1942
  });
1940
1943
  });
@@ -1950,7 +1953,7 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
1950
1953
  scopeId,
1951
1954
  accessor,
1952
1955
  serializeStateful,
1953
- resumeMarker,
1956
+ serializeMarker,
1954
1957
  parentEndTag,
1955
1958
  singleNode,
1956
1959
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -1958,7 +1961,8 @@ function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarke
1958
1961
  }
1959
1962
  function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1960
1963
  const { state } = $chunk.boundary;
1961
- const resumeMarker = serializeMarker !== 0;
1964
+ const resumeKeys = serializeMarker !== 0;
1965
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1962
1966
  let flushBranchIds = "";
1963
1967
  if (serializeBranch !== 0) {
1964
1968
  let loopScopes;
@@ -1991,12 +1995,12 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
1991
1995
  }
1992
1996
  withBranchId(branchId, () => {
1993
1997
  cb(i);
1994
- if (resumeMarker) {
1995
- writeScope(branchId, {
1996
- ["#LoopKey" /* LoopKey */]: itemKey === i ? void 0 : itemKey
1997
- });
1998
- } else {
1999
- loopScopes = push(loopScopes, writeScope(branchId, {}));
1998
+ const branchScope = writeScope(branchId, {});
1999
+ if (resumeKeys && itemKey !== i) {
2000
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
2001
+ }
2002
+ if (!resumeMarker) {
2003
+ loopScopes = push(loopScopes, referenceScope(branchScope));
2000
2004
  }
2001
2005
  });
2002
2006
  });
@@ -2012,7 +2016,7 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
2012
2016
  scopeId,
2013
2017
  accessor,
2014
2018
  serializeStateful,
2015
- resumeMarker,
2019
+ serializeMarker,
2016
2020
  parentEndTag,
2017
2021
  singleNode,
2018
2022
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -2020,7 +2024,8 @@ function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, ser
2020
2024
  }
2021
2025
  function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2022
2026
  const { state } = $chunk.boundary;
2023
- const resumeMarker = serializeMarker !== 0;
2027
+ const resumeKeys = serializeMarker !== 0;
2028
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
2024
2029
  let flushBranchIds = "";
2025
2030
  if (serializeBranch !== 0) {
2026
2031
  let loopScopes;
@@ -2053,12 +2058,12 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
2053
2058
  }
2054
2059
  withBranchId(branchId, () => {
2055
2060
  cb(i);
2056
- if (resumeMarker) {
2057
- writeScope(branchId, {
2058
- ["#LoopKey" /* LoopKey */]: itemKey === i ? void 0 : itemKey
2059
- });
2060
- } else {
2061
- loopScopes = push(loopScopes, writeScope(branchId, {}));
2061
+ const branchScope = writeScope(branchId, {});
2062
+ if (resumeKeys && itemKey !== i) {
2063
+ branchScope["#LoopKey" /* LoopKey */] = itemKey;
2064
+ }
2065
+ if (!resumeMarker) {
2066
+ loopScopes = push(loopScopes, referenceScope(branchScope));
2062
2067
  }
2063
2068
  });
2064
2069
  });
@@ -2074,7 +2079,7 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
2074
2079
  scopeId,
2075
2080
  accessor,
2076
2081
  serializeStateful,
2077
- resumeMarker,
2082
+ serializeMarker,
2078
2083
  parentEndTag,
2079
2084
  singleNode,
2080
2085
  singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : ""
@@ -2083,7 +2088,7 @@ function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch,
2083
2088
  function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2084
2089
  const { state } = $chunk.boundary;
2085
2090
  const resumeBranch = serializeBranch !== 0;
2086
- const resumeMarker = serializeMarker !== 0;
2091
+ const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
2087
2092
  const branchId = _peek_scope_id();
2088
2093
  if (resumeMarker && resumeBranch && !singleNode) {
2089
2094
  $chunk.writeHTML(state.mark("[" /* BranchStart */, ""));
@@ -2097,22 +2102,22 @@ function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeS
2097
2102
  // It may make sense to pass in another arg for this.
2098
2103
  ["ConditionalRenderer:" /* ConditionalRenderer */ + accessor]: branchIndex || void 0,
2099
2104
  // we convert 0 to undefined since the runtime defaults branch to 0.
2100
- ["BranchScopes:" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
2105
+ ["BranchScopes:" /* BranchScopes */ + accessor]: resumeMarker ? void 0 : referenceScope(writeScope(branchId, {}))
2101
2106
  });
2102
2107
  }
2103
2108
  writeBranchEnd(
2104
2109
  scopeId,
2105
2110
  accessor,
2106
2111
  serializeStateful,
2107
- resumeMarker,
2112
+ serializeMarker,
2108
2113
  parentEndTag,
2109
2114
  singleNode,
2110
2115
  shouldWriteBranch ? " " + branchId : ""
2111
2116
  );
2112
2117
  }
2113
- function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, parentEndTag, singleNode, branchIds) {
2118
+ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
2114
2119
  const endTag = parentEndTag || "";
2115
- if (resumeMarker) {
2120
+ if (serializeMarker !== 0) {
2116
2121
  if (!parentEndTag || serializeStateful !== 0) {
2117
2122
  const { state } = $chunk.boundary;
2118
2123
  const mark = singleNode ? state.mark(
@@ -2130,6 +2135,13 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, resumeMarker, pare
2130
2135
  $chunk.writeHTML(endTag);
2131
2136
  }
2132
2137
  }
2138
+ function scopeHasReference(scope) {
2139
+ return !!scope[K_SCOPE_REFERENCED];
2140
+ }
2141
+ function referenceScope(scope) {
2142
+ scope[K_SCOPE_REFERENCED] = 1;
2143
+ return scope;
2144
+ }
2133
2145
  var writeScope = (scopeId, partialScope) => {
2134
2146
  return writeScopeToState($chunk.boundary.state, scopeId, partialScope);
2135
2147
  };
@@ -2170,7 +2182,7 @@ function _scope_with_id(scopeId) {
2170
2182
  scope = { [K_SCOPE_ID]: scopeId };
2171
2183
  state.scopes.set(scopeId, scope);
2172
2184
  }
2173
- return scope;
2185
+ return referenceScope(scope);
2174
2186
  }
2175
2187
  function $global() {
2176
2188
  return $chunk.boundary.state.$global;
@@ -2662,24 +2674,31 @@ function flushSerializer(boundary) {
2662
2674
  const { writeScopes, serializer } = state;
2663
2675
  const { flushed } = serializer;
2664
2676
  if (writeScopes || flushed) {
2677
+ let shouldSerialize = false;
2665
2678
  const serializeData = [];
2666
2679
  let { lastSerializedScopeId } = state;
2667
2680
  if (!state.hasGlobals) {
2668
2681
  state.hasGlobals = true;
2669
2682
  serializeData.push(getFilteredGlobals(state.$global));
2683
+ shouldSerialize = true;
2670
2684
  }
2671
2685
  for (const key in writeScopes) {
2672
2686
  const scope = writeScopes[key];
2673
- const scopeId = getScopeId(scope);
2674
- const scopeIdDelta = scopeId - lastSerializedScopeId;
2675
- lastSerializedScopeId = scopeId + 1;
2676
- if (scopeIdDelta) serializeData.push(scopeIdDelta);
2677
- serializeData.push(scope);
2678
- }
2679
- state.resumes = concatSequence(
2680
- state.resumes,
2681
- serializer.stringify(serializeData, boundary)
2682
- );
2687
+ if (scopeHasReference(scope) || Object.getOwnPropertyNames(scope).length) {
2688
+ const scopeId = getScopeId(scope);
2689
+ const scopeIdDelta = scopeId - lastSerializedScopeId;
2690
+ lastSerializedScopeId = scopeId + 1;
2691
+ if (scopeIdDelta) serializeData.push(scopeIdDelta);
2692
+ serializeData.push(scope);
2693
+ shouldSerialize = true;
2694
+ }
2695
+ }
2696
+ if (shouldSerialize) {
2697
+ state.resumes = concatSequence(
2698
+ state.resumes,
2699
+ serializer.stringify(serializeData, boundary)
2700
+ );
2701
+ }
2683
2702
  state.lastSerializedScopeId = lastSerializedScopeId;
2684
2703
  state.writeScopes = null;
2685
2704
  if (flushed) {
@@ -2756,7 +2775,7 @@ function getFilteredGlobals($global2) {
2756
2775
  }
2757
2776
  function _subscribe(subscribers, scope) {
2758
2777
  $chunk.boundary.state.serializer.writeCall(scope, subscribers, "add");
2759
- return scope;
2778
+ return referenceScope(scope);
2760
2779
  }
2761
2780
 
2762
2781
  // src/html/attrs.ts