throw compiler error when binding directly to const variables (#4506)

pull/4564/head
vlasy 5 years ago committed by GitHub
parent 0ccdca21da
commit e06a900b23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -72,6 +72,11 @@ export default class Binding extends Node {
}); });
variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true; variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;
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',
});
} }
const type = parent.get_static_attribute_value('type'); const type = parent.get_static_attribute_value('type');

@ -0,0 +1,7 @@
<script>
const dummy = {
foo: 'bar'
};
</script>
<input bind:value={dummy.foo}>

@ -0,0 +1,15 @@
[{
"code": "invalid-binding",
"message": "Cannot bind to a variable which is not writable",
"pos": 61,
"start": {
"line": 5,
"column": 19,
"character": 61
},
"end": {
"line": 5,
"column": 24,
"character": 66
}
}]

@ -0,0 +1,5 @@
<script>
const dummy = 'foo';
</script>
<input bind:value={dummy}>
Loading…
Cancel
Save