From fc64b4c2472cd6cf212214475ae2b52caa334974 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Wed, 15 May 2024 17:44:47 +0200 Subject: [PATCH 1/5] feat: allow `as` expressions for bindable props --- packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts index fdf0ecfbf..fa1e37211 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts @@ -153,7 +153,12 @@ export class ExportedNames { : element.name.text; if (element.initializer) { - const call = element.initializer; + let call = element.initializer; + // if it's an as expression we need to check wether the as + // expression expression is a call + if (ts.isAsExpression(call)) { + call = call.expression; + } if (ts.isCallExpression(call) && ts.isIdentifier(call.expression)) { if (call.expression.text === '$bindable') { this.$props.bindings.push(name); From 7eaa2ed9de96ed51333b2e338af3892ded07a6e8 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Fri, 17 May 2024 09:49:12 +0200 Subject: [PATCH 2/5] chore: add test to ts-runes-bindable --- .../samples/ts-runes-bindable/expectedv2.ts | 20 +++++++++---------- .../samples/ts-runes-bindable/input.svelte | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts index bc9f4863e..6baa3a0be 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts @@ -1,12 +1,12 @@ /// ;function render() { -/*Ωignore_startΩ*/;type $$ComponentProps = { a: unknown, b?: unknown };/*Ωignore_endΩ*/ - let { a, b = $bindable() }: $$ComponentProps = $props(); -; -async () => {}; -return { props: {} as any as $$ComponentProps, slots: {}, events: {} }} - -export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_with_any_event(render())) { - constructor(options = __sveltets_2_runes_constructor(__sveltets_2_with_any_event(render()))) { super(options); } - $$bindings = __sveltets_$$bindings('b'); -} \ No newline at end of file + /*Ωignore_startΩ*/;type $$ComponentProps = { a: unknown, b?: unknown, c?: number };/*Ωignore_endΩ*/ + let { a, b = $bindable(), c = $bindable(0) as number }: $$ComponentProps = $props(); + ; + async () => {}; + return { props: {} as any as $$ComponentProps, slots: {}, events: {} }} + + export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_with_any_event(render())) { + constructor(options = __sveltets_2_runes_constructor(__sveltets_2_with_any_event(render()))) { super(options); } + $$bindings = __sveltets_$$bindings('b', 'c'); + } \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/input.svelte index 838402191..3e3588d2a 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/input.svelte +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/input.svelte @@ -1,3 +1,3 @@ From f17d5e969b23729744b5d2a51d06fc1da470748a Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Fri, 17 May 2024 09:53:13 +0200 Subject: [PATCH 3/5] chore: copy paste expected without formatting --- .../samples/ts-runes-bindable/expectedv2.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts index 6baa3a0be..eec37b4bb 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts @@ -1,12 +1,12 @@ /// ;function render() { - /*Ωignore_startΩ*/;type $$ComponentProps = { a: unknown, b?: unknown, c?: number };/*Ωignore_endΩ*/ - let { a, b = $bindable(), c = $bindable(0) as number }: $$ComponentProps = $props(); - ; - async () => {}; - return { props: {} as any as $$ComponentProps, slots: {}, events: {} }} - - export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_with_any_event(render())) { - constructor(options = __sveltets_2_runes_constructor(__sveltets_2_with_any_event(render()))) { super(options); } - $$bindings = __sveltets_$$bindings('b', 'c'); - } \ No newline at end of file +/*Ωignore_startΩ*/;type $$ComponentProps = { a: unknown, b?: unknown, c?: number };/*Ωignore_endΩ*/ + let { a, b = $bindable(), c = $bindable(0) as number }: $$ComponentProps = $props(); +; +async () => {}; +return { props: {} as any as $$ComponentProps, slots: {}, events: {} }} + +export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_with_any_event(render())) { + constructor(options = __sveltets_2_runes_constructor(__sveltets_2_with_any_event(render()))) { super(options); } + $$bindings = __sveltets_$$bindings('b', 'c'); +} \ No newline at end of file From 8ca2b20affadeda59c8b1b5790faa2bbf2e5e1a6 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Fri, 17 May 2024 09:57:51 +0200 Subject: [PATCH 4/5] chore: test tabs vs spaces --- .../test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts index eec37b4bb..0f7c3f59b 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-bindable/expectedv2.ts @@ -1,12 +1,12 @@ /// ;function render() { /*Ωignore_startΩ*/;type $$ComponentProps = { a: unknown, b?: unknown, c?: number };/*Ωignore_endΩ*/ - let { a, b = $bindable(), c = $bindable(0) as number }: $$ComponentProps = $props(); + let { a, b = $bindable(), c = $bindable(0) as number }: $$ComponentProps = $props(); ; async () => {}; return { props: {} as any as $$ComponentProps, slots: {}, events: {} }} export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_with_any_event(render())) { - constructor(options = __sveltets_2_runes_constructor(__sveltets_2_with_any_event(render()))) { super(options); } - $$bindings = __sveltets_$$bindings('b', 'c'); + constructor(options = __sveltets_2_runes_constructor(__sveltets_2_with_any_event(render()))) { super(options); } + $$bindings = __sveltets_$$bindings('b', 'c'); } \ No newline at end of file From ccc2a8c007c5600046a28af08fbc2f3f6ec3d04b Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Fri, 17 May 2024 11:14:41 +0200 Subject: [PATCH 5/5] chore: fix expected for svelte 5 --- .../fixtures/svelte-element-error/expected_svelte_5.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/svelte-element-error/expected_svelte_5.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/svelte-element-error/expected_svelte_5.json index 538f272bc..615d332f4 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/svelte-element-error/expected_svelte_5.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/svelte-element-error/expected_svelte_5.json @@ -3,7 +3,7 @@ "range": { "start": { "line": 4, "character": 0 }, "end": { "line": 4, "character": 0 } }, "severity": 1, "source": "ts", - "message": "`` must have a 'this' attribute", + "message": "`` must have a 'this' attribute with a value", "code": -1 } ]