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: @const treats multiple declarations as sequence expression #11349

Closed
jrmajor opened this issue Apr 27, 2024 · 2 comments · Fixed by #11357
Closed

Svelte 5: @const treats multiple declarations as sequence expression #11349

jrmajor opened this issue Apr 27, 2024 · 2 comments · Fixed by #11357
Milestone

Comments

@jrmajor
Copy link
Contributor

jrmajor commented Apr 27, 2024

Describe the bug

{#if true}
	{@const foo = 'foo', bar = 'bar'}
{/if}

The following code fails to compile in Svelte 4 ({@const ...} must be an assignment.).

In Svelte 5, it treats 'foo', bar = 'bar' as a sequence expression, which is not how const declarations work in JS.

const foo = 'foo', bar = 'bar';
console.log(foo); // 'foo'
console.log(bar); // 'bar'

Reproduction

REPL: Svelte 4 / Svelte 5

Logs

No response

System Info

Only tested in REPL.

Severity

annoyance

@Infectious-Smile

This comment was marked as spam.

@dummdidumm
Copy link
Member

It should be a compiler error in Svelte 5

@dummdidumm dummdidumm added this to the 5.0 milestone Apr 27, 2024
Rich-Harris pushed a commit that referenced this issue Apr 29, 2024
* fix: disallow sequence expressions in `@const` tags

closes #11349

* allow parenthesized sequence expression
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 a pull request may close this issue.

3 participants