Skip to content

Commit 2329284

Browse files
committed
working
1 parent b29e1e3 commit 2329284

File tree

10 files changed

+59
-1
lines changed

10 files changed

+59
-1
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export function visit_component(node, context) {
7474
attribute.type !== 'SpreadAttribute' &&
7575
attribute.type !== 'LetDirective' &&
7676
attribute.type !== 'OnDirective' &&
77-
attribute.type !== 'BindDirective'
77+
attribute.type !== 'BindDirective' &&
78+
attribute.type !== 'UseTag'
7879
) {
7980
e.component_invalid_directive(attribute);
8081
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ export function build_component(node, component_name, context, anchor = context.
252252
);
253253
}
254254
}
255+
} else if (attribute.type === 'UseTag') {
256+
push_prop(
257+
b.prop(
258+
'init',
259+
b.call('Symbol', b.literal('@use')),
260+
b.thunk(/** @type {Expression} */ (context.visit(attribute.expression))),
261+
true
262+
)
263+
);
255264
}
256265
}
257266

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
set_active_effect,
1414
set_active_reaction
1515
} from '../../runtime.js';
16+
import { attach } from './attachments.js';
1617

1718
/**
1819
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
@@ -407,6 +408,10 @@ export function set_attributes(
407408
}
408409
}
409410

411+
for (let symbol of Object.getOwnPropertySymbols(next)) {
412+
attach(element, next[symbol]);
413+
}
414+
410415
return current;
411416
}
412417

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
let props = $props();
3+
</script>
4+
5+
<div {...props}></div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
ssrHtml: `<div></div>`,
5+
html: `<div>set from component</div>`
6+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
</script>
4+
5+
<Child {@use (node) => node.textContent = 'set from component'} />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
ssrHtml: `<div></div><button>increment</button>`,
6+
html: `<div>1</div><button>increment</button>`,
7+
8+
test: ({ assert, target }) => {
9+
const btn = target.querySelector('button');
10+
11+
flushSync(() => btn?.click());
12+
assert.htmlEqual(target.innerHTML, `<div>2</div><button>increment</button>`);
13+
}
14+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
let value = $state(1);
3+
</script>
4+
5+
<div {@use (node) => node.textContent = value}></div>
6+
<button onclick={() => value += 1}>increment</button>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
ssrHtml: `<div></div>`,
5+
html: `<div>DIV</div>`
6+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svelte:element this={'div'} {@use (node) => node.textContent = node.nodeName}></svelte:element>

0 commit comments

Comments
 (0)