mirror of https://github.com/sveltejs/svelte
parent
1f52cf00d9
commit
3bfcaccc85
@ -0,0 +1,21 @@
|
|||||||
|
/** @import { PropertyDefinition } from 'estree' */
|
||||||
|
/** @import { Context } from '../types' */
|
||||||
|
import * as e from '../../../errors.js';
|
||||||
|
import { get_name } from '../../nodes.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {PropertyDefinition} node
|
||||||
|
* @param {Context} context
|
||||||
|
*/
|
||||||
|
export function PropertyDefinition(node, context) {
|
||||||
|
const name = get_name(node.key);
|
||||||
|
const field = name && context.state.state_fields.get(name);
|
||||||
|
|
||||||
|
if (field && node !== field.node && node.value) {
|
||||||
|
if (/** @type {number} */ (node.start) < /** @type {number} */ (field.node.start)) {
|
||||||
|
e.state_field_invalid_assignment(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.next();
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"code": "state_field_invalid_assignment",
|
||||||
|
"message": "Cannot assign to a state field before its declaration",
|
||||||
|
"start": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 1
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
@ -0,0 +1,7 @@
|
|||||||
|
export class Counter {
|
||||||
|
count = -1;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.count = $state(0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue