Skip to content

Commit 474c588

Browse files
fix: disallow bind:group to snippet parameters (#15401)
1 parent e4987d2 commit 474c588

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed

.changeset/hip-oranges-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: disallow `bind:group` to snippet parameters

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ Attribute values containing `{...}` must be enclosed in quote marks, unless the
8484
`bind:group` can only bind to an Identifier or MemberExpression
8585
```
8686

87+
### bind_group_invalid_snippet_parameter
88+
89+
```
90+
Cannot `bind:group` to a snippet parameter
91+
```
92+
8793
### bind_invalid_expression
8894

8995
```

packages/svelte/messages/compile-errors/template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454

5555
> `bind:group` can only bind to an Identifier or MemberExpression
5656
57+
## bind_group_invalid_snippet_parameter
58+
59+
> Cannot `bind:group` to a snippet parameter
60+
5761
## bind_invalid_expression
5862

5963
> Can only bind to an Identifier or MemberExpression or a `{get, set}` pair

packages/svelte/src/compiler/errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,15 @@ export function bind_group_invalid_expression(node) {
752752
e(node, 'bind_group_invalid_expression', `\`bind:group\` can only bind to an Identifier or MemberExpression\nhttps://svelte.dev/e/bind_group_invalid_expression`);
753753
}
754754

755+
/**
756+
* Cannot `bind:group` to a snippet parameter
757+
* @param {null | number | NodeLike} node
758+
* @returns {never}
759+
*/
760+
export function bind_group_invalid_snippet_parameter(node) {
761+
e(node, 'bind_group_invalid_snippet_parameter', `Cannot \`bind:group\` to a snippet parameter\nhttps://svelte.dev/e/bind_group_invalid_snippet_parameter`);
762+
}
763+
755764
/**
756765
* Can only bind to an Identifier or MemberExpression or a `{get, set}` pair
757766
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export function BindDirective(node, context) {
191191
throw new Error('Cannot find declaration for bind:group');
192192
}
193193

194+
if (binding.kind === 'snippet') {
195+
e.bind_group_invalid_snippet_parameter(node);
196+
}
197+
194198
// Traverse the path upwards and find all EachBlocks who are (indirectly) contributing to bind:group,
195199
// i.e. one of their declarations is referenced in the binding. This allows group bindings to work
196200
// correctly when referencing a variable declared in an EachBlock by using the index of the each block
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "bind_group_invalid_snippet_parameter",
4+
"end": {
5+
"column": 44,
6+
"line": 2
7+
},
8+
"message": "Cannot `bind:group` to a snippet parameter",
9+
"start": {
10+
"column": 21,
11+
"line": 2
12+
}
13+
}
14+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{#snippet test(group)}
2+
<input type="radio" bind:group={group.name} />
3+
{/snippet}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy