Skip to content

Commit bbf0191

Browse files
committed
fix proxying logic
1 parent b1cc424 commit bbf0191

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { dev, is_ignored } from '../../../../state.js';
44
import * as b from '#compiler/builders';
55
import { get_rune } from '../../../scope.js';
66
import { 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);

0 commit comments

Comments
 (0)