Skip to content

Commit

Permalink
better error for bindings to let: values - fixes #2301
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 13, 2019
1 parent 079a1ba commit cd0f535
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/compile/nodes/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/validator/samples/binding-let/errors.json
Original file line number Diff line number Diff line change
@@ -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
}
}]
7 changes: 7 additions & 0 deletions test/validator/samples/binding-let/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let Foo;
</script>

<Foo let:bar>
<input bind:value={bar}>
</Foo>

0 comments on commit cd0f535

Please sign in to comment.