Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-keys-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: add `$state.eager`
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
"prettier-plugin-svelte": "^3.4.0",
"rimraf": "^6.0.1",
"semver": "^7.7.2",
"svelte": "^5.38.8",
"svelte2tsx": "^0.7.42",
"svelte": "^5.41.0",
"svelte2tsx": "^0.7.45",
"tsx": "^4.20.5",
"typescript": "~5.9.2",
"typescript-eslint": "^8.43.0",
Expand Down
5 changes: 4 additions & 1 deletion src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,15 @@ function analyzeRuneVariables(
continue;
}
switch (globalName) {
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3093
// See https://github.com/sveltejs/svelte/blob/bd2d3db6d0d7a931c2e84c38a5c537e30dda1dbe/packages/svelte/types/index.d.ts#L3124
case "$state": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(initial: T): T",
"<T>(): T | undefined",
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function eager<T>(value: T): T",
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function raw<T>(initial: T): T;",
"export function raw<T>(): T | undefined;",
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/parser/ast/svelte5/$state-eager-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"svelteFeatures": {
"runes": true
}
}
18 changes: 18 additions & 0 deletions tests/fixtures/parser/ast/svelte5/$state-eager-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
let a = $state(1);
let b = $state(2);

async function add(a, b) {
await new Promise((f) => setTimeout(f, 500)); // artificial delay
return a + b;
}
</script>

<button onclick={() => a++}>a++</button>
<button onclick={() => b++}>b++</button>

<p>{$state.eager(a)} + {$state.eager(b)} = {await add(a, b)}</p>

{#if $effect.pending()}
<p>pending promises: {$effect.pending()}</p>
{/if}
Loading
Loading