mirror of https://github.com/sveltejs/svelte
feat: allow state/derived/props to be explicitly exported from components (#10523)
* Revert "fix: stricter validation for component exports (#10430)"
This reverts commit dab0a43693
.
* dont remove old changeset
* changeset
* tweak error messages
* make component-exported state work
* consistency
* fix
* fix
* update messages
* update tests
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10569/head
parent
ad2b8b9112
commit
02c6176622
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow state/derived/props to be explicitly exported from components
|
@ -1,4 +0,0 @@
|
|||||||
<script>
|
|
||||||
let count = $state(0);
|
|
||||||
export const double = $derived(count * 2);
|
|
||||||
</script>
|
|
@ -1,10 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
error: {
|
|
||||||
code: 'invalid-state-export',
|
|
||||||
message:
|
|
||||||
"Cannot export state if it is reassigned. Either export a function returning the state value or only mutate the state value's properties",
|
|
||||||
position: [59, 99]
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,15 +0,0 @@
|
|||||||
<script>
|
|
||||||
export const object = $state({
|
|
||||||
ok: true
|
|
||||||
});
|
|
||||||
|
|
||||||
export const primitive = $state('nope');
|
|
||||||
|
|
||||||
export function update_object() {
|
|
||||||
object.ok = !object.ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function update_primitive() {
|
|
||||||
primitive = 'yep';
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,9 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
error: {
|
|
||||||
code: 'invalid-prop-export',
|
|
||||||
message:
|
|
||||||
'Cannot export properties. To expose the current value of a property, export a function returning its value'
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,4 +0,0 @@
|
|||||||
<script>
|
|
||||||
let { foo } = $props();
|
|
||||||
export { foo };
|
|
||||||
</script>
|
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let doubled = $derived(count * 2);
|
||||||
|
|
||||||
|
export { count, doubled };
|
||||||
|
|
||||||
|
export function increment() {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{count}
|
||||||
|
{doubled}
|
@ -1,15 +0,0 @@
|
|||||||
<script>
|
|
||||||
export const count1 = $state.frozen({value: 0});
|
|
||||||
export const count2 = $state({value: 0});
|
|
||||||
|
|
||||||
export function increment() {
|
|
||||||
count2.value += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{count1.value}
|
|
||||||
{count2.value}
|
|
||||||
|
|
||||||
<!-- so that count1/2 become sources -->
|
|
||||||
<svelte:options accessors />
|
|
Loading…
Reference in new issue