ripple 0.3.127 → 0.4.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.
Files changed (192) hide show
  1. package/CHANGELOG.md +293 -0
  2. package/package.json +10 -4
  3. package/src/runtime/element.js +23 -6
  4. package/src/runtime/index-client.js +81 -41
  5. package/src/runtime/index-server.js +1 -0
  6. package/src/runtime/internal/client/blocks.js +192 -114
  7. package/src/runtime/internal/client/component.js +4 -30
  8. package/src/runtime/internal/client/composite.js +12 -13
  9. package/src/runtime/internal/client/constants.js +14 -5
  10. package/src/runtime/internal/client/context.js +12 -19
  11. package/src/runtime/internal/client/css.js +7 -9
  12. package/src/runtime/internal/client/events.js +178 -90
  13. package/src/runtime/internal/client/expression.js +185 -124
  14. package/src/runtime/internal/client/for.js +616 -264
  15. package/src/runtime/internal/client/head.js +10 -5
  16. package/src/runtime/internal/client/html.js +1 -0
  17. package/src/runtime/internal/client/hydration.js +152 -10
  18. package/src/runtime/internal/client/if.js +239 -50
  19. package/src/runtime/internal/client/index.js +9 -13
  20. package/src/runtime/internal/client/operations.js +44 -51
  21. package/src/runtime/internal/client/portal.js +163 -85
  22. package/src/runtime/internal/client/render.js +44 -25
  23. package/src/runtime/internal/client/rpc.js +3 -3
  24. package/src/runtime/internal/client/runtime.js +799 -576
  25. package/src/runtime/internal/client/selector.js +77 -0
  26. package/src/runtime/internal/client/template.js +133 -158
  27. package/src/runtime/internal/client/transport.js +38 -0
  28. package/src/runtime/internal/client/try.js +465 -426
  29. package/src/runtime/internal/client/types.d.ts +65 -21
  30. package/src/runtime/internal/client/utils.js +1 -3
  31. package/src/runtime/internal/server/dynamic.js +20 -21
  32. package/src/runtime/internal/server/index.js +327 -275
  33. package/src/runtime/internal/server/rpc.js +3 -2
  34. package/src/runtime/internal/server/transport.js +16 -0
  35. package/src/runtime/transport.js +21 -0
  36. package/tests/client/__snapshots__/for.test.tsrx.snap +0 -5
  37. package/tests/client/array/array.copy-within.test.tsrx +12 -12
  38. package/tests/client/array/array.derived.test.tsrx +46 -46
  39. package/tests/client/array/array.iteration.test.tsrx +10 -10
  40. package/tests/client/array/array.mutations.test.tsrx +20 -20
  41. package/tests/client/array/array.static.test.tsrx +11 -11
  42. package/tests/client/array/array.to-methods.test.tsrx +6 -6
  43. package/tests/client/async-suspend.test.tsrx +74 -75
  44. package/tests/client/basic/basic.attributes.test.tsrx +86 -83
  45. package/tests/client/basic/basic.collections.test.tsrx +12 -12
  46. package/tests/client/basic/basic.components.test.tsrx +99 -25
  47. package/tests/client/basic/basic.errors.test.tsrx +18 -18
  48. package/tests/client/basic/basic.events.test.tsrx +42 -42
  49. package/tests/client/basic/basic.get-set.test.tsrx +8 -8
  50. package/tests/client/basic/basic.reactivity.test.tsrx +97 -29
  51. package/tests/client/basic/basic.rendering.test.tsrx +25 -25
  52. package/tests/client/basic/basic.utilities.test.tsrx +3 -3
  53. package/tests/client/boundaries.test.tsrx +8 -8
  54. package/tests/client/boxed-locals.test.tsrx +452 -0
  55. package/tests/client/compiler/__snapshots__/compiler.assignments.test.tsrx.snap +6 -6
  56. package/tests/client/compiler/compiler.assignments.test.tsrx +9 -73
  57. package/tests/client/compiler/compiler.attributes.test.tsrx +23 -23
  58. package/tests/client/compiler/compiler.basic.test.tsrx +15 -60
  59. package/tests/client/compiler/compiler.tracked-access.test.tsrx +18 -43
  60. package/tests/client/compiler/compiler.try-in-function.test.tsrx +2 -2
  61. package/tests/client/composite/__snapshots__/composite.render.test.tsrx.snap +0 -1
  62. package/tests/client/composite/composite.dynamic-components.test.tsrx +77 -6
  63. package/tests/client/composite/composite.props.test.tsrx +149 -12
  64. package/tests/client/composite/composite.reactivity.test.tsrx +51 -52
  65. package/tests/client/composite/composite.render.test.tsrx +26 -9
  66. package/tests/client/css/scoped-styles.test.tsrx +8 -8
  67. package/tests/client/date.test.tsrx +42 -42
  68. package/tests/client/derived-release.test.tsrx +370 -0
  69. package/tests/client/dynamic-elements.test.tsrx +45 -45
  70. package/tests/client/events.test.tsrx +97 -71
  71. package/tests/client/for-selector.test.tsrx +221 -0
  72. package/tests/client/for-single-root-items.test.tsrx +118 -3
  73. package/tests/client/for.test.tsrx +332 -31
  74. package/tests/client/head.test.tsrx +19 -19
  75. package/tests/client/html.test.tsrx +11 -9
  76. package/tests/client/if-block.test.tsrx +80 -0
  77. package/tests/client/map.test.tsrx +16 -16
  78. package/tests/client/media-query.test.tsrx +7 -7
  79. package/tests/client/portal.test.tsrx +224 -26
  80. package/tests/client/primitive-text.test.tsrx +50 -0
  81. package/tests/client/prop-kind-switch.test.tsrx +141 -0
  82. package/tests/client/ref.test.tsrx +17 -17
  83. package/tests/client/return.test.tsrx +26 -3
  84. package/tests/client/root-boundary.test.tsrx +42 -0
  85. package/tests/client/scoped-flush.test.tsrx +8 -8
  86. package/tests/client/set.test.tsrx +6 -6
  87. package/tests/client/svg.test.tsrx +11 -11
  88. package/tests/client/switch.test.tsrx +44 -44
  89. package/tests/client/track-async-hydration.test.tsrx +4 -4
  90. package/tests/client/try.test.tsrx +151 -83
  91. package/tests/client/tsx.test.tsrx +43 -40
  92. package/tests/client/url/url.derived.test.tsrx +6 -6
  93. package/tests/client/url-search-params/url-search-params.derived.test.tsrx +8 -8
  94. package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +10 -10
  95. package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +10 -10
  96. package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +18 -18
  97. package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +2 -2
  98. package/tests/hydration/basic.test.js +74 -1
  99. package/tests/hydration/build-components.js +22 -1
  100. package/tests/hydration/compiled/client/basic.js +1142 -713
  101. package/tests/hydration/compiled/client/composite.js +151 -100
  102. package/tests/hydration/compiled/client/events.js +190 -150
  103. package/tests/hydration/compiled/client/for.js +1472 -1126
  104. package/tests/hydration/compiled/client/fragment-cursor.js +2341 -0
  105. package/tests/hydration/compiled/client/head.js +255 -199
  106. package/tests/hydration/compiled/client/hmr.js +54 -41
  107. package/tests/hydration/compiled/client/html-in-template.js +54 -39
  108. package/tests/hydration/compiled/client/html.js +1633 -1263
  109. package/tests/hydration/compiled/client/if-children.js +420 -270
  110. package/tests/hydration/compiled/client/if-fragment-controlflow.js +363 -317
  111. package/tests/hydration/compiled/client/if.js +229 -219
  112. package/tests/hydration/compiled/client/mixed-control-flow.js +420 -400
  113. package/tests/hydration/compiled/client/nested-control-flow.js +1326 -1255
  114. package/tests/hydration/compiled/client/portal.js +87 -95
  115. package/tests/hydration/compiled/client/reactivity.js +140 -83
  116. package/tests/hydration/compiled/client/return.js +28 -19
  117. package/tests/hydration/compiled/client/streaming.js +390 -306
  118. package/tests/hydration/compiled/client/switch.js +258 -266
  119. package/tests/hydration/compiled/client/track-async-serialization.js +448 -280
  120. package/tests/hydration/compiled/client/try.js +173 -129
  121. package/tests/hydration/compiled/client/typed-text.js +71 -0
  122. package/tests/hydration/compiled/fixtures/money.js +10 -0
  123. package/tests/hydration/compiled/server/basic.js +123 -6
  124. package/tests/hydration/compiled/server/composite.js +16 -30
  125. package/tests/hydration/compiled/server/events.js +19 -19
  126. package/tests/hydration/compiled/server/for.js +109 -49
  127. package/tests/hydration/compiled/server/fragment-cursor.js +1687 -0
  128. package/tests/hydration/compiled/server/head.js +20 -28
  129. package/tests/hydration/compiled/server/hmr.js +2 -2
  130. package/tests/hydration/compiled/server/html.js +71 -247
  131. package/tests/hydration/compiled/server/if-children.js +107 -15
  132. package/tests/hydration/compiled/server/if.js +11 -15
  133. package/tests/hydration/compiled/server/mixed-control-flow.js +8 -8
  134. package/tests/hydration/compiled/server/portal.js +14 -22
  135. package/tests/hydration/compiled/server/reactivity.js +14 -46
  136. package/tests/hydration/compiled/server/streaming.js +19 -19
  137. package/tests/hydration/compiled/server/switch.js +8 -8
  138. package/tests/hydration/compiled/server/track-async-serialization.js +150 -23
  139. package/tests/hydration/compiled/server/try.js +8 -8
  140. package/tests/hydration/compiled/server/typed-text.js +17 -0
  141. package/tests/hydration/components/basic.tsrx +44 -8
  142. package/tests/hydration/components/composite.tsrx +2 -2
  143. package/tests/hydration/components/events.tsrx +25 -25
  144. package/tests/hydration/components/for.tsrx +115 -67
  145. package/tests/hydration/components/fragment-cursor.tsrx +650 -0
  146. package/tests/hydration/components/head.tsrx +16 -16
  147. package/tests/hydration/components/hmr.tsrx +2 -2
  148. package/tests/hydration/components/html.tsrx +7 -7
  149. package/tests/hydration/components/if-children.tsrx +72 -25
  150. package/tests/hydration/components/if.tsrx +18 -18
  151. package/tests/hydration/components/mixed-control-flow.tsrx +11 -11
  152. package/tests/hydration/components/portal.tsrx +3 -3
  153. package/tests/hydration/components/reactivity.tsrx +16 -16
  154. package/tests/hydration/components/streaming.tsrx +20 -20
  155. package/tests/hydration/components/switch.tsrx +20 -20
  156. package/tests/hydration/components/text-types.ts +4 -0
  157. package/tests/hydration/components/track-async-serialization.tsrx +80 -26
  158. package/tests/hydration/components/try.tsrx +8 -8
  159. package/tests/hydration/components/typed-text.tsrx +22 -0
  160. package/tests/hydration/fixtures/money.js +10 -0
  161. package/tests/hydration/for.test.js +36 -0
  162. package/tests/hydration/fragment-cursor.test.js +111 -0
  163. package/tests/hydration/if-children.test.js +24 -0
  164. package/tests/hydration/streaming.test.js +19 -0
  165. package/tests/hydration/track-async-serialization.test.js +87 -2
  166. package/tests/hydration/tsconfig.text-types.json +10 -0
  167. package/tests/hydration/typed-text.test.js +34 -0
  168. package/tests/server/await.test.tsrx +3 -3
  169. package/tests/server/basic.attributes.test.tsrx +42 -42
  170. package/tests/server/basic.components.test.tsrx +64 -8
  171. package/tests/server/basic.test.tsrx +34 -32
  172. package/tests/server/compiler.test.tsrx +1 -70
  173. package/tests/server/composite.props.test.tsrx +6 -6
  174. package/tests/server/dynamic-elements.test.tsrx +31 -8
  175. package/tests/server/for.test.tsrx +94 -0
  176. package/tests/server/head.test.tsrx +11 -11
  177. package/tests/server/scoped-styles.test.tsrx +2 -2
  178. package/tests/server/streaming-ssr.test.tsrx +48 -43
  179. package/tests/server/track-async-serialization.test.tsrx +204 -21
  180. package/tests/server/try.test.tsrx +48 -48
  181. package/tests/types/transport.ts +40 -0
  182. package/tests/utils/vite-plugin-config.test.js +23 -0
  183. package/types/index.d.ts +48 -7
  184. package/types/server.d.ts +3 -0
  185. package/types/transport.d.ts +15 -0
  186. package/src/runtime/internal/client/switch.js +0 -113
  187. package/src/utils/errors.js +0 -13
  188. package/tests/client/lazy-array.test.tsrx +0 -31
  189. package/tests/client/lazy-destructuring.test.tsrx +0 -438
  190. package/tests/client/tracked-index-access.test.tsrx +0 -113
  191. package/tests/server/lazy-destructuring.test.tsrx +0 -595
  192. package/tests/server/tracked-index-access.test.tsrx +0 -76
@@ -1,23 +1,24 @@
1
- /** @import { Block } from '#client' */
1
+ /** @import { AppendIntoAnchor, Block } from '#client' */
2
2
 
3
3
  import { is_array } from '@tsrx/core/runtime/language-helpers';
4
4
  import { branch, destroy_block, render } from './blocks.js';
5
- import { BRANCH_BLOCK, UNINITIALIZED } from './constants.js';
5
+ import { BRANCH_BLOCK, IF_BLOCK, UNINITIALIZED } from './constants.js';
6
6
  import { create_text, get_next_sibling } from './operations.js';
7
7
  import { assign_nodes } from './template.js';
8
8
  import { active_block } from './runtime.js';
9
9
  import { hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
10
10
  import { COMMENT_NODE, HYDRATION_END, HYDRATION_START, TEXT_NODE } from '../../../constants.js';
11
- import { is_tsrx_element } from '../../element.js';
11
+ import { is_tsrx_element, TSRX_ELEMENT } from '../../element.js';
12
12
 
13
13
  /**
14
- * Finds the nearest enclosing BRANCH_BLOCK in the block hierarchy.
14
+ * Finds the nearest enclosing block that owns a DOM range (a branch or an if
15
+ * block) in the block hierarchy.
15
16
  * @param {Block | null} block
16
17
  * @returns {Block | null}
17
18
  */
18
19
  function find_enclosing_branch(block) {
19
20
  while (block !== null) {
20
- if ((block.f & BRANCH_BLOCK) !== 0) {
21
+ if ((block.f & (BRANCH_BLOCK | IF_BLOCK)) !== 0) {
21
22
  return block;
22
23
  }
23
24
  block = block.p;
@@ -32,13 +33,19 @@ function find_enclosing_branch(block) {
32
33
  * @returns {void}
33
34
  */
34
35
  export function render_value(value, anchor, block) {
35
- if (is_tsrx_element(value)) {
36
- render_tsrx_element(value, anchor, block);
37
- } else if (is_array(value)) {
36
+ // render_tsrx_element, inline: an element's render may return another
37
+ // element (a wrapper), an array, or text.
38
+ var rendered = false;
39
+ // is_tsrx_element, inline: every component render passes through here.
40
+ while (value != null && value[TSRX_ELEMENT] === true) {
41
+ value = value.render(anchor, block, value.p);
42
+ rendered = true;
43
+ }
44
+ if (is_array(value)) {
38
45
  render_tsrx_collection(value, anchor, block);
39
46
  } else if (value != null) {
40
47
  var text = value + '';
41
- if (text !== '') {
48
+ if (rendered || text !== '') {
42
49
  render_tsrx_collection_text(text, anchor, true);
43
50
  }
44
51
  }
@@ -60,11 +67,27 @@ function render_tsrx_collection(value, anchor, block) {
60
67
  var start = document.createComment('');
61
68
  var end = document.createComment('');
62
69
 
63
- anchor.before(start, end);
70
+ insert_before(anchor, start);
71
+ insert_before(anchor, end);
64
72
  assign_nodes(start, end);
65
73
  render_tsrx_collection_items(value, end, block);
66
74
  }
67
75
 
76
+ /**
77
+ * Inserts `node` before `anchor`, or appends it into the parent when `anchor`
78
+ * is an append-into sentinel (see `append_into`).
79
+ * @param {ChildNode | AppendIntoAnchor} anchor
80
+ * @param {Node} node
81
+ * @returns {void}
82
+ */
83
+ function insert_before(anchor, node) {
84
+ if (/** @type {AppendIntoAnchor} */ (anchor).into === true) {
85
+ /** @type {AppendIntoAnchor} */ (anchor).parent.appendChild(node);
86
+ } else {
87
+ /** @type {ChildNode} */ (anchor).before(node);
88
+ }
89
+ }
90
+
68
91
  /**
69
92
  * @param {any[]} value
70
93
  * @param {ChildNode} anchor
@@ -92,7 +115,7 @@ function render_tsrx_collection_items(value, anchor, block) {
92
115
  * @returns {void}
93
116
  */
94
117
  function render_tsrx_element(value, anchor, block) {
95
- var result = value.render(anchor, block);
118
+ var result = value.render(anchor, block, value.p);
96
119
 
97
120
  if (is_tsrx_element(result)) {
98
121
  render_tsrx_element(result, anchor, block);
@@ -112,7 +135,7 @@ function render_tsrx_element(value, anchor, block) {
112
135
  function render_tsrx_collection_text(value, anchor, assign = false) {
113
136
  if (!hydrating) {
114
137
  var text = create_text(value);
115
- anchor.before(text);
138
+ insert_before(anchor, text);
116
139
  if (assign) {
117
140
  assign_nodes(text, text);
118
141
  }
@@ -167,68 +190,99 @@ function render_tsrx_collection_text(value, anchor, assign = false) {
167
190
  set_hydrate_node(node ?? anchor);
168
191
  }
169
192
 
193
+ /**
194
+ * @typedef {{
195
+ * start: Node | null;
196
+ * end: Node | null;
197
+ * a: ChildNode;
198
+ * n: number;
199
+ * g: () => any;
200
+ * b: Block | null;
201
+ * m: Comment | null;
202
+ * t: Text | null;
203
+ * v: string | import('../../element.js').TSRXElement | typeof UNINITIALIZED;
204
+ * e: boolean;
205
+ * i: boolean;
206
+ * p: Block | null;
207
+ * o: Node | null;
208
+ * }} ExpressionState
209
+ */
210
+
170
211
  /**
171
212
  * @param {Node} node
172
213
  * @param {() => any} get_value
173
214
  * @returns {void}
174
215
  */
175
216
  export function expression(node, get_value) {
176
- var anchor = /** @type {ChildNode} */ (node);
177
- /** @type {Block | null} */
178
- var child_block = null;
179
- /** @type {Comment | null} */
180
- var end = null;
181
- /** @type {Text | null} */
182
- var text = null;
183
- /** @type {string | import('../../element.js').TSRXElement | typeof UNINITIALIZED} */
184
- var value = UNINITIALIZED;
185
- var is_element = false;
186
- var initialized = false;
187
- /** @type {Block | null} */
188
- var modified_parent_branch = null;
189
- /** @type {Node | null} */
190
- var original_parent_start = null;
191
-
192
- render(() => {
193
- var next_value = get_value();
217
+ // State lives on the render block instead of a per-expression closure, and
218
+ // the anchor's node type is read once since the anchor never changes.
219
+ render(run_expression, {
220
+ start: null,
221
+ end: null,
222
+ a: /** @type {ChildNode} */ (node),
223
+ n: node.nodeType,
224
+ g: get_value,
225
+ // child block rendering a TSRX element / collection
226
+ b: null,
227
+ // hydration end marker
228
+ m: null,
229
+ // text node inserted before a comment anchor
230
+ t: null,
231
+ // last rendered value
232
+ v: UNINITIALIZED,
233
+ // whether the last value was an element / collection
234
+ e: false,
235
+ // whether the block has rendered once
236
+ i: false,
237
+ // enclosing branch whose start was moved to include element content
238
+ p: null,
239
+ // that branch's original start node
240
+ o: null,
241
+ });
242
+ }
243
+
244
+ /**
245
+ * @param {ExpressionState} s
246
+ * @returns {void}
247
+ */
248
+ function run_expression(s) {
249
+ var next_value = s.g();
250
+ var anchor = s.a;
251
+ var type = typeof next_value;
252
+ var is_hydration_marker =
253
+ hydrating && s.n === COMMENT_NODE && /** @type {Comment} */ (anchor).data === HYDRATION_START;
254
+
255
+ if (is_hydration_marker) {
256
+ s.m ??= ensure_expression_end(anchor);
257
+ }
258
+
259
+ var end = s.m;
260
+
261
+ if (next_value !== null && (type === 'object' || type === 'function')) {
194
262
  var next_is_collection = is_array(next_value);
195
- var next_is_element = next_is_collection || is_tsrx_element(next_value);
196
- var is_hydration_marker =
197
- hydrating &&
198
- anchor.nodeType === COMMENT_NODE &&
199
- /** @type {Comment} */ (anchor).data === HYDRATION_START;
200
-
201
- if (is_hydration_marker) {
202
- end ??= ensure_expression_end(anchor);
203
- }
204
263
 
205
- if (next_is_element) {
206
- if (initialized && is_element && value === next_value) {
264
+ if (next_is_collection || is_tsrx_element(next_value)) {
265
+ if (s.i && s.e && s.v === next_value) {
207
266
  if (end !== null) {
208
- advance_hydration(end);
267
+ settle_hydration(end);
209
268
  }
210
269
  return;
211
270
  }
212
271
 
213
- if (anchor.nodeType === TEXT_NODE) {
272
+ if (s.n === TEXT_NODE) {
214
273
  /** @type {Text} */ (anchor).nodeValue = '';
215
- } else if (text !== null) {
216
- text.remove();
217
- text = null;
274
+ } else if (s.t !== null) {
275
+ s.t.remove();
276
+ s.t = null;
218
277
  }
219
278
 
220
- if (child_block !== null) {
221
- destroy_block(child_block);
222
- child_block = null;
223
- // Restore parent branch's start since we may update it again below
224
- if (modified_parent_branch !== null && modified_parent_branch.s !== null) {
225
- modified_parent_branch.s.start = original_parent_start;
226
- modified_parent_branch = null;
227
- original_parent_start = null;
228
- }
279
+ if (s.b !== null) {
280
+ destroy_block(s.b);
281
+ s.b = null;
282
+ restore_parent_start(s);
229
283
  }
230
284
 
231
- if (end !== null && (initialized || !hydrating)) {
285
+ if (end !== null && (s.i || !hydrating)) {
232
286
  clear_expression_range(anchor, end);
233
287
  }
234
288
 
@@ -236,18 +290,18 @@ export function expression(node, get_value) {
236
290
  set_hydrate_node(get_next_sibling(anchor) ?? end);
237
291
  }
238
292
 
239
- // Find the enclosing branch block BEFORE creating child_block
293
+ // Find the enclosing branch block BEFORE creating the child block
240
294
  // so we can update its s.start to include content inserted before anchor
241
295
  var parent_branch = find_enclosing_branch(active_block);
242
296
 
243
- child_block = branch(() => {
297
+ var child_block = (s.b = branch(() => {
244
298
  var block = /** @type {Block} */ (active_block);
245
299
  if (next_is_collection) {
246
300
  render_tsrx_collection(next_value, end ?? anchor, block);
247
301
  } else {
248
302
  render_tsrx_element(next_value, end ?? anchor, block);
249
303
  }
250
- });
304
+ }));
251
305
 
252
306
  // Update parent branch's s.start to include content inserted before anchor.
253
307
  // This ensures that when the parent branch is destroyed, the full DOM range
@@ -267,81 +321,91 @@ export function expression(node, get_value) {
267
321
  // update it to include the child's content
268
322
  if (parent_start === anchor || parent_start === end) {
269
323
  // Save original so we can restore it when switching to non-TSRXElement
270
- if (modified_parent_branch === null) {
271
- modified_parent_branch = parent_branch;
272
- original_parent_start = parent_start;
324
+ if (s.p === null) {
325
+ s.p = parent_branch;
326
+ s.o = parent_start;
273
327
  }
274
328
  parent_branch.s.start = child_start;
275
329
  }
276
330
  }
277
331
 
278
- value = next_value;
279
- is_element = true;
280
- initialized = true;
332
+ s.v = next_value;
333
+ s.e = true;
334
+ s.i = true;
281
335
  if (end !== null) {
282
- advance_hydration(end);
336
+ settle_hydration(end);
283
337
  }
284
338
  return;
285
339
  }
340
+ }
286
341
 
287
- var next_text = (next_value ?? '') + '';
342
+ var next_text = next_value == null ? '' : next_value + '';
288
343
 
289
- if (initialized && !is_element && value === next_text) {
290
- if (end !== null) {
291
- advance_hydration(end);
292
- }
293
- return;
344
+ if (s.i && !s.e && s.v === next_text) {
345
+ if (end !== null) {
346
+ settle_hydration(end);
294
347
  }
348
+ return;
349
+ }
295
350
 
296
- if (child_block !== null) {
297
- destroy_block(child_block);
298
- child_block = null;
299
- // Restore parent branch's start to original value since the child's DOM nodes
300
- // have been removed and the old start reference would be stale
301
- if (modified_parent_branch !== null && modified_parent_branch.s !== null) {
302
- modified_parent_branch.s.start = original_parent_start;
303
- modified_parent_branch = null;
304
- original_parent_start = null;
305
- }
306
- }
351
+ if (s.b !== null) {
352
+ destroy_block(s.b);
353
+ s.b = null;
354
+ // Restore parent branch's start to original value since the child's DOM nodes
355
+ // have been removed and the old start reference would be stale
356
+ restore_parent_start(s);
357
+ }
307
358
 
308
- if (is_hydration_marker) {
309
- text = get_hydrated_text(anchor, /** @type {Comment} */ (end));
359
+ if (is_hydration_marker) {
360
+ var text = (s.t = get_hydrated_text(anchor, /** @type {Comment} */ (end)));
310
361
 
311
- if (next_text === '') {
312
- if (text !== null) {
313
- text.remove();
314
- text = null;
315
- }
316
- } else if (text === null) {
317
- text = create_text(next_text);
318
- /** @type {Comment} */ (end).before(text);
319
- } else if (text.nodeValue !== next_text) {
320
- text.nodeValue = next_text;
362
+ if (next_text === '') {
363
+ if (text !== null) {
364
+ text.remove();
365
+ s.t = null;
321
366
  }
322
- } else if (anchor.nodeType === COMMENT_NODE) {
323
- if (next_text === '') {
324
- if (text !== null) {
325
- text.remove();
326
- text = null;
327
- }
328
- } else if (text === null) {
329
- text = create_text(next_text);
330
- (end ?? anchor).before(text);
331
- } else if (text.nodeValue !== next_text) {
332
- text.nodeValue = next_text;
367
+ } else if (text === null) {
368
+ text = s.t = create_text(next_text);
369
+ /** @type {Comment} */ (end).before(text);
370
+ } else if (text.nodeValue !== next_text) {
371
+ text.nodeValue = next_text;
372
+ }
373
+ } else if (s.n === COMMENT_NODE) {
374
+ var text = s.t;
375
+ if (next_text === '') {
376
+ if (text !== null) {
377
+ text.remove();
378
+ s.t = null;
333
379
  }
334
- } else if (anchor.nodeType === TEXT_NODE) {
335
- /** @type {Text} */ (anchor).nodeValue = next_text;
380
+ } else if (text === null) {
381
+ text = s.t = create_text(next_text);
382
+ (end ?? anchor).before(text);
383
+ } else if (text.nodeValue !== next_text) {
384
+ text.nodeValue = next_text;
336
385
  }
386
+ } else if (s.n === TEXT_NODE) {
387
+ /** @type {Text} */ (anchor).nodeValue = next_text;
388
+ }
337
389
 
338
- value = next_text;
339
- is_element = false;
340
- initialized = true;
341
- if (end !== null) {
342
- advance_hydration(end);
343
- }
344
- });
390
+ s.v = next_text;
391
+ s.e = false;
392
+ s.i = true;
393
+ if (end !== null) {
394
+ settle_hydration(end);
395
+ }
396
+ }
397
+
398
+ /**
399
+ * @param {ExpressionState} s
400
+ * @returns {void}
401
+ */
402
+ function restore_parent_start(s) {
403
+ var parent = s.p;
404
+ if (parent !== null && parent.s !== null) {
405
+ parent.s.start = s.o;
406
+ s.p = null;
407
+ s.o = null;
408
+ }
345
409
  }
346
410
 
347
411
  /**
@@ -416,17 +480,14 @@ function clear_expression_range(anchor, end) {
416
480
  }
417
481
 
418
482
  /**
483
+ * Leaves the hydration cursor on the expression's end marker, the last node
484
+ * the expression owns: the parent steps past it with its own sibling
485
+ * navigation, exactly as it does after an element or a control-flow block.
419
486
  * @param {Comment} end
420
487
  * @returns {void}
421
488
  */
422
- function advance_hydration(end) {
423
- if (!hydrating) {
424
- return;
425
- }
426
-
427
- var next = get_next_sibling(end);
428
-
429
- if (next !== null) {
430
- set_hydrate_node(next);
489
+ function settle_hydration(end) {
490
+ if (hydrating) {
491
+ set_hydrate_node(end);
431
492
  }
432
493
  }