svelte 5.58.0 → 5.59.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.
- package/compiler/index.js +1 -1
- package/package.json +19 -1
- package/renderer.d.ts +1 -0
- package/src/compiler/errors.js +19 -0
- package/src/compiler/index.js +37 -2
- package/src/compiler/migrate/index.js +2 -1
- package/src/compiler/phases/1-parse/read/options.js +20 -0
- package/src/compiler/phases/2-analyze/index.js +21 -2
- package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/Attribute.js +6 -2
- package/src/compiler/phases/2-analyze/visitors/BindDirective.js +4 -0
- package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +2 -1
- package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/OnDirective.js +6 -0
- package/src/compiler/phases/2-analyze/visitors/RegularElement.js +13 -6
- package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +5 -1
- package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/Text.js +3 -1
- package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +6 -0
- package/src/compiler/phases/2-analyze/visitors/shared/element.js +3 -2
- package/src/compiler/phases/3-transform/client/transform-client.js +68 -1
- package/src/compiler/phases/3-transform/client/transform-template/index.js +4 -3
- package/src/compiler/phases/3-transform/client/transform-template/template.js +1 -1
- package/src/compiler/phases/3-transform/client/utils.js +3 -2
- package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +23 -13
- package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +13 -1
- package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +11 -1
- package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +8 -5
- package/src/compiler/phases/3-transform/client/visitors/shared/component.js +17 -8
- package/src/compiler/phases/3-transform/client/visitors/shared/element.js +4 -3
- package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +7 -1
- package/src/compiler/phases/3-transform/server/transform-server.js +14 -1
- package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +8 -0
- package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +8 -4
- package/src/compiler/print/index.js +45 -57
- package/src/compiler/state.js +12 -0
- package/src/compiler/utils/builders.js +2 -2
- package/src/compiler/validate-options.js +47 -1
- package/src/index-client.js +3 -3
- package/src/internal/client/constants.js +15 -1
- package/src/internal/client/custom-renderer/containers.js +213 -0
- package/src/internal/client/custom-renderer/cross.js +145 -0
- package/src/internal/client/custom-renderer/index.js +28 -0
- package/src/internal/client/custom-renderer/state.js +59 -0
- package/src/internal/client/dev/css.js +3 -1
- package/src/internal/client/dev/debug.js +6 -6
- package/src/internal/client/dev/elements.js +9 -7
- package/src/internal/client/dev/tracing.js +67 -11
- package/src/internal/client/dev/validation.js +2 -1
- package/src/internal/client/dom/blocks/async.js +2 -1
- package/src/internal/client/dom/blocks/await.js +110 -19
- package/src/internal/client/dom/blocks/boundary.js +142 -88
- package/src/internal/client/dom/blocks/branches.js +94 -75
- package/src/internal/client/dom/blocks/css-props.js +31 -3
- package/src/internal/client/dom/blocks/each.js +166 -45
- package/src/internal/client/dom/blocks/html.js +19 -13
- package/src/internal/client/dom/blocks/slot.js +3 -3
- package/src/internal/client/dom/blocks/snippet.js +52 -3
- package/src/internal/client/dom/blocks/svelte-element.js +17 -6
- package/src/internal/client/dom/blocks/svelte-head.js +13 -4
- package/src/internal/client/dom/css.js +4 -4
- package/src/internal/client/dom/elements/attributes.js +91 -51
- package/src/internal/client/dom/elements/bindings/input.js +19 -10
- package/src/internal/client/dom/elements/bindings/select.js +13 -9
- package/src/internal/client/dom/elements/class.js +16 -5
- package/src/internal/client/dom/elements/events.js +153 -21
- package/src/internal/client/dom/elements/misc.js +3 -2
- package/src/internal/client/dom/elements/style.js +17 -6
- package/src/internal/client/dom/hydration.js +6 -6
- package/src/internal/client/dom/operations.js +435 -14
- package/src/internal/client/dom/reconciler.js +2 -2
- package/src/internal/client/dom/template.js +94 -66
- package/src/internal/client/error-handling.js +4 -12
- package/src/internal/client/errors.js +85 -2
- package/src/internal/client/index.js +9 -2
- package/src/internal/client/reactivity/async.js +257 -122
- package/src/internal/client/reactivity/batch.js +1124 -531
- package/src/internal/client/reactivity/deriveds.js +281 -177
- package/src/internal/client/reactivity/effects.js +87 -54
- package/src/internal/client/reactivity/sources.js +30 -124
- package/src/internal/client/reactivity/status.js +1 -1
- package/src/internal/client/render.js +60 -87
- package/src/internal/client/runtime.js +931 -153
- package/src/internal/client/validate.js +2 -2
- package/src/internal/disclose-version.js +1 -1
- package/src/internal/flags/custom-renderer-server.js +10 -0
- package/src/internal/flags/custom-renderer.js +3 -0
- package/src/internal/flags/index.js +6 -0
- package/src/internal/init-operations.js +3 -0
- package/src/internal/shared/errors.js +20 -0
- package/src/legacy/legacy-client.js +6 -2
- package/src/renderer/index-server.js +18 -0
- package/src/renderer/index.js +2 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +245 -25
- package/types/index.d.ts.map +10 -1
- package/src/internal/client/reactivity/utils.js +0 -18
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { teardown } from '../../reactivity/effects.js';
|
|
2
|
-
import { define_property } from '../../../shared/utils.js';
|
|
2
|
+
import { array_from, define_property } from '../../../shared/utils.js';
|
|
3
|
+
import { is_passive_event } from '../../../../utils.js';
|
|
3
4
|
import { hydrating } from '../hydration.js';
|
|
4
5
|
import { queue_micro_task } from '../task.js';
|
|
5
6
|
import { FILENAME } from '../../../../constants.js';
|
|
@@ -11,6 +12,13 @@ import {
|
|
|
11
12
|
set_active_reaction
|
|
12
13
|
} from '../../runtime.js';
|
|
13
14
|
import { without_reactive_context } from './bindings/shared.js';
|
|
15
|
+
import {
|
|
16
|
+
remove_attribute,
|
|
17
|
+
dispatch_event,
|
|
18
|
+
add_event_listener,
|
|
19
|
+
remove_event_listener
|
|
20
|
+
} from '../operations.js';
|
|
21
|
+
import { current_renderer } from '../../custom-renderer/state.js';
|
|
14
22
|
|
|
15
23
|
/**
|
|
16
24
|
* Used on elements, as a map of event type -> event handler,
|
|
@@ -18,6 +26,9 @@ import { without_reactive_context } from './bindings/shared.js';
|
|
|
18
26
|
*/
|
|
19
27
|
export const event_symbol = Symbol('events');
|
|
20
28
|
|
|
29
|
+
// The native listener boundary at which a delegated descendant stopped propagation.
|
|
30
|
+
const propagation_stopped_at = Symbol('propagation stopped at');
|
|
31
|
+
|
|
21
32
|
/** @type {Set<string>} */
|
|
22
33
|
export const all_registered_events = new Set();
|
|
23
34
|
|
|
@@ -30,10 +41,11 @@ export const root_event_handles = new Set();
|
|
|
30
41
|
* @param {HTMLElement} dom
|
|
31
42
|
*/
|
|
32
43
|
export function replay_events(dom) {
|
|
44
|
+
// custom renderers safe since it immediately returns if not hydrating
|
|
33
45
|
if (!hydrating) return;
|
|
34
46
|
|
|
35
|
-
dom
|
|
36
|
-
dom
|
|
47
|
+
remove_attribute(dom, 'onload');
|
|
48
|
+
remove_attribute(dom, 'onerror');
|
|
37
49
|
// @ts-expect-error
|
|
38
50
|
const event = dom.__e;
|
|
39
51
|
if (event !== undefined) {
|
|
@@ -41,7 +53,7 @@ export function replay_events(dom) {
|
|
|
41
53
|
dom.__e = undefined;
|
|
42
54
|
queueMicrotask(() => {
|
|
43
55
|
if (dom.isConnected) {
|
|
44
|
-
dom
|
|
56
|
+
dispatch_event(dom, event);
|
|
45
57
|
}
|
|
46
58
|
});
|
|
47
59
|
}
|
|
@@ -54,15 +66,31 @@ export function replay_events(dom) {
|
|
|
54
66
|
* @param {AddEventListenerOptions} [options]
|
|
55
67
|
*/
|
|
56
68
|
export function create_event(event_name, dom, handler, options = {}) {
|
|
69
|
+
// Capture whether a custom renderer is active at creation time (during mount),
|
|
70
|
+
// since `renderer` will be null when the event actually fires
|
|
71
|
+
var is_custom_renderer = current_renderer != null;
|
|
72
|
+
|
|
57
73
|
/**
|
|
58
74
|
* @this {EventTarget}
|
|
75
|
+
* @param {...any} args
|
|
59
76
|
*/
|
|
60
|
-
function target_handler(
|
|
77
|
+
function target_handler(...args) {
|
|
78
|
+
if (is_custom_renderer) {
|
|
79
|
+
// Custom renderers don't use DOM event propagation/delegation,
|
|
80
|
+
// so just call the handler directly
|
|
81
|
+
return without_reactive_context(() => {
|
|
82
|
+
return handler?.apply(this, /** @type {any} */ (args));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
var event = /** @type {Event} */ (args[0]);
|
|
61
86
|
if (!options.capture) {
|
|
62
87
|
// Only call in the bubble phase, else delegated events would be called before the capturing events
|
|
63
88
|
handle_event_propagation.call(dom, event);
|
|
64
89
|
}
|
|
65
|
-
|
|
90
|
+
// Native stopPropagation() does not stop other listeners on the same element.
|
|
91
|
+
// Only skip this callback if a delegated descendant stopped before reaching it.
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
if (options.capture || event[propagation_stopped_at] !== dom) {
|
|
66
94
|
return without_reactive_context(() => {
|
|
67
95
|
return handler?.call(this, event);
|
|
68
96
|
});
|
|
@@ -74,18 +102,17 @@ export function create_event(event_name, dom, handler, options = {}) {
|
|
|
74
102
|
// defer the attachment till after it's been appended to the document. TODO: remove this once Chrome fixes
|
|
75
103
|
// this bug. The same applies to wheel events and touch events.
|
|
76
104
|
if (
|
|
77
|
-
|
|
78
|
-
event_name.startsWith('touch') ||
|
|
79
|
-
event_name === 'wheel'
|
|
105
|
+
!is_custom_renderer &&
|
|
106
|
+
(event_name.startsWith('pointer') || event_name.startsWith('touch') || event_name === 'wheel')
|
|
80
107
|
) {
|
|
81
108
|
target_handler.__removed = false;
|
|
82
109
|
queue_micro_task(() => {
|
|
83
110
|
if (!target_handler.__removed) {
|
|
84
|
-
dom
|
|
111
|
+
add_event_listener(dom, event_name, target_handler, options);
|
|
85
112
|
}
|
|
86
113
|
});
|
|
87
114
|
} else {
|
|
88
|
-
dom
|
|
115
|
+
add_event_listener(dom, event_name, target_handler, options);
|
|
89
116
|
}
|
|
90
117
|
|
|
91
118
|
return target_handler;
|
|
@@ -106,7 +133,7 @@ export function on(element, type, handler, options = {}) {
|
|
|
106
133
|
|
|
107
134
|
return () => {
|
|
108
135
|
target_handler.__removed = true;
|
|
109
|
-
element
|
|
136
|
+
remove_event_listener(element, type, target_handler, options);
|
|
110
137
|
};
|
|
111
138
|
}
|
|
112
139
|
|
|
@@ -123,17 +150,19 @@ export function event(event_name, dom, handler, capture, passive) {
|
|
|
123
150
|
var target_handler = create_event(event_name, dom, handler, options);
|
|
124
151
|
|
|
125
152
|
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
dom ===
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
153
|
+
// if there's a renderer we will never add to body, window or document.
|
|
154
|
+
current_renderer == null &&
|
|
155
|
+
(dom === document.body ||
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
dom === window ||
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
dom === document ||
|
|
160
|
+
// Firefox has quirky behavior, it can happen that we still get "canplay" events when the element is already removed
|
|
161
|
+
dom instanceof HTMLMediaElement)
|
|
133
162
|
) {
|
|
134
163
|
teardown(() => {
|
|
135
164
|
target_handler.__removed = true;
|
|
136
|
-
dom
|
|
165
|
+
remove_event_listener(dom, event_name, target_handler, options);
|
|
137
166
|
});
|
|
138
167
|
}
|
|
139
168
|
}
|
|
@@ -163,6 +192,89 @@ export function delegate(events) {
|
|
|
163
192
|
}
|
|
164
193
|
}
|
|
165
194
|
|
|
195
|
+
/**
|
|
196
|
+
* How many delegation roots are listening to each event type on each node
|
|
197
|
+
* @type {Map<EventTarget, Map<string, number>>}
|
|
198
|
+
*/
|
|
199
|
+
const delegated_listeners = new Map();
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Makes `target` a root for delegated events: listens on `target` and on `document`
|
|
203
|
+
* for every delegated event type, including types registered later, and dispatches
|
|
204
|
+
* them to the handlers set with `delegated(...)`. Used for `mount`/`hydrate` targets,
|
|
205
|
+
* and for DOM containers that DOM content is rendered into from a custom renderer.
|
|
206
|
+
*
|
|
207
|
+
* This always uses DOM methods directly (rather than renderer-aware operations),
|
|
208
|
+
* since it may be torn down while a custom renderer is active.
|
|
209
|
+
* @param {EventTarget} target
|
|
210
|
+
* @returns {() => void} stops listening
|
|
211
|
+
*/
|
|
212
|
+
export function listen_to_delegated_events(target) {
|
|
213
|
+
/** @type {Set<string>} */
|
|
214
|
+
var registered_events = new Set();
|
|
215
|
+
|
|
216
|
+
/** @param {Array<string>} events */
|
|
217
|
+
var event_handle = (events) => {
|
|
218
|
+
for (var i = 0; i < events.length; i++) {
|
|
219
|
+
var event_name = events[i];
|
|
220
|
+
|
|
221
|
+
if (registered_events.has(event_name)) continue;
|
|
222
|
+
registered_events.add(event_name);
|
|
223
|
+
|
|
224
|
+
var passive = is_passive_event(event_name);
|
|
225
|
+
|
|
226
|
+
// Add the event listener to both the target and the document.
|
|
227
|
+
// The target listener ensures we catch events from within in case
|
|
228
|
+
// the outer content stops propagation of the event.
|
|
229
|
+
//
|
|
230
|
+
// The document listener ensures we catch events that originate from elements that were
|
|
231
|
+
// manually moved outside of the target (e.g. via manual portals).
|
|
232
|
+
for (const node of [target, document]) {
|
|
233
|
+
var counts = delegated_listeners.get(node);
|
|
234
|
+
|
|
235
|
+
if (counts === undefined) {
|
|
236
|
+
counts = new Map();
|
|
237
|
+
delegated_listeners.set(node, counts);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var count = counts.get(event_name);
|
|
241
|
+
|
|
242
|
+
if (count === undefined) {
|
|
243
|
+
node.addEventListener(event_name, handle_event_propagation, { passive });
|
|
244
|
+
counts.set(event_name, 1);
|
|
245
|
+
} else {
|
|
246
|
+
counts.set(event_name, count + 1);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
event_handle(array_from(all_registered_events));
|
|
253
|
+
root_event_handles.add(event_handle);
|
|
254
|
+
|
|
255
|
+
return () => {
|
|
256
|
+
for (var event_name of registered_events) {
|
|
257
|
+
for (const node of [target, document]) {
|
|
258
|
+
var counts = /** @type {Map<string, number>} */ (delegated_listeners.get(node));
|
|
259
|
+
var count = /** @type {number} */ (counts.get(event_name));
|
|
260
|
+
|
|
261
|
+
if (--count == 0) {
|
|
262
|
+
node.removeEventListener(event_name, handle_event_propagation);
|
|
263
|
+
counts.delete(event_name);
|
|
264
|
+
|
|
265
|
+
if (counts.size === 0) {
|
|
266
|
+
delegated_listeners.delete(node);
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
counts.set(event_name, count);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
root_event_handles.delete(event_handle);
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
166
278
|
// used to store the reference to the currently propagated event
|
|
167
279
|
// to prevent garbage collection between microtasks in Firefox (<= 141)
|
|
168
280
|
// If the event object is GCed too early, the expando __root property
|
|
@@ -179,7 +291,21 @@ let last_propagated_event_clear_scheduled = false;
|
|
|
179
291
|
* @returns {void}
|
|
180
292
|
*/
|
|
181
293
|
export function handle_event_propagation(event) {
|
|
294
|
+
// this function is custom renderers safe since it's invoked in `mount`
|
|
182
295
|
var handler_element = this;
|
|
296
|
+
var was_stopped = event.cancelBubble;
|
|
297
|
+
|
|
298
|
+
// Another listener at this boundary may already have dispatched the delegated
|
|
299
|
+
// handler that stopped propagation. Do not dispatch it again.
|
|
300
|
+
// @ts-expect-error
|
|
301
|
+
if (was_stopped && event[propagation_stopped_at] === handler_element) return;
|
|
302
|
+
|
|
303
|
+
if (!was_stopped) {
|
|
304
|
+
// The same event object may be dispatched again.
|
|
305
|
+
// @ts-expect-error
|
|
306
|
+
delete event[propagation_stopped_at];
|
|
307
|
+
}
|
|
308
|
+
|
|
183
309
|
var owner_document = /** @type {Node} */ (handler_element).ownerDocument;
|
|
184
310
|
var event_name = event.type;
|
|
185
311
|
var path = event.composedPath?.() || [];
|
|
@@ -302,7 +428,13 @@ export function handle_event_propagation(event) {
|
|
|
302
428
|
throw_error = error;
|
|
303
429
|
}
|
|
304
430
|
}
|
|
305
|
-
if (event.cancelBubble)
|
|
431
|
+
if (event.cancelBubble) {
|
|
432
|
+
if (!was_stopped) {
|
|
433
|
+
// @ts-expect-error
|
|
434
|
+
event[propagation_stopped_at] = handler_element;
|
|
435
|
+
}
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
306
438
|
|
|
307
439
|
path_idx++;
|
|
308
440
|
current_target = path_idx < path.length ? /** @type {Element} */ (path[path_idx]) : null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hydrating } from '../hydration.js';
|
|
2
|
-
import { clear_text_content, get_first_child } from '../operations.js';
|
|
2
|
+
import { clear_text_content, get_first_child, add_event_listener } from '../operations.js';
|
|
3
3
|
import { queue_micro_task } from '../task.js';
|
|
4
4
|
import { FORM_RESET_HANDLER } from '../../constants.js';
|
|
5
5
|
|
|
@@ -38,7 +38,8 @@ let listening_to_form_reset = false;
|
|
|
38
38
|
export function add_form_reset_listener() {
|
|
39
39
|
if (!listening_to_form_reset) {
|
|
40
40
|
listening_to_form_reset = true;
|
|
41
|
-
|
|
41
|
+
add_event_listener(
|
|
42
|
+
document,
|
|
42
43
|
'reset',
|
|
43
44
|
(evt) => {
|
|
44
45
|
// Needs to happen one tick later or else the dom properties of the form
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { to_style } from '../../../shared/attributes.js';
|
|
2
|
+
import { custom_renderers_flag } from '../../../flags/index.js';
|
|
3
|
+
import { current_renderer } from '../../custom-renderer/state.js';
|
|
2
4
|
import { STYLE_CACHE } from '../../constants.js';
|
|
3
5
|
import { hydrating } from '../hydration.js';
|
|
6
|
+
import {
|
|
7
|
+
style_remove_property,
|
|
8
|
+
style_set_property,
|
|
9
|
+
get_attribute,
|
|
10
|
+
remove_attribute,
|
|
11
|
+
set_css_text
|
|
12
|
+
} from '../operations.js';
|
|
4
13
|
|
|
5
14
|
/**
|
|
6
15
|
* @param {Element & ElementCSSInlineStyle} dom
|
|
@@ -14,9 +23,9 @@ function update_styles(dom, prev = {}, next, priority) {
|
|
|
14
23
|
|
|
15
24
|
if (prev[key] !== value) {
|
|
16
25
|
if (next[key] == null) {
|
|
17
|
-
dom
|
|
26
|
+
style_remove_property(/** @type {HTMLElement} */ (dom), key);
|
|
18
27
|
} else {
|
|
19
|
-
dom
|
|
28
|
+
style_set_property(/** @type {HTMLElement} */ (dom), key, value, priority);
|
|
20
29
|
}
|
|
21
30
|
}
|
|
22
31
|
}
|
|
@@ -31,14 +40,16 @@ function update_styles(dom, prev = {}, next, priority) {
|
|
|
31
40
|
export function set_style(dom, value, prev_styles, next_styles) {
|
|
32
41
|
var prev = /** @type {any} */ (dom)[STYLE_CACHE];
|
|
33
42
|
|
|
34
|
-
|
|
43
|
+
// Custom renderers only deal in attributes, so rather than updating individual properties
|
|
44
|
+
// (which would mean parsing and editing the `style` attribute), always set the whole thing
|
|
45
|
+
if (hydrating || prev !== value || (custom_renderers_flag && current_renderer !== null)) {
|
|
35
46
|
var next_style_attr = to_style(value, next_styles);
|
|
36
47
|
|
|
37
|
-
if (!hydrating || next_style_attr !== dom
|
|
48
|
+
if (!hydrating || next_style_attr !== get_attribute(dom, 'style')) {
|
|
38
49
|
if (next_style_attr == null) {
|
|
39
|
-
dom
|
|
50
|
+
remove_attribute(dom, 'style');
|
|
40
51
|
} else {
|
|
41
|
-
dom
|
|
52
|
+
set_css_text(/** @type {HTMLElement} */ (dom), next_style_attr);
|
|
42
53
|
}
|
|
43
54
|
}
|
|
44
55
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
HYDRATION_START_FAILED
|
|
10
10
|
} from '../../../constants.js';
|
|
11
11
|
import * as w from '../warnings.js';
|
|
12
|
-
import { get_next_sibling } from './operations.js';
|
|
12
|
+
import { get_next_sibling, get_node_value, node_type, remove_node } from './operations.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Use this variable to guard everything related to hydration code so it can be treeshaken out
|
|
@@ -90,8 +90,8 @@ export function skip_nodes(remove = true) {
|
|
|
90
90
|
var node = hydrate_node;
|
|
91
91
|
|
|
92
92
|
while (true) {
|
|
93
|
-
if (node
|
|
94
|
-
var data =
|
|
93
|
+
if (node_type(node) === COMMENT_NODE) {
|
|
94
|
+
var data = get_node_value(node) ?? '';
|
|
95
95
|
|
|
96
96
|
if (data === HYDRATION_END) {
|
|
97
97
|
if (depth === 0) return node;
|
|
@@ -109,7 +109,7 @@ export function skip_nodes(remove = true) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
var next = /** @type {TemplateNode} */ (get_next_sibling(node));
|
|
112
|
-
if (remove) node
|
|
112
|
+
if (remove) remove_node(node);
|
|
113
113
|
node = next;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -119,10 +119,10 @@ export function skip_nodes(remove = true) {
|
|
|
119
119
|
* @param {TemplateNode} node
|
|
120
120
|
*/
|
|
121
121
|
export function read_hydration_instruction(node) {
|
|
122
|
-
if (!node || node
|
|
122
|
+
if (!node || node_type(node) !== COMMENT_NODE) {
|
|
123
123
|
w.hydration_mismatch();
|
|
124
124
|
throw HYDRATION_ERROR;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
return
|
|
127
|
+
return get_node_value(node) ?? '';
|
|
128
128
|
}
|