Skip to content

Commit 574d260

Browse files
authored
chore: update proxy reassignment code (#13014)
1 parent e7e7ef6 commit 574d260

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,10 @@ export function build_getter(node, state) {
4747

4848
/**
4949
* @param {Expression} value
50-
* @param {PrivateIdentifier | string} proxy_reference
50+
* @param {Expression} previous
5151
*/
52-
export function build_proxy_reassignment(value, proxy_reference) {
53-
return dev
54-
? b.call(
55-
'$.proxy',
56-
value,
57-
b.null,
58-
typeof proxy_reference === 'string'
59-
? b.id(proxy_reference)
60-
: b.member(b.this, proxy_reference)
61-
)
62-
: b.call('$.proxy', value);
52+
export function build_proxy_reassignment(value, previous) {
53+
return dev ? b.call('$.proxy', value, b.null, previous) : b.call('$.proxy', value);
6354
}
6455

6556
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function build_assignment(operator, left, right, context) {
4848
value =
4949
private_state.kind === 'raw_state'
5050
? value
51-
: build_proxy_reassignment(value, private_state.id);
51+
: build_proxy_reassignment(value, b.member(b.this, private_state.id));
5252
}
5353

5454
if (!context.state.in_constructor) {
@@ -95,7 +95,7 @@ function build_assignment(operator, left, right, context) {
9595
context.state.analysis.runes &&
9696
should_proxy(value, context.state.scope)
9797
) {
98-
value = binding.kind === 'raw_state' ? value : build_proxy_reassignment(value, object.name);
98+
value = binding.kind === 'raw_state' ? value : build_proxy_reassignment(value, object);
9999
}
100100

101101
return transform.assign(object, value);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ export function ClassBody(node, context) {
139139
if (field.kind === 'state') {
140140
// set foo(value) { this.#foo = value; }
141141
const value = b.id('value');
142+
const prev = b.member(b.this, field.id);
143+
142144
body.push(
143145
b.method(
144146
'set',
145147
definition.key,
146148
[value],
147-
[b.stmt(b.call('$.set', member, build_proxy_reassignment(value, field.id)))]
149+
[b.stmt(b.call('$.set', member, build_proxy_reassignment(value, prev)))]
148150
)
149151
);
150152
}

0 commit comments

Comments
 (0)