Skip to content

feat: Support latest runes #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 15, 2024
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/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
Loading