attachments-2
Rich Harris 8 months ago
parent 1d4cb8eab3
commit 35b9d21316

@ -9,26 +9,18 @@ import * as b from '../../../../utils/builders.js';
*/ */
export function Attachment(node, context) { export function Attachment(node, context) {
for (const attachment of node.attachments) { for (const attachment of node.attachments) {
if (attachment.type === 'SpreadElement') { context.state.init.push(
context.state.init.push( b.stmt(
b.stmt( b.call(
b.call( '$.attach',
'$.attach_all', context.state.node,
context.state.node, b.thunk(
b.thunk(/** @type {Expression} */ (context.visit(attachment.argument))) /** @type {Expression} */ (
context.visit(attachment.type === 'SpreadElement' ? attachment.argument : attachment)
)
) )
) )
); )
} else { );
context.state.init.push(
b.stmt(
b.call(
'$.attach',
context.state.node,
b.thunk(/** @type {Expression} */ (context.visit(attachment)))
)
)
);
}
} }
} }

@ -11,7 +11,7 @@ export function attach(node, get_fn) {
if (Array.isArray(attachment)) { if (Array.isArray(attachment)) {
for (const fn of attachment) { for (const fn of attachment) {
if (fn) { if (fn) {
$effect(() => fn(node)); effect(() => fn(node));
} }
} }
} else if (attachment) { } else if (attachment) {

Loading…
Cancel
Save