mirror of https://github.com/sveltejs/svelte
fix: error when exporting reassigned state from module context (#10728)
fixes #10380pull/10730/head
parent
ae4af6841a
commit
b1267b03b6
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: error when exporting reassigned state from module context
|
@ -0,0 +1,10 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
error: {
|
||||||
|
code: 'invalid-state-export',
|
||||||
|
message:
|
||||||
|
"Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties",
|
||||||
|
position: [76, 114]
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,15 @@
|
|||||||
|
<script context="module">
|
||||||
|
export const object = $state({
|
||||||
|
ok: true
|
||||||
|
});
|
||||||
|
|
||||||
|
export let primitive = $state('nope');
|
||||||
|
|
||||||
|
export function update_object() {
|
||||||
|
object.ok = !object.ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function update_primitive() {
|
||||||
|
primitive = 'yep';
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in new issue