mirror of https://github.com/sveltejs/svelte
fix: tighten up `export default` validation (#14368)
through #14363 I noticed our `export default` validation wasn't quite right: - missed checking for derived/state exports - the "cannot have a default export" error was only thrown if you did `export default` from the instance script, but it shouldn't matter from which component part you export it; it's never okpull/14366/head
parent
4c98c2e4a6
commit
4dfa0e31fe
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: tighten up `export default` validation
|
@ -0,0 +1,10 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'derived_invalid_export',
|
||||
message:
|
||||
'Cannot export derived state from a module. To expose the current derived value, export a function returning its value',
|
||||
position: [61, 83]
|
||||
}
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
let count = $state(0);
|
||||
|
||||
const double = $derived(count * 2);
|
||||
|
||||
export default double;
|
@ -0,0 +1,10 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'state_invalid_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: [93, 118]
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
let primitive = $state('nope');
|
||||
|
||||
export function update_primitive() {
|
||||
primitive = 'yep';
|
||||
}
|
||||
|
||||
export default primitive;
|
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"code": "module_illegal_default_export",
|
||||
"message": "A component cannot have a default export",
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 19
|
||||
}
|
||||
}
|
||||
]
|
@ -0,0 +1,3 @@
|
||||
<script module>
|
||||
export default 42;
|
||||
</script>
|
Loading…
Reference in new issue