@@ -756,7 +756,20 @@ function serialize_inline_component(node, component_name, context) {
756
756
}
757
757
events [ attribute . name ] . push ( handler ) ;
758
758
} else if ( attribute . type === 'SpreadAttribute' ) {
759
- props_and_spreads . push ( /** @type {import('estree').Expression } */ ( context . visit ( attribute ) ) ) ;
759
+ const expression = /** @type {import('estree').Expression } */ ( context . visit ( attribute ) ) ;
760
+ if ( attribute . metadata . dynamic ) {
761
+ let value = expression ;
762
+
763
+ if ( attribute . metadata . contains_call_expression ) {
764
+ const id = b . id ( context . state . scope . generate ( 'spread_element' ) ) ;
765
+ context . state . init . push ( b . var ( id , b . call ( '$.derived' , b . thunk ( value ) ) ) ) ;
766
+ value = b . call ( '$.get' , id ) ;
767
+ }
768
+
769
+ props_and_spreads . push ( b . thunk ( value ) ) ;
770
+ } else {
771
+ props_and_spreads . push ( expression ) ;
772
+ }
760
773
} else if ( attribute . type === 'Attribute' ) {
761
774
if ( attribute . name . startsWith ( '--' ) ) {
762
775
custom_css_props . push (
@@ -895,7 +908,7 @@ function serialize_inline_component(node, component_name, context) {
895
908
? b . object ( /** @type {import('estree').Property[] } */ ( props_and_spreads [ 0 ] ) || [ ] )
896
909
: b . call (
897
910
'$.spread_props' ,
898
- b . thunk ( b . array ( props_and_spreads . map ( ( p ) => ( Array . isArray ( p ) ? b . object ( p ) : p ) ) ) )
911
+ ... props_and_spreads . map ( ( p ) => ( Array . isArray ( p ) ? b . object ( p ) : p ) )
899
912
) ;
900
913
/** @param {import('estree').Identifier } node_id */
901
914
let fn = ( node_id ) =>
@@ -2764,8 +2777,8 @@ export const template_visitors = {
2764
2777
}
2765
2778
} ,
2766
2779
LetDirective ( node , { state } ) {
2767
- // let:x --> const x = $.derived(() => $.unwrap($$ slotProps) .x);
2768
- // let:x={{y, z}} --> const derived_x = $.derived(() => { const { y, z } = $.unwrap($$ slotProps) .x; return { y, z }));
2780
+ // let:x --> const x = $.derived(() => $$ slotProps.x);
2781
+ // let:x={{y, z}} --> const derived_x = $.derived(() => { const { y, z } = $$ slotProps.x; return { y, z }));
2769
2782
if ( node . expression && node . expression . type !== 'Identifier' ) {
2770
2783
const name = state . scope . generate ( node . name ) ;
2771
2784
const bindings = state . scope . get_bindings ( node ) ;
@@ -2787,7 +2800,7 @@ export const template_visitors = {
2787
2800
b . object_pattern ( node . expression . properties )
2788
2801
: // @ts -expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
2789
2802
b . array_pattern ( node . expression . elements ) ,
2790
- b . member ( b . call ( '$.unwrap' , b . id ( '$$slotProps' ) ) , b . id ( node . name ) )
2803
+ b . member ( b . id ( '$$slotProps' ) , b . id ( node . name ) )
2791
2804
) ,
2792
2805
b . return ( b . object ( bindings . map ( ( binding ) => b . init ( binding . node . name , binding . node ) ) ) )
2793
2806
] )
@@ -2798,10 +2811,7 @@ export const template_visitors = {
2798
2811
const name = node . expression === null ? node . name : node . expression . name ;
2799
2812
return b . const (
2800
2813
name ,
2801
- b . call (
2802
- '$.derived' ,
2803
- b . thunk ( b . member ( b . call ( '$.unwrap' , b . id ( '$$slotProps' ) ) , b . id ( node . name ) ) )
2804
- )
2814
+ b . call ( '$.derived' , b . thunk ( b . member ( b . id ( '$$slotProps' ) , b . id ( node . name ) ) ) )
2805
2815
) ;
2806
2816
}
2807
2817
} ,
@@ -2854,7 +2864,9 @@ export const template_visitors = {
2854
2864
2855
2865
for ( const attribute of node . attributes ) {
2856
2866
if ( attribute . type === 'SpreadAttribute' ) {
2857
- spreads . push ( /** @type {import('estree').Expression } */ ( context . visit ( attribute ) ) ) ;
2867
+ spreads . push (
2868
+ b . thunk ( /** @type {import('estree').Expression } */ ( context . visit ( attribute ) ) )
2869
+ ) ;
2858
2870
} else if ( attribute . type === 'Attribute' ) {
2859
2871
const [ , value ] = serialize_attribute_value ( attribute . value , context ) ;
2860
2872
if ( attribute . name === 'name' ) {
@@ -2873,7 +2885,7 @@ export const template_visitors = {
2873
2885
const props_expression =
2874
2886
spreads . length === 0
2875
2887
? b . object ( props )
2876
- : b . call ( '$.spread_props' , b . thunk ( b . array ( [ b . object ( props ) , ...spreads ] ) ) ) ;
2888
+ : b . call ( '$.spread_props' , b . object ( props ) , ...spreads ) ;
2877
2889
const fallback =
2878
2890
node . fragment . nodes . length === 0
2879
2891
? b . literal ( null )
@@ -2883,8 +2895,8 @@ export const template_visitors = {
2883
2895
) ;
2884
2896
2885
2897
const expression = is_default
2886
- ? b . member ( b . call ( '$.unwrap' , b . id ( '$$props' ) ) , b . id ( 'children' ) )
2887
- : b . member ( b . member ( b . call ( '$.unwrap' , b . id ( '$$props' ) ) , b . id ( '$$slots' ) ) , name , true , true ) ;
2898
+ ? b . member ( b . id ( '$$props' ) , b . id ( 'children' ) )
2899
+ : b . member ( b . member ( b . id ( '$$props' ) , b . id ( '$$slots' ) ) , name , true , true ) ;
2888
2900
2889
2901
const slot = b . call ( '$.slot' , context . state . node , expression , props_expression , fallback ) ;
2890
2902
context . state . init . push ( b . stmt ( slot ) ) ;
0 commit comments