Skip to content

Commit cd0f535

Browse files
committed
better error for bindings to let: values - fixes sveltejs#2301
1 parent 079a1ba commit cd0f535

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/compile/nodes/Binding.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ export default class Binding extends Node {
3131
this.is_contextual = scope.names.has(name);
3232

3333
// make sure we track this as a mutable ref
34-
if (this.is_contextual) {
34+
if (scope.is_let(name)) {
35+
component.error(this, {
36+
code: 'invalid-binding',
37+
message: 'Cannot bind to a variable declared with the let: directive'
38+
});
39+
} else if (this.is_contextual) {
3540
scope.dependencies_for_name.get(name).forEach(name => {
3641
const variable = component.var_lookup.get(name);
3742
variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[{
2+
"code": "invalid-binding",
3+
"message": "Cannot bind to a variable declared with the let: directive",
4+
"pos": 52,
5+
"start": {
6+
"line": 6,
7+
"column": 8,
8+
"character": 52
9+
},
10+
"end": {
11+
"line": 6,
12+
"column": 24,
13+
"character": 68
14+
}
15+
}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let Foo;
3+
</script>
4+
5+
<Foo let:bar>
6+
<input bind:value={bar}>
7+
</Foo>

0 commit comments

Comments
 (0)