diff --git a/CHANGELOG.md b/CHANGELOG.md index 313b3a6..e1e922d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 3.2.7 (unreleased) - (fix) force quote style inside style directives +- (fix) Svelte 5: properly determine end of snippet parameters with TS annotations ## 3.2.6 diff --git a/src/embed.ts b/src/embed.ts index e739185..c0018fe 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -100,16 +100,16 @@ export function embed(path: FastPath, _options: Options) { printSvelteBlockJS('key'); break; case 'SnippetBlock': - // We merge the two parts into one expression, which future-proofs this for template TS support + // We merge the two parts into one expression to then treat it like a function if (node === parent.expression) { parent.expression.end = options.originalText.indexOf( ')', - parent.context?.end ?? // TODO: remove at some point, snippet API changed in .next-.. + (parent.parameters?.[parent.parameters.length - 1] as any)?.typeAnnotation + ?.end ?? parent.parameters?.[parent.parameters.length - 1]?.end ?? parent.expression.end, ) + 1; - parent.context = null; parent.parameters = null; node.isJS = true; node.asFunction = true; diff --git a/test/printer/samples/snippet-ts.html.skip b/test/printer/samples/snippet-ts.html.skip new file mode 100644 index 0000000..2559ea1 --- /dev/null +++ b/test/printer/samples/snippet-ts.html.skip @@ -0,0 +1,14 @@ + + +{#snippet test1(arg: string)} + foo +{/snippet} + +{#snippet test2(arg: (typeof obj)["key"])} + foo +{/snippet} + +{#snippet test3({ onselect }: { onselect: (value: string) => void })} + foo +{/snippet}