@@ -632,6 +632,15 @@ function collect_parent_each_blocks(context) {
632
632
) ;
633
633
}
634
634
635
+ /**
636
+ * Svelte legacy mode should use safe equals in most places, runes mode shouldn't
637
+ * @param {import('../types.js').ComponentClientTransformState } state
638
+ * @param {import('estree').Expression } arg
639
+ */
640
+ function create_derived ( state , arg ) {
641
+ return b . call ( state . analysis . runes ? '$.derived' : '$.derived_safe_equal' , arg ) ;
642
+ }
643
+
635
644
/**
636
645
* @param {import('#compiler').Component | import('#compiler').SvelteComponent | import('#compiler').SvelteSelf } node
637
646
* @param {string } component_name
@@ -745,7 +754,7 @@ function serialize_inline_component(node, component_name, context) {
745
754
746
755
if ( should_wrap_in_derived ) {
747
756
const id = b . id ( context . state . scope . generate ( attribute . name ) ) ;
748
- context . state . init . push ( b . var ( id , b . call ( '$.derived' , b . thunk ( value ) ) ) ) ;
757
+ context . state . init . push ( b . var ( id , create_derived ( context . state , b . thunk ( value ) ) ) ) ;
749
758
arg = b . call ( '$.get' , id ) ;
750
759
}
751
760
@@ -1649,9 +1658,8 @@ function serialize_template_literal(values, visit, state) {
1649
1658
state . init . push (
1650
1659
b . const (
1651
1660
id ,
1652
- b . call (
1653
- // In runes mode, we want things to be fine-grained - but not in legacy mode
1654
- state . analysis . runes ? '$.derived' : '$.derived_safe_equal' ,
1661
+ create_derived (
1662
+ state ,
1655
1663
b . thunk ( /** @type {import('estree').Expression } */ ( visit ( node . expression ) ) )
1656
1664
)
1657
1665
)
@@ -1701,9 +1709,8 @@ export const template_visitors = {
1701
1709
state . init . push (
1702
1710
b . const (
1703
1711
declaration . id ,
1704
- b . call (
1705
- // In runes mode, we want things to be fine-grained - but not in legacy mode
1706
- state . analysis . runes ? '$.derived' : '$.derived_safe_equal' ,
1712
+ create_derived (
1713
+ state ,
1707
1714
b . thunk ( /** @type {import('estree').Expression } */ ( visit ( declaration . init ) ) )
1708
1715
)
1709
1716
)
@@ -1738,10 +1745,7 @@ export const template_visitors = {
1738
1745
] )
1739
1746
) ;
1740
1747
1741
- state . init . push (
1742
- // In runes mode, we want things to be fine-grained - but not in legacy mode
1743
- b . const ( tmp , b . call ( state . analysis . runes ? '$.derived' : '$.derived_safe_equal' , fn ) )
1744
- ) ;
1748
+ state . init . push ( b . const ( tmp , create_derived ( state , fn ) ) ) ;
1745
1749
1746
1750
// we need to eagerly evaluate the expression in order to hit any
1747
1751
// 'Cannot access x before initialization' errors
@@ -2995,12 +2999,7 @@ export const template_visitors = {
2995
2999
const name = node . expression === null ? node . name : node . expression . name ;
2996
3000
return b . const (
2997
3001
name ,
2998
- b . call (
2999
- // in legacy mode, sources can be mutated but they're not fine-grained.
3000
- // Using the safe-equal derived version ensures the slot is still updated
3001
- state . analysis . runes ? '$.derived' : '$.derived_safe_equal' ,
3002
- b . thunk ( b . member ( b . id ( '$$slotProps' ) , b . id ( node . name ) ) )
3003
- )
3002
+ create_derived ( state , b . thunk ( b . member ( b . id ( '$$slotProps' ) , b . id ( node . name ) ) ) )
3004
3003
) ;
3005
3004
}
3006
3005
} ,
0 commit comments