Skip to content

Commit 4d0b743

Browse files
authored
feat: use linked lists for each blocks (#11107)
* unify indexed/keyed each blocks * WIP * comment out console temporarily * WIP * animations * fix animations * mostly working * working * revert unnecessary test changes * remove unused code * noop when item matches * add test * DRY * simplify * mostly working * fix * fix * uncomment * remove unnecessary test * unused * appease eslint etc * avoid mutating lookup * reuse lookup * perf tweaks * microoptimisations * more efficient linking * optimise
1 parent 4820259 commit 4d0b743

File tree

7 files changed

+218
-355
lines changed

7 files changed

+218
-355
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,44 +2315,29 @@ export const template_visitors = {
23152315
)
23162316
: /** @type {import('estree').Expression} */ (context.visit(node.key))
23172317
)
2318-
: b.literal(null);
2318+
: b.id('$.index');
23192319

23202320
if (node.index && each_node_meta.contains_group_binding) {
23212321
// We needed to create a unique identifier for the index above, but we want to use the
23222322
// original index name in the template, therefore create another binding
23232323
declarations.push(b.let(node.index, index));
23242324
}
23252325

2326-
let callee = '$.each_indexed';
2327-
2328-
/** @type {import('estree').Expression[]} */
2329-
const args = [];
2330-
2331-
if ((each_type & EACH_KEYED) !== 0) {
2332-
if (context.state.options.dev && key_function.type !== 'Literal') {
2333-
context.state.init.push(
2334-
b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function))
2335-
);
2336-
}
2337-
2338-
callee = '$.each_keyed';
2339-
2340-
args.push(
2341-
context.state.node,
2342-
b.literal(each_type),
2343-
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2344-
key_function,
2345-
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children)))
2346-
);
2347-
} else {
2348-
args.push(
2349-
context.state.node,
2350-
b.literal(each_type),
2351-
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2352-
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children)))
2326+
if (context.state.options.dev && (each_type & EACH_KEYED) !== 0) {
2327+
context.state.init.push(
2328+
b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function))
23532329
);
23542330
}
23552331

2332+
/** @type {import('estree').Expression[]} */
2333+
const args = [
2334+
context.state.node,
2335+
b.literal(each_type),
2336+
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2337+
key_function,
2338+
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children)))
2339+
];
2340+
23562341
if (node.fallback) {
23572342
args.push(
23582343
b.arrow(
@@ -2362,7 +2347,7 @@ export const template_visitors = {
23622347
);
23632348
}
23642349

2365-
context.state.init.push(b.stmt(b.call(callee, ...args)));
2350+
context.state.init.push(b.stmt(b.call('$.each', ...args)));
23662351
},
23672352
IfBlock(node, context) {
23682353
context.state.template.push('<!>');

0 commit comments

Comments
 (0)