File tree Expand file tree Collapse file tree 1 file changed +18
-11
lines changed
packages/svelte/src/compiler/phases/3-transform/client/visitors Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -172,21 +172,28 @@ export function VariableDeclaration(node, context) {
172
172
) ;
173
173
} else {
174
174
const bindings = extract_paths ( declarator . id ) ;
175
- const object_id = context . state . scope . generate ( '$$d' ) ;
176
175
177
- declarations . push (
178
- b . declarator (
179
- b . id ( object_id ) ,
180
- b . call ( '$.derived' , rune === '$derived.by' ? value : b . thunk ( value ) )
181
- )
182
- ) ;
176
+ const init = /** @type {CallExpression } */ ( declarator . init ) ;
177
+
178
+ /** @type {Identifier } */
179
+ let id ;
180
+ let rhs = value ;
181
+
182
+ if ( init . arguments [ 0 ] . type === 'Identifier' ) {
183
+ id = init . arguments [ 0 ] ;
184
+ } else {
185
+ id = b . id ( context . state . scope . generate ( '$$d' ) ) ;
186
+ rhs = b . call ( '$.get' , id ) ;
187
+
188
+ declarations . push (
189
+ b . declarator ( id , b . call ( '$.derived' , rune === '$derived.by' ? value : b . thunk ( value ) ) )
190
+ ) ;
191
+ }
192
+
183
193
for ( let i = 0 ; i < bindings . length ; i ++ ) {
184
194
const binding = bindings [ i ] ;
185
195
declarations . push (
186
- b . declarator (
187
- binding . node ,
188
- b . call ( '$.derived' , b . thunk ( binding . expression ( b . call ( '$.get' , b . id ( object_id ) ) ) ) )
189
- )
196
+ b . declarator ( binding . node , b . call ( '$.derived' , b . thunk ( binding . expression ( rhs ) ) ) )
190
197
) ;
191
198
}
192
199
}
You can’t perform that action at this time.
0 commit comments