tweak message to better accommodate the case in which state is declared after a regular property

pull/15820/head
Rich Harris 4 months ago
parent 8c7ad3c5a3
commit 15c7b143f9

@ -211,10 +211,10 @@ Cannot bind to %thing%
### constructor_state_reassignment
```
Cannot redeclare stateful field `%name%` in the constructor. The field was originally declared here: `%original_location%`
A state field declaration in a constructor must be the first assignment, and the only one that uses a rune
```
To create stateful class fields in the constructor, the rune assignment must be the _first_ assignment to the class field.
[State fields]($state#Classes) can be declared as normal class fields or inside the constructor, in which case the declaration must be the _first_ assignment.
Assignments thereafter must not use the rune.
```ts

@ -12,9 +12,9 @@
## constructor_state_reassignment
> Cannot redeclare stateful field `%name%` in the constructor. The field was originally declared here: `%original_location%`
> A state field declaration in a constructor must be the first assignment, and the only one that uses a rune
To create stateful class fields in the constructor, the rune assignment must be the _first_ assignment to the class field.
[State fields]($state#Classes) can be declared as normal class fields or inside the constructor, in which case the declaration must be the _first_ assignment.
Assignments thereafter must not use the rune.
```ts

@ -105,14 +105,12 @@ export function constant_binding(node, thing) {
}
/**
* Cannot redeclare stateful field `%name%` in the constructor. The field was originally declared here: `%original_location%`
* A state field declaration in a constructor must be the first assignment, and the only one that uses a rune
* @param {null | number | NodeLike} node
* @param {string} name
* @param {string} original_location
* @returns {never}
*/
export function constructor_state_reassignment(node, name, original_location) {
e(node, 'constructor_state_reassignment', `Cannot redeclare stateful field \`${name}\` in the constructor. The field was originally declared here: \`${original_location}\`\nhttps://svelte.dev/e/constructor_state_reassignment`);
export function constructor_state_reassignment(node) {
e(node, 'constructor_state_reassignment', `A state field declaration in a constructor must be the first assignment, and the only one that uses a rune\nhttps://svelte.dev/e/constructor_state_reassignment`);
}
/**

@ -1,7 +1,7 @@
[
{
"code": "constructor_state_reassignment",
"message": "Cannot redeclare stateful field `count` in the constructor. The field was originally declared here: `(unknown):2:1`",
"message": "A state field declaration in a constructor must be the first assignment, and the only one that uses a rune",
"start": {
"line": 5,
"column": 2

@ -1,7 +1,7 @@
[
{
"code": "constructor_state_reassignment",
"message": "Cannot redeclare stateful field `count` in the constructor. The field was originally declared here: `(unknown):3:2`",
"message": "A state field declaration in a constructor must be the first assignment, and the only one that uses a rune",
"start": {
"line": 5,
"column": 2

@ -1,7 +1,7 @@
[
{
"code": "constructor_state_reassignment",
"message": "Cannot redeclare stateful field `count` in the constructor. The field was originally declared here: `(unknown):3:2`",
"message": "A state field declaration in a constructor must be the first assignment, and the only one that uses a rune",
"start": {
"line": 5,
"column": 2

@ -1,7 +1,7 @@
[
{
"code": "constructor_state_reassignment",
"message": "Cannot redeclare stateful field `count` in the constructor. The field was originally declared here: `(unknown):3:1`",
"message": "A state field declaration in a constructor must be the first assignment, and the only one that uses a rune",
"start": {
"line": 5,
"column": 2

@ -1,7 +1,7 @@
[
{
"code": "constructor_state_reassignment",
"message": "Cannot redeclare stateful field `count` in the constructor. The field was originally declared here: `(unknown):2:1`",
"message": "A state field declaration in a constructor must be the first assignment, and the only one that uses a rune",
"start": {
"line": 4,
"column": 2

@ -0,0 +1,14 @@
[
{
"code": "constructor_state_reassignment",
"message": "A state field declaration in a constructor must be the first assignment, and the only one that uses a rune",
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 24
}
}
]

@ -0,0 +1,6 @@
export class Counter {
constructor() {
this.count = -1;
this.count = $state(0);
}
}
Loading…
Cancel
Save