Skip to content

Commit

Permalink
fix: allow for whitespace in snippets declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed May 5, 2024
1 parent 9d7907e commit 6569127
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/SnippetBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ export function handleSnippet(
if (snippetBlock.parameters?.length) {
generic = `<[${snippetBlock.parameters
.map((p) =>
p.typeAnnotation
? str.original.slice(p.typeAnnotation.start + 1, p.typeAnnotation.end)
p.typeAnnotation?.typeAnnotation
? str.original.slice(
p.typeAnnotation.typeAnnotation.start,
p.typeAnnotation.typeAnnotation.end
)
: // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
'any'
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts"></script>

if(foo as true){ } else if (bar as false){ }

for(let item of __sveltets_2_ensureArray(items as [''])){let i = 1;item;
item as string;
}

{

try { const $$_value = await (foo as Promise<void>);{ const result: any = $$_value;

}} catch($$_e) { const error: any = __sveltets_2_any();

}}

item as string;

var foo/*Ωignore_startΩ*/: import('svelte').Snippet<[string]>/*Ωignore_endΩ*/ = (bar: string) => {async () => { };return __sveltets_2_any(0)};

var foo2/*Ωignore_startΩ*/: import('svelte').Snippet<[string]>/*Ωignore_endΩ*/ = (bar : string) => {async () => { };return __sveltets_2_any(0)};

var foo3/*Ωignore_startΩ*/: import('svelte').Snippet<[string | number]>/*Ωignore_endΩ*/ = (bar : string | number) => {async () => { };return __sveltets_2_any(0)};

var foo3/*Ωignore_startΩ*/: import('svelte').Snippet<[string | number, (str: string)=>void]>/*Ωignore_endΩ*/ = (bar : string | number, baz : (str: string)=>void) => {async () => { };return __sveltets_2_any(0)};

;__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,}});}
{ svelteHTML.createElement("label", { "id":ok!,}); }
{ const $$_tnenopmoC0C = __sveltets_2_ensureComponent(Component); const $$_tnenopmoC0 = new $$_tnenopmoC0C({ target: __sveltets_2_any(), props: { }});x = $$_tnenopmoC0 as any;}
{ const $$_div0 = svelteHTML.createElement("div", { });x= $$_div0.clientWidth as any;}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
snippet
{/snippet}

{#snippet foo2(bar : string)}
snippet
{/snippet}

{#snippet foo3(bar : string | number)}
snippet
{/snippet}

{#snippet foo3(bar : string | number, baz : (str: string)=>void)}
snippet
{/snippet}

{@render foo(bar as string)}

<button onclick={(e: Event) => {e as any}}>click</button>
Expand Down

0 comments on commit 6569127

Please sign in to comment.