Skip to content

Commit

Permalink
feat: add $state.frozen support (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama authored Jan 21, 2024
1 parent e27a3de commit d5b3322
Show file tree
Hide file tree
Showing 10 changed files with 12,338 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-kangaroos-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

feat: add `$state.frozen` support
4 changes: 4 additions & 0 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ function analyzeRuneVariables(
"<T>(initial: T): T",
"<T>(): T | undefined",
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function frozen<T>(initial: T): Readonly<T>;",
"export function frozen<T>(): Readonly<T> | undefined;",
]);
break;
}
case "$derived": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
let numbers = $state.frozen([1, 2, 3]);
</script>

<button onclick="{() => (numbers = [...numbers, numbers.length + 1])}">
push
</button>

<button onclick="{() => (numbers = numbers.slice(0, -1))}"> pop </button>

<p>
{numbers.join(" + ") || 0}
=
{numbers.reduce((a, b) => a + b, 0)}
</p>
Loading

0 comments on commit d5b3322

Please sign in to comment.