File tree Expand file tree Collapse file tree 4 files changed +49
-0
lines changed
src/compiler/phases/3-transform/client/visitors
tests/runtime-runes/samples/element-is-attribute Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " svelte " : patch
3
+ ---
4
+
5
+ fix: handle ` is ` attribute on elements with spread
Original file line number Diff line number Diff line change @@ -278,6 +278,15 @@ function serialize_element_spread_attributes(
278
278
// TODO: handle contains_call_expression
279
279
const [ , value ] = serialize_attribute_value ( attribute . value , context ) ;
280
280
281
+ if (
282
+ name === 'is' &&
283
+ value . type === 'Literal' &&
284
+ context . state . metadata . namespace === 'html'
285
+ ) {
286
+ context . state . template . push ( ` is="${ escape_html ( value . value , true ) } "` ) ;
287
+ continue ;
288
+ }
289
+
281
290
if (
282
291
is_event_attribute ( attribute ) &&
283
292
( attribute . value [ 0 ] . expression . type === 'ArrowFunctionExpression' ||
Original file line number Diff line number Diff line change
1
+ import { flushSync } from 'svelte' ;
2
+ import { test } from '../../test' ;
3
+
4
+ export default test ( {
5
+ mode : [ 'client' ] ,
6
+ test ( { assert, target, logs } ) {
7
+ const [ b1 , b2 ] = target . querySelectorAll ( 'button' ) ;
8
+
9
+ b1 . click ( ) ;
10
+ flushSync ( ) ;
11
+ assert . deepEqual ( logs , [ 'works' ] ) ;
12
+
13
+ b2 . click ( ) ;
14
+ flushSync ( ) ;
15
+ assert . deepEqual ( logs , [ 'works' , 'works' ] ) ;
16
+ }
17
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" context =" module" >
2
+ if (! customElements .get (' x-button' )) {
3
+ class XButton extends HTMLButtonElement {
4
+ connectedCallback() {
5
+ this .addEventListener (' click' , () => console .log (' works' ));
6
+ }
7
+ }
8
+
9
+ customElements .define (' x-button' , XButton , { extends: ' button' });
10
+ }
11
+ </script >
12
+
13
+ <script lang =" ts" >
14
+ let { ... props } = $props ();
15
+ </script >
16
+
17
+ <button is =" x-button" >click me</button >
18
+ <button {...props } is =" x-button" >click me</button >
You can’t perform that action at this time.
0 commit comments