mirror of https://github.com/sveltejs/svelte
parent
531e75d314
commit
b29e1e3a6f
@ -0,0 +1,21 @@
|
|||||||
|
/** @import { Expression } from 'estree' */
|
||||||
|
/** @import { AST } from '#compiler' */
|
||||||
|
/** @import { ComponentContext } from '../types' */
|
||||||
|
import * as b from '../../../../utils/builders.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AST.UseTag} node
|
||||||
|
* @param {ComponentContext} context
|
||||||
|
*/
|
||||||
|
export function UseTag(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,11 @@
|
|||||||
|
import { effect } from '../../reactivity/effects.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Element} node
|
||||||
|
* @param {() => (node: Element) => void} get_fn
|
||||||
|
*/
|
||||||
|
export function attach(node, get_fn) {
|
||||||
|
effect(() => {
|
||||||
|
get_fn()(node);
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
ssrHtml: `<div></div>`,
|
||||||
|
html: `<div>DIV</div>`
|
||||||
|
});
|
@ -0,0 +1 @@
|
|||||||
|
<div {@use (node) => node.textContent = node.nodeName}></div>
|
Loading…
Reference in new issue