-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow mutation of private derived state (#15228)
Also disallow reassignment of private derived state Fixes #15227
- Loading branch information
1 parent
7ab18bb
commit 02788f8
Showing
13 changed files
with
102 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: allow mutation of private derived state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/svelte/tests/validator/samples/mutate-derived-private-field/errors.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/validator/samples/mutate-derived-private-field/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
class Test{ | ||
#der = $derived({test: 0}); | ||
set test(v){ | ||
this.#der.test = 45; | ||
} | ||
} | ||
</script> |
14 changes: 14 additions & 0 deletions
14
packages/svelte/tests/validator/samples/reassign-derived-literal/errors.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"code": "constant_assignment", | ||
"message": "Cannot assign to derived state", | ||
"start": { | ||
"column": 3, | ||
"line": 6 | ||
}, | ||
"end": { | ||
"column": 29, | ||
"line": 6 | ||
} | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/validator/samples/reassign-derived-literal/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
class Test{ | ||
der = $derived({ test: 0 }); | ||
set test(v){ | ||
this["der"] = { test: 45 }; | ||
} | ||
} | ||
</script> |
14 changes: 14 additions & 0 deletions
14
packages/svelte/tests/validator/samples/reassign-derived-private-field/errors.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"code": "constant_assignment", | ||
"message": "Cannot assign to derived state", | ||
"start": { | ||
"column": 3, | ||
"line": 6 | ||
}, | ||
"end": { | ||
"column": 27, | ||
"line": 6 | ||
} | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/validator/samples/reassign-derived-private-field/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
class Test{ | ||
#der = $derived({ test: 0 }); | ||
set test(v){ | ||
this.#der = { test: 45 }; | ||
} | ||
} | ||
</script> |
14 changes: 14 additions & 0 deletions
14
packages/svelte/tests/validator/samples/reassign-derived-public-field/errors.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"code": "constant_assignment", | ||
"message": "Cannot assign to derived state", | ||
"start": { | ||
"column": 3, | ||
"line": 6 | ||
}, | ||
"end": { | ||
"column": 26, | ||
"line": 6 | ||
} | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/validator/samples/reassign-derived-public-field/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
class Test{ | ||
der = $derived({ test: 0 }); | ||
set test(v){ | ||
this.der = { test: 45 }; | ||
} | ||
} | ||
</script> |