Skip to content

Conversation

@samuelkal
Copy link

This PR improves the error message when a snippet in Svelte contains TypeScript-style type annotations
(e.g., {#snippet bar(text: string)}) but the <script> tag does not have lang="ts".

Without this fix, users get a generic "Unexpected token" error, which is confusing.
Now, the compiler shows a more helpful message:
"Unexpected token ':' – did you forget to add lang='ts'?"

References issue: #16835

Tests have been run with pnpm test and linting with pnpm lint. Only the error message output has been adjusted.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2025

🦋 Changeset detected

Latest commit: 0b62c63

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dummdidumm
Copy link
Member

Thank you for starting a PR for this. I think the given solution won't work though.

Consider this snippet:

{#snippet aa({x: y})}
	{y}
{/snippet}

{@render aa({x: 'hi'})}

This matches your pattern and would fail wrongfully. I think it would be better to check once the error is thrown instead, look for the : or similar triggers and then add the "did you mean to add ... lang=ts" if we know the script tag doesn't already have it.

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants