From 719f17be66e1a1b0f0eedac70c65a5759e2c6577 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:22:57 +0200 Subject: [PATCH] fix: add legacy methods to own component shape (#2451) see https://github.com/sveltejs/svelte/pull/12666 for why we need this --- packages/svelte2tsx/src/svelte2tsx/addComponentExport.ts | 2 +- packages/svelte2tsx/svelte-shims-v4.d.ts | 2 +- .../javascript-runes.v5/expected/TestRunes.svelte.d.ts | 5 ++++- .../typescript-runes.v5/expected/TestRunes.svelte.d.ts | 5 ++++- .../test/svelte2tsx/samples/creates-dts/expected-svelte5.ts | 2 +- .../samples/creates-no-script-dts/expected-svelte5.ts | 2 +- .../samples/transforms-interfaces-dts/expected-svelte5.ts | 2 +- .../svelte2tsx/samples/ts-creates-dts/expected-svelte5.ts | 2 +- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/addComponentExport.ts b/packages/svelte2tsx/src/svelte2tsx/addComponentExport.ts index 39d14ad4e..4cbf2b980 100644 --- a/packages/svelte2tsx/src/svelte2tsx/addComponentExport.ts +++ b/packages/svelte2tsx/src/svelte2tsx/addComponentExport.ts @@ -167,7 +167,7 @@ function addSimpleComponentExport({ statement = `\ninterface $$__sveltets_2_IsomorphicComponent = any, Events extends Record = any, Slots extends Record = any, Exports = {}, Bindings = string> { new (options: import('svelte').ComponentConstructorOptions): import('svelte').SvelteComponent & { $$bindings?: Bindings } & Exports; - (internal: unknown, props: ${!canHaveAnyProp && exportedNames.hasNoProps() ? '{$$events?: Events, $$slots?: Slots}' : 'Props & {$$events?: Events, $$slots?: Slots}'}): Exports; + (internal: unknown, props: ${!canHaveAnyProp && exportedNames.hasNoProps() ? '{$$events?: Events, $$slots?: Slots}' : 'Props & {$$events?: Events, $$slots?: Slots}'}): Exports & { $set?: any, $on?: any }; z_$$bindings?: Bindings; }\n` + (usesSlots diff --git a/packages/svelte2tsx/svelte-shims-v4.d.ts b/packages/svelte2tsx/svelte-shims-v4.d.ts index 032c9b589..e8e276255 100644 --- a/packages/svelte2tsx/svelte-shims-v4.d.ts +++ b/packages/svelte2tsx/svelte-shims-v4.d.ts @@ -243,7 +243,7 @@ declare function __sveltets_$$bindings(...bindings: B interface __sveltets_2_IsomorphicComponent = any, Events extends Record = any, Slots extends Record = any, Exports = {}, Bindings = string> { new (options: import('svelte').ComponentConstructorOptions): import('svelte').SvelteComponent & { $$bindings?: Bindings } & Exports; - (internal: unknown, props: Props extends Record ? {$$events?: Events, $$slots?: Slots} : Props & {$$events?: Events, $$slots?: Slots}): Exports; + (internal: unknown, props: Props extends Record ? {$$events?: Events, $$slots?: Slots} : Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any }; z_$$bindings?: Bindings; } diff --git a/packages/svelte2tsx/test/emitDts/samples/javascript-runes.v5/expected/TestRunes.svelte.d.ts b/packages/svelte2tsx/test/emitDts/samples/javascript-runes.v5/expected/TestRunes.svelte.d.ts index a5ead56ce..6c3b7250e 100644 --- a/packages/svelte2tsx/test/emitDts/samples/javascript-runes.v5/expected/TestRunes.svelte.d.ts +++ b/packages/svelte2tsx/test/emitDts/samples/javascript-runes.v5/expected/TestRunes.svelte.d.ts @@ -5,7 +5,10 @@ interface $$__sveltets_2_IsomorphicComponent = (internal: unknown, props: Props & { $$events?: Events; $$slots?: Slots; - }): Exports; + }): Exports & { + $set?: any; + $on?: any; + }; z_$$bindings?: Bindings; } declare const TestRunes: $$__sveltets_2_IsomorphicComponent<{ diff --git a/packages/svelte2tsx/test/emitDts/samples/typescript-runes.v5/expected/TestRunes.svelte.d.ts b/packages/svelte2tsx/test/emitDts/samples/typescript-runes.v5/expected/TestRunes.svelte.d.ts index a5ead56ce..6c3b7250e 100644 --- a/packages/svelte2tsx/test/emitDts/samples/typescript-runes.v5/expected/TestRunes.svelte.d.ts +++ b/packages/svelte2tsx/test/emitDts/samples/typescript-runes.v5/expected/TestRunes.svelte.d.ts @@ -5,7 +5,10 @@ interface $$__sveltets_2_IsomorphicComponent = (internal: unknown, props: Props & { $$events?: Events; $$slots?: Slots; - }): Exports; + }): Exports & { + $set?: any; + $on?: any; + }; z_$$bindings?: Bindings; } declare const TestRunes: $$__sveltets_2_IsomorphicComponent<{ diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/creates-dts/expected-svelte5.ts b/packages/svelte2tsx/test/svelte2tsx/samples/creates-dts/expected-svelte5.ts index bd79bd473..72cd512b3 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/creates-dts/expected-svelte5.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/creates-dts/expected-svelte5.ts @@ -26,7 +26,7 @@ return { props: { /** @type {boolean} */bar: bar , foobar: foobar}, exports: {}, bindings: "", slots: {'default': {bar:bar}}, events: {'click':__sveltets_2_mapElementEvent('click'), 'hi': __sveltets_2_customEvent} }} interface $$__sveltets_2_IsomorphicComponent = any, Events extends Record = any, Slots extends Record = any, Exports = {}, Bindings = string> { new (options: import('svelte').ComponentConstructorOptions): import('svelte').SvelteComponent & { $$bindings?: Bindings } & Exports; - (internal: unknown, props: Props & {$$events?: Events, $$slots?: Slots}): Exports; + (internal: unknown, props: Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any }; z_$$bindings?: Bindings; } type $$__sveltets_2_PropsWithChildren = Props & diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/expected-svelte5.ts b/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/expected-svelte5.ts index 7244310a3..bfff5c6ed 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/expected-svelte5.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/creates-no-script-dts/expected-svelte5.ts @@ -8,7 +8,7 @@ async () => { { svelteHTML.createElement("button", { "on:click":undefined,}); { return { props: /** @type {Record} */ ({}), exports: {}, bindings: "", slots: {'default': {}}, events: {'click':__sveltets_2_mapElementEvent('click')} }} interface $$__sveltets_2_IsomorphicComponent = any, Events extends Record = any, Slots extends Record = any, Exports = {}, Bindings = string> { new (options: import('svelte').ComponentConstructorOptions): import('svelte').SvelteComponent & { $$bindings?: Bindings } & Exports; - (internal: unknown, props: {$$events?: Events, $$slots?: Slots}): Exports; + (internal: unknown, props: {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any }; z_$$bindings?: Bindings; } type $$__sveltets_2_PropsWithChildren = Props & diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/transforms-interfaces-dts/expected-svelte5.ts b/packages/svelte2tsx/test/svelte2tsx/samples/transforms-interfaces-dts/expected-svelte5.ts index d57609f30..2cc91a067 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/transforms-interfaces-dts/expected-svelte5.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/transforms-interfaces-dts/expected-svelte5.ts @@ -24,7 +24,7 @@ async () => {}; return { props: {foo: foo , bar: bar}, exports: {}, bindings: "", slots: {}, events: {} }} interface $$__sveltets_2_IsomorphicComponent = any, Events extends Record = any, Slots extends Record = any, Exports = {}, Bindings = string> { new (options: import('svelte').ComponentConstructorOptions): import('svelte').SvelteComponent & { $$bindings?: Bindings } & Exports; - (internal: unknown, props: Props & {$$events?: Events, $$slots?: Slots}): Exports; + (internal: unknown, props: Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any }; z_$$bindings?: Bindings; } diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-creates-dts/expected-svelte5.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-creates-dts/expected-svelte5.ts index 952e79474..8e2f675c3 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-creates-dts/expected-svelte5.ts +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-creates-dts/expected-svelte5.ts @@ -25,7 +25,7 @@ async () => { return { props: {bar: bar , foobar: foobar} as {bar: Bar, foobar?: typeof foobar}, exports: {}, bindings: "", slots: {'default': {bar:bar}}, events: {...__sveltets_2_toEventTypings<{swipe: string}>(), 'click':__sveltets_2_mapElementEvent('click')} }} interface $$__sveltets_2_IsomorphicComponent = any, Events extends Record = any, Slots extends Record = any, Exports = {}, Bindings = string> { new (options: import('svelte').ComponentConstructorOptions): import('svelte').SvelteComponent & { $$bindings?: Bindings } & Exports; - (internal: unknown, props: Props & {$$events?: Events, $$slots?: Slots}): Exports; + (internal: unknown, props: Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any }; z_$$bindings?: Bindings; } type $$__sveltets_2_PropsWithChildren = Props &