From d9405037748e3ba050bd4081223841c4a4425be0 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Tue, 21 May 2024 10:57:08 +0200 Subject: [PATCH 1/2] fix: use correct semantic tokens for `$props` types --- packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts | 5 ++++- .../test/svelte2tsx/samples/ts-runes-generics/expectedv2.ts | 2 +- .../test/svelte2tsx/samples/ts-runes/expectedv2.ts | 2 +- .../expectedv2.ts | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts index fdf0ecfbf..da6bdd214 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts @@ -184,7 +184,10 @@ export class ExportedNames { generic_arg.end + this.astOffset, node.parent.pos + this.astOffset ); - this.str.appendRight(generic_arg.end + this.astOffset, this.$props.type); + this.str.appendRight( + generic_arg.end + this.astOffset, + surroundWithIgnoreComments(this.$props.type) + ); } } else { if (!this.isTsFile) { diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-generics/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-generics/expectedv2.ts index 8ee4f9c16..e2a415314 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-generics/expectedv2.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-generics/expectedv2.ts @@ -1,7 +1,7 @@ /// ;function render() { ;type $$ComponentProps = { a: T, b: string }; - let { a, b }:$$ComponentProps = $props(); + let { a, b }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props(); let x = $state(0); let y = $derived(x * 2); ; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes/expectedv2.ts index a79725a86..a4b6020df 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes/expectedv2.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes/expectedv2.ts @@ -1,7 +1,7 @@ /// ;function render() { ;type $$ComponentProps = { a: number, b: string }; - let { a, b }:$$ComponentProps = $props(); + let { a, b }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props(); let x = $state(0); let y = $derived(x * 2); ; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-sveltekit-autotypes-$props-rune-unchanged/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-sveltekit-autotypes-$props-rune-unchanged/expectedv2.ts index 6699fbec3..d9d8a85dc 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-sveltekit-autotypes-$props-rune-unchanged/expectedv2.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-sveltekit-autotypes-$props-rune-unchanged/expectedv2.ts @@ -2,7 +2,7 @@ ;function render() { const snapshot: any = {};;type $$ComponentProps = {form: boolean, data: true }; - let { form, data }:$$ComponentProps = $props(); + let { form, data }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props(); ; async () => {}; return { props: {} as any as $$ComponentProps, exports: {} as any as { snapshot: any }, slots: {}, events: {} }} From 61e7b25fc3be8e9cbf34aa1aa36e09cf99986d63 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 21 May 2024 15:04:21 +0200 Subject: [PATCH 2/2] Update packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts --- packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts index da6bdd214..73a7b6707 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts @@ -186,6 +186,7 @@ export class ExportedNames { ); this.str.appendRight( generic_arg.end + this.astOffset, + // so that semantic tokens ignore it, preventing an overlap of tokens surroundWithIgnoreComments(this.$props.type) ); }