Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow exports with source from script module even if no bind is …
Browse files Browse the repository at this point in the history
…present
paoloricciuti committed Dec 8, 2024
1 parent c1c59e7 commit c87a370
Showing 5 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-carrots-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: allow exports with source from script module even if no bind is present
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
@@ -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;

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
error: false
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script module>
export { blah } from "./blah.js";
</script>
22 changes: 15 additions & 7 deletions packages/svelte/tests/compiler-errors/test.ts
Original file line number Diff line number Diff line change
@@ -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<CompilerErrorTest>((config, cwd) => {
@@ -25,6 +27,9 @@ const { test, run } = suite<CompilerErrorTest>((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<CompilerErrorTest>((config, cwd) => {
}
}

if (!caught_error) {
if (config.error !== false && !caught_error) {
assert.fail('Expected an error');
}
}
@@ -50,6 +55,9 @@ const { test, run } = suite<CompilerErrorTest>((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<CompilerErrorTest>((config, cwd) => {
}
}

if (!caught_error) {
if (config.error !== false && !caught_error) {
assert.fail('Expected an error');
}
}

0 comments on commit c87a370

Please sign in to comment.