Skip to content

Commit

Permalink
feat: add support for $derived.by type (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Feb 25, 2024
1 parent f3761c5 commit 850ad74
Show file tree
Hide file tree
Showing 10 changed files with 11,027 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-teachers-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: add support for `$derived.by` type
3 changes: 3 additions & 0 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ function analyzeRuneVariables(
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(expression: T): T",
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function by<T>(fn: () => T): T;",
]);
break;
}
case "$effect": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
let numbers = $state([1, 2, 3]);
let total = $derived.by(() => {
let total = 0;
for (const n of numbers) {
total += n;
}
return total;
});
</script>

<button on:click={() => numbers.push(numbers.length + 1)}>
{numbers.join(' + ')} = {total}
</button>

0 comments on commit 850ad74

Please sign in to comment.