diff --git a/src/compiler/compile/nodes/Binding.ts b/src/compiler/compile/nodes/Binding.ts index 4028ad699b..2f199709c8 100644 --- a/src/compiler/compile/nodes/Binding.ts +++ b/src/compiler/compile/nodes/Binding.ts @@ -73,7 +73,7 @@ export default class Binding extends Node { variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true; - if (!variable.writable) component.error(this.expression.node, { + if (info.expression.type === 'Identifier' && !variable.writable) component.error(this.expression.node, { code: 'invalid-binding', message: 'Cannot bind to a variable which is not writable', }); diff --git a/test/validator/samples/binding-const-field/errors.json b/test/validator/samples/binding-const-field/errors.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/test/validator/samples/binding-const-field/errors.json @@ -0,0 +1 @@ +[] diff --git a/test/validator/samples/binding-const-field/input.svelte b/test/validator/samples/binding-const-field/input.svelte new file mode 100644 index 0000000000..055a16438d --- /dev/null +++ b/test/validator/samples/binding-const-field/input.svelte @@ -0,0 +1,7 @@ + + + diff --git a/test/validator/samples/binding-const/input.svelte b/test/validator/samples/binding-const/input.svelte index 8147896730..1857a1932c 100644 --- a/test/validator/samples/binding-const/input.svelte +++ b/test/validator/samples/binding-const/input.svelte @@ -2,4 +2,4 @@ const dummy = 'foo'; - \ No newline at end of file +