Skip to content

Commit

Permalink
feat: Support latest runes (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama authored Jun 15, 2024
1 parent d974c4b commit a27c8e9
Show file tree
Hide file tree
Showing 16 changed files with 5,972 additions and 299 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-ears-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: support Svelte 5.0.0-next.155. (Add `$state.is` and replace `$effect.active` with `$effect.tracking`)
19 changes: 11 additions & 8 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function analyzeRuneVariables(
continue;
}
switch (globalName) {
// See /~https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2585
// See /~https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2646
case "$state": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(initial: T): T",
Expand All @@ -332,9 +332,12 @@ function analyzeRuneVariables(
appendDeclareNamespaceVirtualScripts(globalName, [
"export function snapshot<T>(state: T): T;",
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function is(a: any, b: any): boolean;",
]);
break;
}
// See /~https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2648
// See /~https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2751
case "$derived": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(expression: T): T",
Expand All @@ -344,36 +347,36 @@ function analyzeRuneVariables(
]);
break;
}
// See /~https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2687
// See /~https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2811
case "$effect": {
appendDeclareFunctionVirtualScripts(globalName, [
"(fn: () => void | (() => void)): void",
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function pre(fn: () => void | (() => void)): void;",
"export function active(): boolean;",
"export function tracking(): boolean;",
"export function root(fn: () => void | (() => void)): () => void;",
]);
break;
}
// See /~https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2768
// See /~https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2913
case "$props": {
appendDeclareFunctionVirtualScripts(globalName, ["(): any"]);
break;
}
// See /~https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2779
// See /~https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2924
case "$bindable": {
appendDeclareFunctionVirtualScripts(globalName, ["<T>(t?: T): T"]);
break;
}
// See /~https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2799
// See /~https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2944
case "$inspect": {
appendDeclareFunctionVirtualScripts(globalName, [
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }`,
]);
break;
}
// See /~https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2822
// See /~https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2967
case "$host": {
appendDeclareFunctionVirtualScripts(globalName, [
`<El extends HTMLElement = HTMLElement>(): El`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
let count = $state(0);
let count = $state(0);
</script>

<button on:click={() => count++}>
clicks: {count}
<button on:click="{() => count++}">
clicks: {count}
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
let foo = $state({});
let bar = {};
foo.bar = bar;
console.log(foo.bar === bar); // false — `foo.bar` is a reactive proxy
console.log($state.is(foo.bar, bar)); // true
</script>
Loading

0 comments on commit a27c8e9

Please sign in to comment.