fix: disallow `bind:group` to snippet parameters (#15401)

props-id-hydration-markers
Paolo Ricciuti 6 months ago committed by GitHub
parent e4987d2a9f
commit 474c588067
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: disallow `bind:group` to snippet parameters

@ -84,6 +84,12 @@ Attribute values containing `{...}` must be enclosed in quote marks, unless the
`bind:group` can only bind to an Identifier or MemberExpression `bind:group` can only bind to an Identifier or MemberExpression
``` ```
### bind_group_invalid_snippet_parameter
```
Cannot `bind:group` to a snippet parameter
```
### bind_invalid_expression ### bind_invalid_expression
``` ```

@ -54,6 +54,10 @@
> `bind:group` can only bind to an Identifier or MemberExpression > `bind:group` can only bind to an Identifier or MemberExpression
## bind_group_invalid_snippet_parameter
> Cannot `bind:group` to a snippet parameter
## bind_invalid_expression ## bind_invalid_expression
> Can only bind to an Identifier or MemberExpression or a `{get, set}` pair > Can only bind to an Identifier or MemberExpression or a `{get, set}` pair

@ -752,6 +752,15 @@ export function bind_group_invalid_expression(node) {
e(node, 'bind_group_invalid_expression', `\`bind:group\` can only bind to an Identifier or MemberExpression\nhttps://svelte.dev/e/bind_group_invalid_expression`); e(node, 'bind_group_invalid_expression', `\`bind:group\` can only bind to an Identifier or MemberExpression\nhttps://svelte.dev/e/bind_group_invalid_expression`);
} }
/**
* Cannot `bind:group` to a snippet parameter
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function bind_group_invalid_snippet_parameter(node) {
e(node, 'bind_group_invalid_snippet_parameter', `Cannot \`bind:group\` to a snippet parameter\nhttps://svelte.dev/e/bind_group_invalid_snippet_parameter`);
}
/** /**
* Can only bind to an Identifier or MemberExpression or a `{get, set}` pair * Can only bind to an Identifier or MemberExpression or a `{get, set}` pair
* @param {null | number | NodeLike} node * @param {null | number | NodeLike} node

@ -191,6 +191,10 @@ export function BindDirective(node, context) {
throw new Error('Cannot find declaration for bind:group'); throw new Error('Cannot find declaration for bind:group');
} }
if (binding.kind === 'snippet') {
e.bind_group_invalid_snippet_parameter(node);
}
// Traverse the path upwards and find all EachBlocks who are (indirectly) contributing to bind:group, // Traverse the path upwards and find all EachBlocks who are (indirectly) contributing to bind:group,
// i.e. one of their declarations is referenced in the binding. This allows group bindings to work // i.e. one of their declarations is referenced in the binding. This allows group bindings to work
// correctly when referencing a variable declared in an EachBlock by using the index of the each block // correctly when referencing a variable declared in an EachBlock by using the index of the each block

@ -0,0 +1,14 @@
[
{
"code": "bind_group_invalid_snippet_parameter",
"end": {
"column": 44,
"line": 2
},
"message": "Cannot `bind:group` to a snippet parameter",
"start": {
"column": 21,
"line": 2
}
}
]

@ -0,0 +1,3 @@
{#snippet test(group)}
<input type="radio" bind:group={group.name} />
{/snippet}
Loading…
Cancel
Save