pull/12215/head
Rich Harris 2 years ago
parent 17c95e232b
commit 35dbddd250

@ -13,12 +13,13 @@ import { queue_micro_task } from './task.js';
* *
* @param {import('#client').TemplateNode | undefined | null} start * @param {import('#client').TemplateNode | undefined | null} start
* @param {import('#client').TemplateNode} end * @param {import('#client').TemplateNode} end
* @param {import('#client').TemplateNode | null} anchor
*/ */
export function assign_nodes(start, end) { export function assign_nodes(start, end, anchor = null) {
const effect = /** @type {import('#client').Effect} */ (current_effect); const effect = /** @type {import('#client').Effect} */ (current_effect);
if (effect.nodes === null) { if (effect.nodes === null) {
effect.nodes = { start, anchor: null, end }; effect.nodes = { start, anchor, end };
} else if (effect.nodes.start === undefined) { } else if (effect.nodes.start === undefined) {
effect.nodes.start = start; effect.nodes.start = start;
} }
@ -64,11 +65,7 @@ export function template(content, flags) {
var end = /** @type {import('#client').TemplateNode} */ (is_fragment ? clone.lastChild : clone); var end = /** @type {import('#client').TemplateNode} */ (is_fragment ? clone.lastChild : clone);
assign_nodes(start, end); assign_nodes(start, end, /** @type {import('#client').TemplateNode} */ (clone.firstChild));
if (unset) {
current_effect.nodes.anchor = clone.firstChild;
}
return clone; return clone;
}; };
@ -251,16 +248,11 @@ export function comment(flags = 0) {
return hydrate_start; return hydrate_start;
} }
var unset = (flags & TEMPLATE_UNSET_START) !== 0;
var frag = document.createDocumentFragment(); var frag = document.createDocumentFragment();
var anchor = empty(); var anchor = empty();
frag.append(anchor); frag.append(anchor);
assign_nodes(unset ? undefined : null, anchor); assign_nodes((flags & TEMPLATE_UNSET_START) !== 0 ? undefined : null, anchor, anchor);
if (unset) {
current_effect.nodes.anchor = anchor;
}
return frag; return frag;
} }

@ -386,7 +386,7 @@ export function destroy_effect(effect, remove_dom = true) {
export function get_first_node(effect) { export function get_first_node(effect) {
if (effect.nodes !== null) { if (effect.nodes !== null) {
if (effect.nodes.start === undefined) { if (effect.nodes.start === undefined) {
return effect.nodes.anchor; return /** @type {import('#client').TemplateNode} */ (effect.nodes.anchor);
} }
if (effect.nodes.start !== null) { if (effect.nodes.start !== null) {

Loading…
Cancel
Save