fix: disallow `export { foo as default }` in `<script module>` (#16447)

* fix: disallow `export { foo as default }` in `<script module>`

* add test

* fix test
pull/16445/head
ComputerGuy 2 months ago committed by GitHub
parent 27c90dfa83
commit 63cbe2108a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: disallow `export { foo as default }` in `<script module>`

@ -11,6 +11,17 @@ export function ExportNamedDeclaration(node, context) {
// visit children, so bindings are correctly initialised
context.next();
if (
context.state.ast_type &&
node.specifiers.some((specifier) =>
specifier.exported.type === 'Identifier'
? specifier.exported.name === 'default'
: specifier.exported.value === 'default'
)
) {
e.module_illegal_default_export(node);
}
if (node.declaration?.type === 'VariableDeclaration') {
// in runes mode, forbid `export let`
if (

@ -0,0 +1,14 @@
[
{
"code": "module_illegal_default_export",
"message": "A component cannot have a default export",
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 32
}
}
]

@ -0,0 +1,4 @@
<script module>
let answer = 42;
export { answer as default};
</script>
Loading…
Cancel
Save