Skip to content

feat: support latest runes ($props.id and $inspect.trace) #673

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 1 commit into from
Feb 23, 2025
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/stale-birds-win.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: support latest runes (`$props.id` and `$inspect.trace`)
20 changes: 13 additions & 7 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function analyzeRuneVariables(
continue;
}
switch (globalName) {
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2299
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2679
case "$state": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(initial: T): T",
Expand All @@ -407,7 +407,7 @@ function analyzeRuneVariables(

break;
}
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2453
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2833
case "$derived": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(expression: T): T",
Expand All @@ -417,7 +417,7 @@ function analyzeRuneVariables(
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2513
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2893
case "$effect": {
appendDeclareFunctionVirtualScripts(globalName, [
"(fn: () => void | (() => void)): void",
Expand All @@ -429,27 +429,33 @@ function analyzeRuneVariables(
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2615
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2997
case "$props": {
// Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors.
appendDeclareFunctionVirtualScripts(globalName, ["<T>(): T"]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function id(): string;",
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2626
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3038
case "$bindable": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(fallback?: T): T",
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2646
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3081
case "$inspect": {
appendDeclareFunctionVirtualScripts(globalName, [
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }`,
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function trace(name?: string): void;",
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16/packages/svelte/types/index.d.ts#L2669
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3144
case "$host": {
appendDeclareFunctionVirtualScripts(globalName, [
`<El extends HTMLElement = HTMLElement>(): El`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
const uid = $props.id();
</script>

<form>
<label for="{uid}-firstname">First Name: </label>
<input id="{uid}-firstname" type="text" />

<label for="{uid}-lastname">Last Name: </label>
<input id="{uid}-lastname" type="text" />
</form>
Loading
Loading