Skip to content

Commit

Permalink
feat: ensure render tag is passed a snippet function
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Nov 22, 2023
1 parent 3f691b6 commit 07ffe29
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/RenderTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
'();'
'());'
);
}
}
3 changes: 3 additions & 0 deletions packages/svelte2tsx/svelte-shims-v4.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;

declare function __sveltets_2_cssProp(prop: Record<string, any>): {};

// @ts-ignore Svelte v3/v4 don't have this
declare function __sveltets_2_ensureSnippet(val: ReturnType<import('svelte').Snippet>): any;

/** @internal PRIVATE API, DO NOT USE */
type __sveltets_2_SvelteAnimationReturnType = {
delay?: number,
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte2tsx/svelte-shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;

declare function __sveltets_2_cssProp(prop: Record<string, any>): {};

// @ts-ignore Svelte v3/v4 don't have this
declare function __sveltets_2_ensureSnippet(val: ReturnType<import('svelte').Snippet>): any;

/** @internal PRIVATE API, DO NOT USE */
type __sveltets_2_SvelteAnimationReturnType = {
delay?: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ item as string;

var foo/*Ωignore_startΩ*/: import('svelte').Snippet<string>/*Ω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,}});}

0 comments on commit 07ffe29

Please sign in to comment.