Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5: Syntax error on snippets with inline typing with optional properties #12068

Closed
7nik opened this issue Jun 17, 2024 · 3 comments
Closed

Comments

@7nik
Copy link

7nik commented Jun 17, 2024

Describe the bug

Syntax error on snippets with inline typing with optional properties.

<script lang="ts"></script>
{#snippet snip({a}: {a?: string})} <!-- Error: Expected token ) -->
  {a}
{/snippet}

Reproduction

REPL

Logs

No response

System Info

Svelte 5.0.0-next.157

Severity

annoyance

@paoloricciuti
Copy link
Member

The problem is this line:

parser.template.slice(parser.index).replace(/\?\s*:/g, ':');

it replace ?: with : and that works fine for optional function parameters but it messes with non optional function parameters that have an optional field in them (i assume the same is true for functions types too).

@paoloricciuti
Copy link
Member

This will basically break whenever theere's one or more ?: in the type itself. So this

<script lang="ts"></script>
{#snippet snip(a: "cool?:")}
  {a}
{/snippet}

is also broken

@paoloricciuti
Copy link
Member

This should be fixed by #12070 (the repl seems fine now)

@7nik 7nik closed this as completed Jun 22, 2024
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

No branches or pull requests

2 participants