Skip to content

Commit a27c8e9

Browse files
authored
feat: Support latest runes (#534)
1 parent d974c4b commit a27c8e9

16 files changed

+5972
-299
lines changed

.changeset/polite-ears-move.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": minor
3+
---
4+
5+
feat: support Svelte 5.0.0-next.155. (Add `$state.is` and replace `$effect.active` with `$effect.tracking`)

src/parser/typescript/analyze/index.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function analyzeRuneVariables(
319319
continue;
320320
}
321321
switch (globalName) {
322-
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2585
322+
// See https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2646
323323
case "$state": {
324324
appendDeclareFunctionVirtualScripts(globalName, [
325325
"<T>(initial: T): T",
@@ -332,9 +332,12 @@ function analyzeRuneVariables(
332332
appendDeclareNamespaceVirtualScripts(globalName, [
333333
"export function snapshot<T>(state: T): T;",
334334
]);
335+
appendDeclareNamespaceVirtualScripts(globalName, [
336+
"export function is(a: any, b: any): boolean;",
337+
]);
335338
break;
336339
}
337-
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2648
340+
// See https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2751
338341
case "$derived": {
339342
appendDeclareFunctionVirtualScripts(globalName, [
340343
"<T>(expression: T): T",
@@ -344,36 +347,36 @@ function analyzeRuneVariables(
344347
]);
345348
break;
346349
}
347-
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2687
350+
// See https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2811
348351
case "$effect": {
349352
appendDeclareFunctionVirtualScripts(globalName, [
350353
"(fn: () => void | (() => void)): void",
351354
]);
352355
appendDeclareNamespaceVirtualScripts(globalName, [
353356
"export function pre(fn: () => void | (() => void)): void;",
354-
"export function active(): boolean;",
357+
"export function tracking(): boolean;",
355358
"export function root(fn: () => void | (() => void)): () => void;",
356359
]);
357360
break;
358361
}
359-
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2768
362+
// See https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2913
360363
case "$props": {
361364
appendDeclareFunctionVirtualScripts(globalName, ["(): any"]);
362365
break;
363366
}
364-
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2779
367+
// See https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2924
365368
case "$bindable": {
366369
appendDeclareFunctionVirtualScripts(globalName, ["<T>(t?: T): T"]);
367370
break;
368371
}
369-
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2799
372+
// See https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2944
370373
case "$inspect": {
371374
appendDeclareFunctionVirtualScripts(globalName, [
372375
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }`,
373376
]);
374377
break;
375378
}
376-
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2822
379+
// See https://github.com/sveltejs/svelte/blob/ccb3c90cd57ca9d764efab317ed1cb8e5282926e/packages/svelte/types/index.d.ts#L2967
377380
case "$host": {
378381
appendDeclareFunctionVirtualScripts(globalName, [
379382
`<El extends HTMLElement = HTMLElement>(): El`,
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
2-
let count = $state(0);
2+
let count = $state(0);
33
</script>
44

5-
<button on:click={() => count++}>
6-
clicks: {count}
5+
<button on:click="{() => count++}">
6+
clicks: {count}
77
</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let foo = $state({});
3+
let bar = {};
4+
5+
foo.bar = bar;
6+
7+
console.log(foo.bar === bar); // false — `foo.bar` is a reactive proxy
8+
console.log($state.is(foo.bar, bar)); // true
9+
</script>

0 commit comments

Comments
 (0)