Skip to content

Commit 536e508

Browse files
committed
more replacements, plus a compiler error
1 parent eafa367 commit 536e508

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

.changeset/dirty-donuts-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
breaking: replace `$derived.call` with `$derived.by`

packages/svelte/src/compiler/errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ const runes = {
208208
'invalid-runes-mode-import': (name) => `${name} cannot be used in runes mode`,
209209
'duplicate-props-rune': () => `Cannot use $props() more than once`,
210210
'invalid-each-assignment': () =>
211-
`Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. 'array[i] = value' instead of 'entry = value')`
211+
`Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. 'array[i] = value' instead of 'entry = value')`,
212+
'invalid-derived-call': () => `$derived.call(...) has been replaced with $derived.by(...)`
212213
};
213214

214215
/** @satisfies {Errors} */

packages/svelte/src/compiler/phases/scope.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ export function get_rune(node, scope) {
717717
if (n.type !== 'Identifier') return null;
718718

719719
joined = n.name + joined;
720+
721+
if (joined === '$derived.call') error(node, 'invalid-derived-call');
720722
if (!Runes.includes(/** @type {any} */ (joined))) return null;
721723

722724
const binding = scope.get(n.name);

sites/svelte-5-preview/src/lib/CodeMirror.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@
208208
{ label: '$state', type: 'keyword', boost: 10 },
209209
{ label: '$props', type: 'keyword', boost: 9 },
210210
{ label: '$derived', type: 'keyword', boost: 8 },
211-
snip('$derived.call(() => {\n\t${}\n});', {
212-
label: '$derived.call',
211+
snip('$derived.by(() => {\n\t${}\n});', {
212+
label: '$derived.by',
213213
type: 'keyword',
214214
boost: 7
215215
}),

sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ If the value of a reactive variable is being computed it should be replaced with
134134
```
135135
...`double` will be calculated first despite the source order. In runes mode, `triple` cannot reference `double` before it has been declared.
136136

137-
## `$derived.call`
137+
## `$derived.by`
138138

139-
Sometimes you need to create complex derivations that don't fit inside a short expression. In these cases, you can use `$derived.call` which accepts a function as its argument.
139+
Sometimes you need to create complex derivations that don't fit inside a short expression. In these cases, you can use `$derived.by` which accepts a function as its argument.
140140

141141
```svelte
142142
<script>
143143
let numbers = $state([1, 2, 3]);
144-
let total = $derived.call(() => {
144+
let total = $derived.by(() => {
145145
let total = 0;
146146
for (const n of numbers) {
147147
total += n;
@@ -155,7 +155,7 @@ Sometimes you need to create complex derivations that don't fit inside a short e
155155
</button>
156156
```
157157

158-
In essence, `$derived(expression)` is equivalent to `$derived.call(() => expression)`.
158+
In essence, `$derived(expression)` is equivalent to `$derived.by(() => expression)`.
159159

160160
## `$effect`
161161

0 commit comments

Comments
 (0)