optimise each blocks

pull/12335/head
Rich Harris 2 years ago
parent fa4d3730f9
commit ee76cd7d7e

@ -1392,13 +1392,8 @@ const template_visitors = {
each.push(b.let(node.index, index));
}
// TODO we shouldn't need these
each.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--#each-item-->'))));
each.push(.../** @type {import('estree').BlockStatement} */ (context.visit(node.body)).body);
each.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--/each-item-->'))));
const for_loop = b.for(
b.let(index, b.literal(0)),
b.binary('<', index, b.member(array_id, b.id('length'))),

@ -181,10 +181,7 @@ export function each(anchor, flags, get_collection, get_key, render_fn, fallback
var item;
for (var i = 0; i < length; i++) {
if (
child_anchor.nodeType !== 8 ||
/** @type {Comment} */ (child_anchor).data !== '#each-item'
) {
if (child_anchor.nodeType === 8 && /** @type {Comment} */ (child_anchor).data === '/each') {
// If `nodes` is null, then that means that the server rendered fewer items than what
// expected, so break out and continue appending non-hydrated items
anchor = /** @type {Comment} */ (child_anchor);
@ -193,15 +190,13 @@ export function each(anchor, flags, get_collection, get_key, render_fn, fallback
break;
}
hydrate_next();
var value = array[i];
var key = get_key(value, i);
item = create_item(child_anchor, state, prev, null, value, key, i, render_fn, flags);
state.items.set(key, item);
var close = hydrate_node.nextSibling; // TODO validate. or replace `<!--]--><!--[-->` with `<!---->`
// hydrate_next();
child_anchor = /** @type {Comment} */ (hydrate_next());
child_anchor = /** @type {Comment} */ (hydrate_node);
prev = item;
}

@ -8,9 +8,7 @@ export default function Each_string_template($$payload) {
for (let $$index = 0; $$index < each_array.length; $$index++) {
const thing = each_array[$$index];
$$payload.out += "<!--#each-item-->";
$$payload.out += `${$.escape(thing)}, `;
$$payload.out += "<!--/each-item-->";
}
$$payload.out += `<!--/each-->`;

Loading…
Cancel
Save