Skip to content

Commit

Permalink
fix: properly determine end of snippet parameters with TS annotations
Browse files Browse the repository at this point in the history
fixes #455
  • Loading branch information
dummdidumm committed Aug 20, 2024
1 parent 0c5692a commit a1a3f92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions test/printer/samples/snippet-ts.html.skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
</script>

{#snippet test1(arg: string)}
foo
{/snippet}

{#snippet test2(arg: (typeof obj)["key"])}
foo
{/snippet}

{#snippet test3({ onselect }: { onselect: (value: string) => void })}
foo
{/snippet}

0 comments on commit a1a3f92

Please sign in to comment.