Skip to content

Commit c87a370

Browse files
committed
fix: allow exports with source from script module even if no bind is present
1 parent c1c59e7 commit c87a370

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

.changeset/four-carrots-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: allow exports with source from script module even if no bind is present

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ export function analyze_component(root, source, options) {
698698
}
699699

700700
for (const node of analysis.module.ast.body) {
701-
if (node.type === 'ExportNamedDeclaration' && node.specifiers !== null) {
701+
if (node.type === 'ExportNamedDeclaration' && node.specifiers !== null && node.source == null) {
702702
for (const specifier of node.specifiers) {
703703
if (specifier.local.type !== 'Identifier') continue;
704704

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: false
5+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script module>
2+
export { blah } from "./blah.js";
3+
</script>

packages/svelte/tests/compiler-errors/test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { suite, type BaseTest } from '../suite';
55
import { read_file } from '../helpers.js';
66

77
interface CompilerErrorTest extends BaseTest {
8-
error: {
9-
code: string;
10-
message: string;
11-
position?: [number, number];
12-
};
8+
error:
9+
| {
10+
code: string;
11+
message: string;
12+
position?: [number, number];
13+
}
14+
| false;
1315
}
1416

1517
const { test, run } = suite<CompilerErrorTest>((config, cwd) => {
@@ -25,6 +27,9 @@ const { test, run } = suite<CompilerErrorTest>((config, cwd) => {
2527
generate: 'client'
2628
});
2729
} catch (e) {
30+
if (config.error === false) {
31+
assert.fail('Unexpected error');
32+
}
2833
const error = e as CompileError;
2934

3035
caught_error = true;
@@ -37,7 +42,7 @@ const { test, run } = suite<CompilerErrorTest>((config, cwd) => {
3742
}
3843
}
3944

40-
if (!caught_error) {
45+
if (config.error !== false && !caught_error) {
4146
assert.fail('Expected an error');
4247
}
4348
}
@@ -50,6 +55,9 @@ const { test, run } = suite<CompilerErrorTest>((config, cwd) => {
5055
generate: 'client'
5156
});
5257
} catch (e) {
58+
if (config.error === false) {
59+
assert.fail('Unexpected error');
60+
}
5361
const error = e as CompileError;
5462

5563
caught_error = true;
@@ -62,7 +70,7 @@ const { test, run } = suite<CompilerErrorTest>((config, cwd) => {
6270
}
6371
}
6472

65-
if (!caught_error) {
73+
if (config.error !== false && !caught_error) {
6674
assert.fail('Expected an error');
6775
}
6876
}

0 commit comments

Comments
 (0)