better error for bindings to let: values - fixes #2301

pull/2408/head
Richard Harris 5 years ago
parent 079a1ba276
commit cd0f535d83

@ -31,7 +31,12 @@ export default class Binding extends Node {
this.is_contextual = scope.names.has(name);
// make sure we track this as a mutable ref
if (this.is_contextual) {
if (scope.is_let(name)) {
component.error(this, {
code: 'invalid-binding',
message: 'Cannot bind to a variable declared with the let: directive'
});
} else if (this.is_contextual) {
scope.dependencies_for_name.get(name).forEach(name => {
const variable = component.var_lookup.get(name);
variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;

@ -0,0 +1,15 @@
[{
"code": "invalid-binding",
"message": "Cannot bind to a variable declared with the let: directive",
"pos": 52,
"start": {
"line": 6,
"column": 8,
"character": 52
},
"end": {
"line": 6,
"column": 24,
"character": 68
}
}]

@ -0,0 +1,7 @@
<script>
let Foo;
</script>
<Foo let:bar>
<input bind:value={bar}>
</Foo>
Loading…
Cancel
Save