Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-mice-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: error in snippets with type annotations
15 changes: 10 additions & 5 deletions src/parser/converts/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,18 @@ export function convertSnippetBlock(
...ctx.getConvertLocation({ start: nodeStart, end: node.end }),
};

let beforeClosingParen: ESTree.Node;
if (node.parameters.length > 0) {
const lastParam = node.parameters[
node.parameters.length - 1
] as ESTree.Pattern & { typeAnnotation?: ESTree.Node };
beforeClosingParen = lastParam.typeAnnotation ?? lastParam;
} else {
beforeClosingParen = node.expression;
}
const closeParenIndex = ctx.code.indexOf(
")",
getWithLoc(
node.parameters.length > 0
? node.parameters[node.parameters.length - 1]
: node.expression,
).end,
getWithLoc(beforeClosingParen).end,
);

const scopeKind =
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/parser/ast/svelte5/ts-snippet03-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script lang="ts">
function hello() {
console.log('Hello');
}
</script>

{@render foo({ onclick: hello })}

{#snippet foo(o: {onclick: () => void})}
<button on:click={o.onclick}>Click me</button>
{/snippet}
Loading
Loading