diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts
index 85623c6da7..8ed8e3390d 100644
--- a/src/compiler/compile/Component.ts
+++ b/src/compiler/compile/Component.ts
@@ -788,26 +788,25 @@ export default class Component {
scope = map.get(node);
}
- let deep = false;
- let names: string[] | null;
+ let deep = false;
+ let names: string[] | null;
- if (node.type === 'AssignmentExpression') {
+ if (node.type === 'AssignmentExpression') {
deep = node.left.type === 'MemberExpression';
names = deep
? [get_object(node.left).name]
: extract_names(node.left);
} else if (node.type === 'UpdateExpression') {
- deep = node.argument.type === 'MemberExpression';
- const { name } = get_object(node.argument);
- names = [name];
+ deep = node.argument.type === 'MemberExpression';
+ const { name } = get_object(node.argument);
+ names = [name];
}
-
if (names) {
names.forEach(name => {
const variable = component.var_lookup.get(name);
if (variable && variable.writable === false && !deep) {
- component.warn(node as any, {
+ component.error(node as any, {
code: 'assignment-to-const',
message: 'You are assigning to a const'
});
diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts
index c3817dc3da..c105bc0e55 100644
--- a/src/compiler/compile/nodes/shared/Expression.ts
+++ b/src/compiler/compile/nodes/shared/Expression.ts
@@ -147,13 +147,13 @@ export default class Expression {
} else {
component.add_reference(node, name);
- const variable = component.var_lookup.get(name);
+ const variable = component.var_lookup.get(name);
if (variable) {
variable[deep ? 'mutated' : 'reassigned'] = true;
if (!deep && variable.writable === false) {
- component.warn(node as any, {
+ component.error(node as any, {
code: 'assignment-to-const',
message: 'You are assigning to a const'
});
diff --git a/test/validator/samples/assignment-to-const-2/errors.json b/test/validator/samples/assignment-to-const-2/errors.json
new file mode 100644
index 0000000000..b8da2a3d8e
--- /dev/null
+++ b/test/validator/samples/assignment-to-const-2/errors.json
@@ -0,0 +1,17 @@
+[
+ {
+ "code": "assignment-to-const",
+ "message": "You are assigning to a const",
+ "start": {
+ "line": 13,
+ "column": 24,
+ "character": 282
+ },
+ "end": {
+ "line": 13,
+ "column": 35,
+ "character": 293
+ },
+ "pos": 282
+ }
+]
\ No newline at end of file
diff --git a/test/validator/samples/assignment-to-const-2/input.svelte b/test/validator/samples/assignment-to-const-2/input.svelte
new file mode 100644
index 0000000000..433c6d0076
--- /dev/null
+++ b/test/validator/samples/assignment-to-const-2/input.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/test/validator/samples/assignment-to-const/errors.json b/test/validator/samples/assignment-to-const/errors.json
new file mode 100644
index 0000000000..9e673499f0
--- /dev/null
+++ b/test/validator/samples/assignment-to-const/errors.json
@@ -0,0 +1,17 @@
+[
+ {
+ "code": "assignment-to-const",
+ "message": "You are assigning to a const",
+ "start": {
+ "line": 16,
+ "column": 2,
+ "character": 237
+ },
+ "end": {
+ "line": 16,
+ "column": 18,
+ "character": 253
+ },
+ "pos": 237
+ }
+]
\ No newline at end of file
diff --git a/test/validator/samples/assignment-to-const/input.svelte b/test/validator/samples/assignment-to-const/input.svelte
index b685507b56..fa688a1202 100644
--- a/test/validator/samples/assignment-to-const/input.svelte
+++ b/test/validator/samples/assignment-to-const/input.svelte
@@ -1,34 +1,24 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
diff --git a/test/validator/samples/assignment-to-const/warnings.json b/test/validator/samples/assignment-to-const/warnings.json
deleted file mode 100644
index fac54a6058..0000000000
--- a/test/validator/samples/assignment-to-const/warnings.json
+++ /dev/null
@@ -1,62 +0,0 @@
-[
- {
- "code": "assignment-to-const",
- "message": "You are assigning to a const",
- "start": {
- "line": 31,
- "column": 24,
- "character": 512
- },
- "end": {
- "line": 31,
- "column": 41,
- "character": 529
- },
- "pos": 512
- },
- {
- "code": "assignment-to-const",
- "message": "You are assigning to a const",
- "start": {
- "line": 32,
- "column": 24,
- "character": 570
- },
- "end": {
- "line": 32,
- "column": 36,
- "character": 582
- },
- "pos": 570
- },
- {
- "code": "assignment-to-const",
- "message": "You are assigning to a const",
- "start": {
- "line": 10,
- "column": 2,
- "character": 171
- },
- "end": {
- "line": 10,
- "column": 19,
- "character": 188
- },
- "pos": 171
- },
- {
- "code": "assignment-to-const",
- "message": "You are assigning to a const",
- "start": {
- "line": 14,
- "column": 2,
- "character": 215
- },
- "end": {
- "line": 14,
- "column": 14,
- "character": 227
- },
- "pos": 215
- }
-]
\ No newline at end of file