Skip to content

Commit c44f35b

Browse files
committed
feat: add $state.eager
1 parent 0aceb9e commit c44f35b

File tree

7 files changed

+8264
-3
lines changed

7 files changed

+8264
-3
lines changed

.changeset/green-keys-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": minor
3+
---
4+
5+
feat: add `$state.eager`

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
"prettier-plugin-svelte": "^3.4.0",
108108
"rimraf": "^6.0.1",
109109
"semver": "^7.7.2",
110-
"svelte": "^5.38.8",
111-
"svelte2tsx": "^0.7.42",
110+
"svelte": "^5.41.0",
111+
"svelte2tsx": "^0.7.45",
112112
"tsx": "^4.20.5",
113113
"typescript": "~5.9.2",
114114
"typescript-eslint": "^8.43.0",

src/parser/typescript/analyze/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,15 @@ function analyzeRuneVariables(
399399
continue;
400400
}
401401
switch (globalName) {
402-
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3093
402+
// See https://github.com/sveltejs/svelte/blob/bd2d3db6d0d7a931c2e84c38a5c537e30dda1dbe/packages/svelte/types/index.d.ts#L3124
403403
case "$state": {
404404
appendDeclareFunctionVirtualScripts(globalName, [
405405
"<T>(initial: T): T",
406406
"<T>(): T | undefined",
407407
]);
408+
appendDeclareNamespaceVirtualScripts(globalName, [
409+
"export function eager<T>(value: T): T",
410+
]);
408411
appendDeclareNamespaceVirtualScripts(globalName, [
409412
"export function raw<T>(initial: T): T;",
410413
"export function raw<T>(): T | undefined;",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"svelteFeatures": {
3+
"runes": true
4+
}
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
let a = $state(1);
3+
let b = $state(2);
4+
5+
async function add(a, b) {
6+
await new Promise((f) => setTimeout(f, 500)); // artificial delay
7+
return a + b;
8+
}
9+
</script>
10+
11+
<button onclick={() => a++}>a++</button>
12+
<button onclick={() => b++}>b++</button>
13+
14+
<p>{$state.eager(a)} + {$state.eager(b)} = {await add(a, b)}</p>
15+
16+
{#if $effect.pending()}
17+
<p>pending promises: {$effect.pending()}</p>
18+
{/if}

0 commit comments

Comments
 (0)