Skip to content

Commit 850ad74

Browse files
authored
feat: add support for $derived.by type (#479)
1 parent f3761c5 commit 850ad74

10 files changed

+11027
-0
lines changed

.changeset/rare-teachers-search.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": minor
3+
---
4+
5+
feat: add support for `$derived.by` type

src/parser/typescript/analyze/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ function analyzeRuneVariables(
328328
appendDeclareFunctionVirtualScripts(globalName, [
329329
"<T>(expression: T): T",
330330
]);
331+
appendDeclareNamespaceVirtualScripts(globalName, [
332+
"export function by<T>(fn: () => T): T;",
333+
]);
331334
break;
332335
}
333336
case "$effect": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script>
2+
let numbers = $state([1, 2, 3]);
3+
let total = $derived.by(() => {
4+
let total = 0;
5+
for (const n of numbers) {
6+
total += n;
7+
}
8+
return total;
9+
});
10+
</script>
11+
12+
<button on:click={() => numbers.push(numbers.length + 1)}>
13+
{numbers.join(' + ')} = {total}
14+
</button>

0 commit comments

Comments
 (0)