disallow computed state fields

pull/15820/head
Rich Harris 4 months ago
parent 0024e1ed3e
commit 8c7ad3c5a3

@ -88,7 +88,7 @@ export class ClassAnalysis {
node.operator === '=' &&
node.left.type === 'MemberExpression' &&
node.left.object.type === 'ThisExpression' &&
(node.left.property.type === 'Identifier' ||
((node.left.property.type === 'Identifier' && !node.left.computed) ||
node.left.property.type === 'PrivateIdentifier' ||
node.left.property.type === 'Literal')
)

@ -0,0 +1,14 @@
[
{
"code": "state_invalid_placement",
"message": "`$state(...)` can only be used as a variable declaration initializer, a class field declaration, or the first assignment to a class field at the top level of the constructor.",
"start": {
"line": 5,
"column": 16
},
"end": {
"line": 5,
"column": 25
}
}
]

@ -0,0 +1,7 @@
const count = 'count';
export class Counter {
constructor() {
this[count] = $state(0);
}
}
Loading…
Cancel
Save