@@ -19,6 +19,7 @@ import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
19
19
import { validate_component_options } from '../validate-options.js' ;
20
20
import { is_reserved , is_svg , is_void } from '../../utils.js' ;
21
21
import { regex_is_valid_identifier } from '../phases/patterns.js' ;
22
+ import { VERSION } from 'svelte/compiler' ;
22
23
23
24
const regex_style_tags = / ( < s t y l e [ ^ > ] + > ) ( [ \S \s ] * ?) ( < \/ s t y l e > ) / g;
24
25
const style_placeholder = '/*$$__STYLE_CONTENT__$$*/' ;
@@ -113,6 +114,16 @@ function find_closing_parenthesis(start, code) {
113
114
return end ;
114
115
}
115
116
117
+ function check_support_writable_deriveds ( ) {
118
+ const [ major , minor , patch ] = VERSION . split ( '.' ) ;
119
+
120
+ if ( + major < 5 ) return false ;
121
+ if ( + minor < 25 ) return false ;
122
+ return true ;
123
+ }
124
+
125
+ const support_writable_derived = check_support_writable_deriveds ( ) ;
126
+
116
127
/**
117
128
* Does a best-effort migration of Svelte code towards using runes, event attributes and render tags.
118
129
* May throw an error if the code is too complex to migrate automatically.
@@ -952,7 +963,11 @@ const instance_script = {
952
963
const reassigned_bindings = bindings . filter ( ( b ) => b ?. reassigned ) ;
953
964
954
965
if (
955
- reassigned_bindings . length === 0 &&
966
+ // on version 5.25.0 deriveds are writable so we can use them even if
967
+ // reassigned (but if the right side is a literal we want to use `$state`)
968
+ ( support_writable_derived
969
+ ? node . body . expression . right . type !== 'Literal'
970
+ : reassigned_bindings . length === 0 ) &&
956
971
! bindings . some ( ( b ) => b ?. kind === 'store_sub' ) &&
957
972
node . body . expression . left . type !== 'MemberExpression'
958
973
) {
0 commit comments