|
|
|
|
@ -83,21 +83,19 @@ export function create_text(value = '') {
|
|
|
|
|
/**
|
|
|
|
|
* @template {Node} N
|
|
|
|
|
* @param {N} node
|
|
|
|
|
* @returns {Node | null}
|
|
|
|
|
*/
|
|
|
|
|
/*@__NO_SIDE_EFFECTS__*/
|
|
|
|
|
export function get_first_child(node) {
|
|
|
|
|
return first_child_getter.call(node);
|
|
|
|
|
return /** @type {TemplateNode | null} */ (first_child_getter.call(node));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @template {Node} N
|
|
|
|
|
* @param {N} node
|
|
|
|
|
* @returns {Node | null}
|
|
|
|
|
*/
|
|
|
|
|
/*@__NO_SIDE_EFFECTS__*/
|
|
|
|
|
export function get_next_sibling(node) {
|
|
|
|
|
return next_sibling_getter.call(node);
|
|
|
|
|
return /** @type {TemplateNode | null} */ (next_sibling_getter.call(node));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -105,14 +103,14 @@ export function get_next_sibling(node) {
|
|
|
|
|
* @template {Node} N
|
|
|
|
|
* @param {N} node
|
|
|
|
|
* @param {boolean} is_text
|
|
|
|
|
* @returns {Node | null}
|
|
|
|
|
* @returns {TemplateNode | null}
|
|
|
|
|
*/
|
|
|
|
|
export function child(node, is_text) {
|
|
|
|
|
if (!hydrating) {
|
|
|
|
|
return get_first_child(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var child = /** @type {TemplateNode} */ (get_first_child(hydrate_node));
|
|
|
|
|
var child = get_first_child(hydrate_node);
|
|
|
|
|
|
|
|
|
|
// Child can be null if we have an element with a single child, like `<p>{text}</p>`, where `text` is empty
|
|
|
|
|
if (child === null) {
|
|
|
|
|
@ -130,14 +128,13 @@ export function child(node, is_text) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
|
|
|
* @param {DocumentFragment | TemplateNode | TemplateNode[]} fragment
|
|
|
|
|
* @param {TemplateNode} node
|
|
|
|
|
* @param {boolean} [is_text]
|
|
|
|
|
* @returns {Node | null}
|
|
|
|
|
* @returns {TemplateNode | null}
|
|
|
|
|
*/
|
|
|
|
|
export function first_child(fragment, is_text = false) {
|
|
|
|
|
export function first_child(node, is_text = false) {
|
|
|
|
|
if (!hydrating) {
|
|
|
|
|
// when not hydrating, `fragment` is a `DocumentFragment` (the result of calling `open_frag`)
|
|
|
|
|
var first = /** @type {DocumentFragment} */ (get_first_child(/** @type {Node} */ (fragment)));
|
|
|
|
|
var first = get_first_child(node);
|
|
|
|
|
|
|
|
|
|
// TODO prevent user comments with the empty string when preserveComments is true
|
|
|
|
|
if (first instanceof Comment && first.data === '') return get_next_sibling(first);
|
|
|
|
|
@ -163,7 +160,7 @@ export function first_child(fragment, is_text = false) {
|
|
|
|
|
* @param {TemplateNode} node
|
|
|
|
|
* @param {number} count
|
|
|
|
|
* @param {boolean} is_text
|
|
|
|
|
* @returns {Node | null}
|
|
|
|
|
* @returns {TemplateNode | null}
|
|
|
|
|
*/
|
|
|
|
|
export function sibling(node, count = 1, is_text = false) {
|
|
|
|
|
let next_sibling = hydrating ? hydrate_node : node;
|
|
|
|
|
@ -195,7 +192,7 @@ export function sibling(node, count = 1, is_text = false) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_hydrate_node(next_sibling);
|
|
|
|
|
return /** @type {TemplateNode} */ (next_sibling);
|
|
|
|
|
return next_sibling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|