diff --git a/.changeset/four-carrots-burn.md b/.changeset/four-carrots-burn.md new file mode 100644 index 000000000000..39cefcc4b76e --- /dev/null +++ b/.changeset/four-carrots-burn.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: allow exports with source from script module even if no bind is present diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index 8f1efd7f635f..9e29813ee336 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -698,7 +698,7 @@ export function analyze_component(root, source, options) { } for (const node of analysis.module.ast.body) { - if (node.type === 'ExportNamedDeclaration' && node.specifiers !== null) { + if (node.type === 'ExportNamedDeclaration' && node.specifiers !== null && node.source == null) { for (const specifier of node.specifiers) { if (specifier.local.type !== 'Identifier') continue; diff --git a/packages/svelte/tests/compiler-errors/samples/export-not-defined-module-with-source/_config.js b/packages/svelte/tests/compiler-errors/samples/export-not-defined-module-with-source/_config.js new file mode 100644 index 000000000000..2212f3b5cbcf --- /dev/null +++ b/packages/svelte/tests/compiler-errors/samples/export-not-defined-module-with-source/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + error: false +}); diff --git a/packages/svelte/tests/compiler-errors/samples/export-not-defined-module-with-source/main.svelte b/packages/svelte/tests/compiler-errors/samples/export-not-defined-module-with-source/main.svelte new file mode 100644 index 000000000000..445aebcf4fbb --- /dev/null +++ b/packages/svelte/tests/compiler-errors/samples/export-not-defined-module-with-source/main.svelte @@ -0,0 +1,3 @@ + diff --git a/packages/svelte/tests/compiler-errors/test.ts b/packages/svelte/tests/compiler-errors/test.ts index ea696890b4f8..3b42519b5a00 100644 --- a/packages/svelte/tests/compiler-errors/test.ts +++ b/packages/svelte/tests/compiler-errors/test.ts @@ -5,11 +5,13 @@ import { suite, type BaseTest } from '../suite'; import { read_file } from '../helpers.js'; interface CompilerErrorTest extends BaseTest { - error: { - code: string; - message: string; - position?: [number, number]; - }; + error: + | { + code: string; + message: string; + position?: [number, number]; + } + | false; } const { test, run } = suite((config, cwd) => { @@ -25,6 +27,9 @@ const { test, run } = suite((config, cwd) => { generate: 'client' }); } catch (e) { + if (config.error === false) { + assert.fail('Unexpected error'); + } const error = e as CompileError; caught_error = true; @@ -37,7 +42,7 @@ const { test, run } = suite((config, cwd) => { } } - if (!caught_error) { + if (config.error !== false && !caught_error) { assert.fail('Expected an error'); } } @@ -50,6 +55,9 @@ const { test, run } = suite((config, cwd) => { generate: 'client' }); } catch (e) { + if (config.error === false) { + assert.fail('Unexpected error'); + } const error = e as CompileError; caught_error = true; @@ -62,7 +70,7 @@ const { test, run } = suite((config, cwd) => { } } - if (!caught_error) { + if (config.error !== false && !caught_error) { assert.fail('Expected an error'); } }