diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/RenderTag.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/RenderTag.ts index a1652826d..ee6efeda8 100644 --- a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/RenderTag.ts +++ b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/RenderTag.ts @@ -6,18 +6,20 @@ import { BaseNode } from '../../interfaces'; * `{@render foo(x)}` --> `;foo(x);` */ export function handleRenderTag(str: MagicString, renderTag: BaseNode): void { - str.overwrite(renderTag.start, renderTag.expression.start, ';', { contentOnly: true }); + str.overwrite(renderTag.start, renderTag.expression.start, ';__sveltets_2_ensureSnippet(', { + contentOnly: true + }); if (renderTag.argument) { str.overwrite( withTrailingPropertyAccess(str.original, renderTag.argument.end), renderTag.end, - ');' + '));' ); } else { str.overwrite( withTrailingPropertyAccess(str.original, renderTag.expression.end), renderTag.end, - '();' + '());' ); } } diff --git a/packages/svelte2tsx/svelte-shims-v4.d.ts b/packages/svelte2tsx/svelte-shims-v4.d.ts index ee610dfe2..f5807b3f5 100644 --- a/packages/svelte2tsx/svelte-shims-v4.d.ts +++ b/packages/svelte2tsx/svelte-shims-v4.d.ts @@ -145,6 +145,9 @@ declare function __sveltets_2_nonNullable(type: T): NonNullable; declare function __sveltets_2_cssProp(prop: Record): {}; +// @ts-ignore Svelte v3/v4 don't have this +declare function __sveltets_2_ensureSnippet(val: ReturnType): any; + /** @internal PRIVATE API, DO NOT USE */ type __sveltets_2_SvelteAnimationReturnType = { delay?: number, diff --git a/packages/svelte2tsx/svelte-shims.d.ts b/packages/svelte2tsx/svelte-shims.d.ts index a8066b0a7..8bc3720fc 100644 --- a/packages/svelte2tsx/svelte-shims.d.ts +++ b/packages/svelte2tsx/svelte-shims.d.ts @@ -224,6 +224,9 @@ declare function __sveltets_2_nonNullable(type: T): NonNullable; declare function __sveltets_2_cssProp(prop: Record): {}; +// @ts-ignore Svelte v3/v4 don't have this +declare function __sveltets_2_ensureSnippet(val: ReturnType): any; + /** @internal PRIVATE API, DO NOT USE */ type __sveltets_2_SvelteAnimationReturnType = { delay?: number, diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/snippet.skip/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/snippet.skip/expectedv2.js index 59714bd7f..163de3102 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/snippet.skip/expectedv2.js +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/snippet.skip/expectedv2.js @@ -2,8 +2,8 @@ { svelteHTML.createElement("div", {}); x; } return __sveltets_2_any(0)} -;foo(1); -;foo(); +;__sveltets_2_ensureSnippet(foo(1)); +;__sveltets_2_ensureSnippet(foo()); { const $$_tnenopmoC0C = __sveltets_2_ensureComponent(Component); new $$_tnenopmoC0C({ target: __sveltets_2_any(), props: {bar:(x) => { { svelteHTML.createElement("div", {}); x; } diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.skip/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.skip/expectedv2.js index a7a109f28..81bbea5b4 100644 --- a/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.skip/expectedv2.js +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/ts-in-template.skip/expectedv2.js @@ -18,7 +18,7 @@ item as string; var foo/*Ωignore_startΩ*/: import('svelte').Snippet/*Ωignore_endΩ*/ = (bar: string) => { return __sveltets_2_any(0)} -;foo(bar as string); +;__sveltets_2_ensureSnippet(foo(bar as string)); { svelteHTML.createElement("button", { "onclick":(e: Event) => {e as any},}); } { const $$_tnenopmoC0C = __sveltets_2_ensureComponent(Component); new $$_tnenopmoC0C({ target: __sveltets_2_any(), props: { "attr":attr as boolean,}});} \ No newline at end of file