Skip to content

feat: support svelte snippets #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/core/compilers/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SvelteCompiler = (async (svg: string) => {
sfc += `{@html \`${escapeSvelte(svg.slice(openTagEnd + 1, closeTagStart))}\`}`

sfc += svg.slice(closeTagStart)
return svelteRunes ? `<script>const{...p}=$props()</script>${sfc}` : sfc
return svelteRunes ? `<script module>export{snippet}</script><script>const{...p}=$props()</script>{#snippet snippet(p)}${sfc}{/snippet}{@render snippet(p)}` : sfc
}) as Compiler

// escape curlies, backtick, \t, \r, \n to avoid breaking output of {@html `here`} in .svelte
Expand Down
8 changes: 6 additions & 2 deletions types/svelte5.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
declare module 'virtual:icons/*' {
import type { Component } from 'svelte'
import type { Component, Snippet } from 'svelte'
import type { SvelteHTMLElements } from 'svelte/elements'

const component: Component<SvelteHTMLElements['svg']>
const snippet: Snippet<[SvelteHTMLElements['svg']?]>

export default component
export { snippet }
}

declare module '~icons/*' {
import type { Component } from 'svelte'
import type { Component, Snippet } from 'svelte'
import type { SvelteHTMLElements } from 'svelte/elements'

const component: Component<SvelteHTMLElements['svg']>
const snippet: Snippet<[SvelteHTMLElements['svg']?]>

export default component
export { snippet }
}