pull/15844/head
Rich Harris 3 months ago
parent f34f28e546
commit 1e2e57ff51

@ -11,35 +11,22 @@ import { build_expression } from './shared/utils.js';
export function KeyBlock(node, context) { export function KeyBlock(node, context) {
context.state.template.push_comment(); context.state.template.push_comment();
const key = build_expression(context, node.expression, node.metadata.expression); const { has_await } = node.metadata.expression;
const expression = build_expression(context, node.expression, node.metadata.expression);
const key = b.thunk(has_await ? b.call('$.get', b.id('$$key')) : expression);
const body = /** @type {Expression} */ (context.visit(node.fragment)); const body = /** @type {Expression} */ (context.visit(node.fragment));
if (node.metadata.expression.has_await) { let call = b.call('$.key', context.state.node, key, b.arrow([b.id('$$anchor')], body));
context.state.init.push(
b.stmt( if (has_await) {
b.call( call = b.call(
'$.async', '$.async',
context.state.node, context.state.node,
b.array([b.thunk(key, true)]), b.array([b.thunk(expression, true)]),
b.arrow( b.arrow([context.state.node, b.id('$$key')], b.block([b.stmt(call)]))
[context.state.node, b.id('$$key')],
b.block([
b.stmt(
b.call(
'$.key',
context.state.node,
b.thunk(b.call('$.get', b.id('$$key'))),
b.arrow([b.id('$$anchor')], body)
)
)
])
)
)
)
);
} else {
context.state.init.push(
b.stmt(b.call('$.key', context.state.node, b.thunk(key), b.arrow([b.id('$$anchor')], body)))
); );
} }
context.state.init.push(b.stmt(call));
} }

@ -15,7 +15,7 @@ import { current_batch } from '../../reactivity/batch.js';
* @param {(anchor: Node) => TemplateNode | void} render_fn * @param {(anchor: Node) => TemplateNode | void} render_fn
* @returns {void} * @returns {void}
*/ */
export function key_block(node, get_key, render_fn) { export function key(node, get_key, render_fn) {
if (hydrating) { if (hydrating) {
hydrate_next(); hydrate_next();
} }

@ -13,7 +13,7 @@ export { async } from './dom/blocks/async.js';
export { validate_snippet_args } from './dev/validation.js'; export { validate_snippet_args } from './dev/validation.js';
export { await_block as await } from './dom/blocks/await.js'; export { await_block as await } from './dom/blocks/await.js';
export { if_block as if } from './dom/blocks/if.js'; export { if_block as if } from './dom/blocks/if.js';
export { key_block as key } from './dom/blocks/key.js'; export { key } from './dom/blocks/key.js';
export { css_props } from './dom/blocks/css-props.js'; export { css_props } from './dom/blocks/css-props.js';
export { index, each } from './dom/blocks/each.js'; export { index, each } from './dom/blocks/each.js';
export { html } from './dom/blocks/html.js'; export { html } from './dom/blocks/html.js';

Loading…
Cancel
Save