Merge pull request #2408 from sveltejs/gh-2301

better error for bindings to let: values
pull/2411/head
Rich Harris 6 years ago committed by GitHub
commit 7fcad18f2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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