Skip to content

Commit 152fe50

Browse files
committed
add test, fix more stuff
1 parent 7e0a81d commit 152fe50

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ function build_assignment(operator, left, right, context) {
4949
/** @type {Expression} */ (context.visit(right))
5050
);
5151
}
52-
} else if (field && (field.type === '$derived' || field.type === '$derived.by')) {
53-
let value = /** @type {Expression} */ (
54-
context.visit(build_assignment_value(operator, left, right))
55-
);
56-
return b.call(b.member(b.this, name), value);
5752
}
5853
}
5954

packages/svelte/tests/snapshot/samples/class-state-field-constructor-assignment/_expected/client/index.svelte.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function Class_state_field_constructor_assignment($$anchor, $$pro
55
$.push($$props, true);
66

77
class Foo {
8-
#a = $.state();
8+
#a = $.state(0);
99

1010
get a() {
1111
return $.get(this.#a);
@@ -16,10 +16,31 @@ export default function Class_state_field_constructor_assignment($$anchor, $$pro
1616
}
1717

1818
#b = $.state();
19+
#foo = $.derived(() => ({ bar: this.a * 2 }));
20+
21+
get foo() {
22+
return $.get(this.#foo);
23+
}
24+
25+
set foo(value) {
26+
$.set(this.#foo, value);
27+
}
28+
29+
#bar = $.derived(() => ({ baz: this.foo }));
30+
31+
get bar() {
32+
return $.get(this.#bar);
33+
}
34+
35+
set bar(value) {
36+
$.set(this.#bar, value);
37+
}
1938

2039
constructor() {
2140
this.a = 1;
2241
$.set(this.#b, 2);
42+
this.foo.bar = 3;
43+
this.bar = 4;
2344
}
2445
}
2546

packages/svelte/tests/snapshot/samples/class-state-field-constructor-assignment/_expected/server/index.svelte.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,33 @@ export default function Class_state_field_constructor_assignment($$payload, $$pr
44
$.push();
55

66
class Foo {
7-
a;
7+
a = 0;
88
#b;
9+
#foo = $.derived(() => ({ bar: this.a * 2 }));
10+
11+
get foo() {
12+
return this.#foo();
13+
}
14+
15+
set foo($$value) {
16+
return this.#foo($$value);
17+
}
18+
19+
#bar = $.derived(() => ({ baz: this.foo }));
20+
21+
get bar() {
22+
return this.#bar();
23+
}
24+
25+
set bar($$value) {
26+
return this.#bar($$value);
27+
}
928

1029
constructor() {
1130
this.a = 1;
1231
this.#b = 2;
32+
this.foo.bar = 3;
33+
this.bar = 4;
1334
}
1435
}
1536

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<script>
22
class Foo {
3-
a = $state();
3+
a = $state(0);
44
#b = $state();
5-
5+
foo = $derived({ bar: this.a * 2 });
6+
bar = $derived({ baz: this.foo });
67
constructor() {
78
this.a = 1;
89
this.#b = 2;
10+
this.foo.bar = 3;
11+
this.bar = 4;
912
}
1013
}
1114
</script>

0 commit comments

Comments
 (0)