File tree 1 file changed +14
-5
lines changed
packages/svelte/src/compiler/phases/3-transform/client/visitors 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { dev, is_ignored } from '../../../../state.js';
4
4
import * as b from '#compiler/builders' ;
5
5
import { get_rune } from '../../../scope.js' ;
6
6
import { transform_inspect_rune } from '../../utils.js' ;
7
+ import { should_proxy } from '../utils.js' ;
7
8
8
9
/**
9
10
* @param {CallExpression } node
@@ -19,15 +20,23 @@ export function CallExpression(node, context) {
19
20
case '$effect.tracking' :
20
21
return b . call ( '$.effect_tracking' ) ;
21
22
22
- // TODO can we reuse this logic for normal declarations, i.e. fall through to this?
23
+ // transform state field assignments in constructors
23
24
case '$state' :
24
25
case '$state.raw' : {
25
- let should_proxy = rune === '$state' && true ; // TODO
26
+ let arg = node . arguments [ 0 ] ;
26
27
27
- let value = node . arguments [ 0 ] && /** @type {Expression } */ ( context . visit ( node . arguments [ 0 ] ) ) ;
28
+ /** @type {Expression | undefined } */
29
+ let value = undefined ;
28
30
29
- if ( value && should_proxy ) {
30
- value = b . call ( '$.proxy' , value ) ;
31
+ if ( arg ) {
32
+ value = /** @type {Expression } */ ( context . visit ( node . arguments [ 0 ] ) ) ;
33
+
34
+ if (
35
+ rune === '$state' &&
36
+ should_proxy ( /** @type {Expression } */ ( arg ) , context . state . scope )
37
+ ) {
38
+ value = b . call ( '$.proxy' , value ) ;
39
+ }
31
40
}
32
41
33
42
return b . call ( '$.state' , value ) ;
You can’t perform that action at this time.
0 commit comments