diff --git a/src/compile/nodes/Binding.ts b/src/compile/nodes/Binding.ts index 3ab2cd8ff5..b03eba0c36 100644 --- a/src/compile/nodes/Binding.ts +++ b/src/compile/nodes/Binding.ts @@ -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; diff --git a/test/validator/samples/binding-let/errors.json b/test/validator/samples/binding-let/errors.json new file mode 100644 index 0000000000..6195a1c3ae --- /dev/null +++ b/test/validator/samples/binding-let/errors.json @@ -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 + } +}] \ No newline at end of file diff --git a/test/validator/samples/binding-let/input.svelte b/test/validator/samples/binding-let/input.svelte new file mode 100644 index 0000000000..79162ddacd --- /dev/null +++ b/test/validator/samples/binding-let/input.svelte @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file