mirror of https://github.com/sveltejs/svelte
fix: stricter validation for component exports (#10430)
disallow exporting props, derived and reassigned state from within components closes #10310, closes #10311, closes #10293pull/10431/head
parent
0e011add4e
commit
dab0a43693
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: disallow exporting props, derived and reassigned state from within components
|
@ -0,0 +1,4 @@
|
||||
<script>
|
||||
let count = $state(0);
|
||||
export const double = $derived(count * 2);
|
||||
</script>
|
@ -0,0 +1,10 @@
|
||||
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]
|
||||
}
|
||||
});
|
@ -0,0 +1,15 @@
|
||||
<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>
|
@ -0,0 +1,9 @@
|
||||
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'
|
||||
}
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
<script>
|
||||
let { foo } = $props();
|
||||
export { foo };
|
||||
</script>
|
Loading…
Reference in new issue