Skip to content

Commit a1a3f92

Browse files
committed
fix: properly determine end of snippet parameters with TS annotations
fixes #455
1 parent 0c5692a commit a1a3f92

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.2.7 (unreleased)
44

55
- (fix) force quote style inside style directives
6+
- (fix) Svelte 5: properly determine end of snippet parameters with TS annotations
67

78
## 3.2.6
89

src/embed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ export function embed(path: FastPath, _options: Options) {
100100
printSvelteBlockJS('key');
101101
break;
102102
case 'SnippetBlock':
103-
// We merge the two parts into one expression, which future-proofs this for template TS support
103+
// We merge the two parts into one expression to then treat it like a function
104104
if (node === parent.expression) {
105105
parent.expression.end =
106106
options.originalText.indexOf(
107107
')',
108-
parent.context?.end ?? // TODO: remove at some point, snippet API changed in .next-..
108+
(parent.parameters?.[parent.parameters.length - 1] as any)?.typeAnnotation
109+
?.end ??
109110
parent.parameters?.[parent.parameters.length - 1]?.end ??
110111
parent.expression.end,
111112
) + 1;
112-
parent.context = null;
113113
parent.parameters = null;
114114
node.isJS = true;
115115
node.asFunction = true;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
</script>
3+
4+
{#snippet test1(arg: string)}
5+
foo
6+
{/snippet}
7+
8+
{#snippet test2(arg: (typeof obj)["key"])}
9+
foo
10+
{/snippet}
11+
12+
{#snippet test3({ onselect }: { onselect: (value: string) => void })}
13+
foo
14+
{/snippet}

0 commit comments

Comments
 (0)