mirror of https://github.com/sveltejs/svelte
parent
6402161932
commit
f2d4792406
@ -1,21 +0,0 @@
|
||||
/** @import { Expression } from 'estree' */
|
||||
/** @import { AST } from '#compiler' */
|
||||
/** @import { ComponentContext } from '../types' */
|
||||
import * as b from '../../../../utils/builders.js';
|
||||
|
||||
/**
|
||||
* @param {AST.AttachTag} node
|
||||
* @param {ComponentContext} context
|
||||
*/
|
||||
export function AttachTag(node, context) {
|
||||
context.state.init.push(
|
||||
b.stmt(
|
||||
b.call(
|
||||
'$.attach',
|
||||
context.state.node,
|
||||
b.thunk(/** @type {Expression} */ (context.visit(node.expression)))
|
||||
)
|
||||
)
|
||||
);
|
||||
context.next();
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/** @import { Expression } from 'estree' */
|
||||
/** @import { AST } from '#compiler' */
|
||||
/** @import { ComponentContext } from '../types' */
|
||||
import * as b from '../../../../utils/builders.js';
|
||||
|
||||
/**
|
||||
* @param {AST.Attachment} node
|
||||
* @param {ComponentContext} context
|
||||
*/
|
||||
export function Attachment(node, context) {
|
||||
for (const attachment of node.attachments) {
|
||||
if (attachment.type === 'SpreadElement') {
|
||||
context.state.init.push(
|
||||
b.stmt(
|
||||
b.call(
|
||||
'$.attach_all',
|
||||
context.state.node,
|
||||
b.thunk(/** @type {Expression} */ (context.visit(attachment.argument)))
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
context.state.init.push(
|
||||
b.stmt(
|
||||
b.call(
|
||||
'$.attach',
|
||||
context.state.node,
|
||||
b.thunk(/** @type {Expression} */ (context.visit(attachment)))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +1,5 @@
|
||||
<div {@attach (node) => {}} {@attach (node) => {}}></div>
|
||||
<div attach(a)></div>
|
||||
<div attach(a, b, c)></div>
|
||||
<div attach(...stuff)></div>
|
||||
<div attach(a, b, c, ...stuff)></div>
|
||||
<div attach((node) => {})></div>
|
||||
|
@ -1 +1 @@
|
||||
<div {@attach (node) => node.textContent = node.nodeName}></div>
|
||||
<div attach((node) => node.textContent = node.nodeName)></div>
|
||||
|
@ -1 +1 @@
|
||||
<svelte:element this={'div'} {@attach (node) => node.textContent = node.nodeName}></svelte:element>
|
||||
<svelte:element this={'div'} attach((node) => node.textContent = node.nodeName)></svelte:element>
|
||||
|
Loading…
Reference in new issue