mirror of https://github.com/sveltejs/svelte
parent
78ab02d3e4
commit
06962c8946
@ -1,27 +1,10 @@
|
||||
/** @import { ClassBody } from 'estree' */
|
||||
/** @import { Context } from '../types' */
|
||||
import { get_rune } from '../../scope.js';
|
||||
|
||||
/**
|
||||
* @param {ClassBody} node
|
||||
* @param {Context} context
|
||||
*/
|
||||
export function ClassBody(node, context) {
|
||||
/** @type {string[]} */
|
||||
const private_derived_state = [];
|
||||
|
||||
for (const definition of node.body) {
|
||||
if (
|
||||
definition.type === 'PropertyDefinition' &&
|
||||
definition.key.type === 'PrivateIdentifier' &&
|
||||
definition.value?.type === 'CallExpression'
|
||||
) {
|
||||
const rune = get_rune(definition.value, context.state.scope);
|
||||
if (rune === '$derived' || rune === '$derived.by') {
|
||||
private_derived_state.push(definition.key.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.next({ ...context.state, private_derived_state });
|
||||
context.next({ ...context.state });
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'constant_assignment',
|
||||
message: 'Cannot assign to derived state'
|
||||
}
|
||||
});
|
@ -1,10 +0,0 @@
|
||||
<script>
|
||||
class Counter {
|
||||
count = $state();
|
||||
#doubled = $derived(this.count * 2);
|
||||
|
||||
nope() {
|
||||
this.#doubled += 1;
|
||||
}
|
||||
}
|
||||
</script>
|
@ -1,8 +0,0 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'constant_assignment',
|
||||
message: 'Cannot assign to derived state'
|
||||
}
|
||||
});
|
@ -1,10 +0,0 @@
|
||||
<script>
|
||||
class Counter {
|
||||
count = $state();
|
||||
#doubled = $derived(this.count * 2);
|
||||
|
||||
nope() {
|
||||
this.#doubled++;
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in new issue