Skip to content

Commit cab2fd2

Browse files
authored
feat: support latest runes ($props.id and $inspect.trace) (#673)
1 parent 573169f commit cab2fd2

File tree

8 files changed

+8193
-7
lines changed

8 files changed

+8193
-7
lines changed

.changeset/stale-birds-win.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: support latest runes (`$props.id` and `$inspect.trace`)

src/parser/typescript/analyze/index.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ function analyzeRuneVariables(
391391
continue;
392392
}
393393
switch (globalName) {
394-
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2299
394+
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2679
395395
case "$state": {
396396
appendDeclareFunctionVirtualScripts(globalName, [
397397
"<T>(initial: T): T",
@@ -407,7 +407,7 @@ function analyzeRuneVariables(
407407

408408
break;
409409
}
410-
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2453
410+
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2833
411411
case "$derived": {
412412
appendDeclareFunctionVirtualScripts(globalName, [
413413
"<T>(expression: T): T",
@@ -417,7 +417,7 @@ function analyzeRuneVariables(
417417
]);
418418
break;
419419
}
420-
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2513
420+
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2893
421421
case "$effect": {
422422
appendDeclareFunctionVirtualScripts(globalName, [
423423
"(fn: () => void | (() => void)): void",
@@ -429,27 +429,33 @@ function analyzeRuneVariables(
429429
]);
430430
break;
431431
}
432-
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2615
432+
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2997
433433
case "$props": {
434434
// Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors.
435435
appendDeclareFunctionVirtualScripts(globalName, ["<T>(): T"]);
436+
appendDeclareNamespaceVirtualScripts(globalName, [
437+
"export function id(): string;",
438+
]);
436439
break;
437440
}
438-
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2626
441+
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3038
439442
case "$bindable": {
440443
appendDeclareFunctionVirtualScripts(globalName, [
441444
"<T>(fallback?: T): T",
442445
]);
443446
break;
444447
}
445-
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2646
448+
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3081
446449
case "$inspect": {
447450
appendDeclareFunctionVirtualScripts(globalName, [
448451
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }`,
449452
]);
453+
appendDeclareNamespaceVirtualScripts(globalName, [
454+
"export function trace(name?: string): void;",
455+
]);
450456
break;
451457
}
452-
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2669
458+
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3144
453459
case "$host": {
454460
appendDeclareFunctionVirtualScripts(globalName, [
455461
`<El extends HTMLElement = HTMLElement>(): El`,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
const uid = $props.id();
3+
</script>
4+
5+
<form>
6+
<label for="{uid}-firstname">First Name: </label>
7+
<input id="{uid}-firstname" type="text" />
8+
9+
<label for="{uid}-lastname">Last Name: </label>
10+
<input id="{uid}-lastname" type="text" />
11+
</form>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy