Skip to content

Commit ffc1f6b

Browse files
committed
dry out
1 parent 796db26 commit ffc1f6b

File tree

1 file changed

+11
-21
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/visitors

1 file changed

+11
-21
lines changed

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ export function EachBlock(node, context) {
313313
}
314314

315315
const { has_await } = node.metadata.expression;
316-
const thunk = b.thunk(collection, has_await);
316+
const get_collection = b.thunk(collection, has_await);
317+
const thunk = has_await ? b.thunk(b.call('$.get', b.id('$$collection'))) : get_collection;
317318

318319
const render_args = [b.id('$$anchor'), item];
319320
if (uses_index || collection_id) render_args.push(index);
@@ -323,7 +324,7 @@ export function EachBlock(node, context) {
323324
const args = [
324325
context.state.node,
325326
b.literal(flags),
326-
has_await ? b.thunk(b.call('$.get', b.id('$$collection'))) : thunk,
327+
thunk,
327328
key_function,
328329
b.arrow(render_args, b.block(declarations.concat(block.body)))
329330
];
@@ -334,36 +335,25 @@ export function EachBlock(node, context) {
334335
);
335336
}
336337

338+
const statements = [add_svelte_meta(b.call('$.each', ...args), node, 'each')];
339+
340+
if (dev && node.metadata.keyed) {
341+
statements.unshift(b.stmt(b.call('$.validate_each_keys', thunk, key_function)));
342+
}
343+
337344
if (has_await) {
338-
const statements = [add_svelte_meta(b.call('$.each', ...args), node, 'each')];
339-
if (dev && node.metadata.keyed) {
340-
statements.unshift(
341-
b.stmt(
342-
b.call(
343-
'$.validate_each_keys',
344-
b.thunk(b.call('$.get', b.id('$$collection'))),
345-
key_function
346-
)
347-
)
348-
);
349-
}
350345
context.state.init.push(
351346
b.stmt(
352347
b.call(
353348
'$.async',
354349
context.state.node,
355-
b.array([thunk]),
350+
b.array([get_collection]),
356351
b.arrow([context.state.node, b.id('$$collection')], b.block(statements))
357352
)
358353
)
359354
);
360355
} else {
361-
if (dev && node.metadata.keyed) {
362-
context.state.init.push(
363-
b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function))
364-
);
365-
}
366-
context.state.init.push(add_svelte_meta(b.call('$.each', ...args), node, 'each'));
356+
context.state.init.push(...statements);
367357
}
368358
}
369359

0 commit comments

Comments
 (0)