simplify a tad

pull/12215/head
Rich Harris 4 months ago
parent 5d078faaf3
commit 06a8f34566

@ -343,9 +343,8 @@ export function destroy_effect(effect, remove_dom = true) {
if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null) { if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null) {
var start = get_first_node(effect); var start = get_first_node(effect);
var end = get_last_node(effect);
remove_nodes(start, end); remove_nodes(start, effect.nodes.end);
removed = true; removed = true;
} }
@ -384,46 +383,30 @@ export function destroy_effect(effect, remove_dom = true) {
* @returns {import('#client').TemplateNode} * @returns {import('#client').TemplateNode}
*/ */
export function get_first_node(effect) { export function get_first_node(effect) {
if (effect.nodes !== null) { var nodes = /** @type {NonNullable<typeof effect.nodes>} */ (effect.nodes);
if (effect.nodes.start === undefined) { var start = nodes.start;
return /** @type {import('#client').TemplateNode} */ (effect.nodes.anchor);
}
if (effect.nodes.start !== null) { if (start === undefined) {
return effect.nodes.start; // edge case — a snippet or component was the first item inside the effect,
} // but it didn't render any DOM. in this case, we return the item's anchor
return /** @type {import('#client').TemplateNode} */ (nodes.anchor);
}
if (start !== null) {
return start;
} }
var child = effect.first; var child = effect.first;
while ( while (child && (child.nodes === null || (child.f & HEAD_EFFECT) !== 0)) {
child &&
((child.f & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0 || (child.f & HEAD_EFFECT) !== 0)
) {
child = child.next; child = child.next;
} }
if (child !== null) { if (child !== null && child.nodes !== null) {
return get_first_node(child); return get_first_node(child);
} }
// in the case that there's no DOM, return the first anchor // in the case that there's no DOM, return the first anchor
return get_last_node(effect); return nodes.end;
}
/**
* @param {import('#client').Effect} effect
* @returns {import('#client').TemplateNode}
*/
function get_last_node(effect) {
if (effect.nodes !== null) {
return effect.nodes.end;
}
if (effect.last !== null) {
return get_last_node(effect.last);
}
return /** @type {import('#client').TemplateNode} */ (/** @type {unknown} */ (null));
} }
/** /**

Loading…
Cancel
Save