File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
packages/svelte/src/compiler/phases/3-transform/client/visitors Expand file tree Collapse file tree 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';
44import * as b from '#compiler/builders' ;
55import { get_rune } from '../../../scope.js' ;
66import { transform_inspect_rune } from '../../utils.js' ;
7+ import { should_proxy } from '../utils.js' ;
78
89/**
910 * @param {CallExpression } node
@@ -19,15 +20,23 @@ export function CallExpression(node, context) {
1920 case '$effect.tracking' :
2021 return b . call ( '$.effect_tracking' ) ;
2122
22- // TODO can we reuse this logic for normal declarations, i.e. fall through to this?
23+ // transform state field assignments in constructors
2324 case '$state' :
2425 case '$state.raw' : {
25- let should_proxy = rune === '$state' && true ; // TODO
26+ let arg = node . arguments [ 0 ] ;
2627
27- let value = node . arguments [ 0 ] && /** @type {Expression } */ ( context . visit ( node . arguments [ 0 ] ) ) ;
28+ /** @type {Expression | undefined } */
29+ let value = undefined ;
2830
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+ }
3140 }
3241
3342 return b . call ( '$.state' , value ) ;
You can’t perform that action at this time.
0 commit comments