Skip to content

Commit

Permalink
fix: disallow sequence expressions in @const tags
Browse files Browse the repository at this point in the history
closes #11349
  • Loading branch information
dummdidumm committed Apr 28, 2024
1 parent bda32ed commit bbde079
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-masks-exercise.md
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: disallow sequence expressions in `@const` tags
2 changes: 1 addition & 1 deletion packages/svelte/messages/compile-errors/template.md
Expand Up @@ -94,7 +94,7 @@
## const_tag_invalid_expression

> {@const ...} must be an assignment
> {@const ...} must consist of a single variable declaration
## const_tag_invalid_placement

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/errors.js
Expand Up @@ -734,7 +734,7 @@ export function component_invalid_directive(node) {
* @returns {never}
*/
export function const_tag_invalid_expression(node) {
e(node, "const_tag_invalid_expression", "{@const ...} must be an assignment");
e(node, "const_tag_invalid_expression", "{@const ...} must consist of a single variable declaration");
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte/src/compiler/phases/1-parse/state/tag.js
Expand Up @@ -552,6 +552,9 @@ function special(parser) {
parser.allow_whitespace();

const init = read_expression(parser);
if (init.type === 'SequenceExpression') {
e.const_tag_invalid_expression(init);
}
parser.allow_whitespace();

parser.eat('}', true);
Expand Down
@@ -0,0 +1,8 @@
import { test } from '../../test';

export default test({
error: {
code: 'const_tag_invalid_expression',
message: '{@const ...} must consist of a single variable declaration'
}
});
@@ -0,0 +1,3 @@
{#if true}
{@const foo = 'foo', bar = 'bar'}
{/if}

0 comments on commit bbde079

Please sign in to comment.