Skip to content

Commit dfe23a1

Browse files
fix: revert #13048 (#13132)
Fixes #13135 --------- Co-authored-by: Simon Holthausen <[email protected]>
1 parent 2b362dd commit dfe23a1

File tree

5 files changed

+21
-63
lines changed

5 files changed

+21
-63
lines changed

.changeset/proud-lobsters-lie.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: Ensure imports are above other statements

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,22 @@ export function client_component(analysis, options) {
457457
analysis.uses_slots ||
458458
analysis.slot_names.size > 0;
459459

460-
const body = [...module.body, ...state.hoisted];
460+
// Merge hoisted statements into module body.
461+
// Ensure imports are on top, with the order preserved, then module body, then hoisted statements
462+
/** @type {ESTree.ImportDeclaration[]} */
463+
const imports = [];
464+
/** @type {ESTree.Program['body']} */
465+
let body = [];
466+
467+
for (const entry of [...module.body, ...state.hoisted]) {
468+
if (entry.type === 'ImportDeclaration') {
469+
imports.push(entry);
470+
} else {
471+
body.push(entry);
472+
}
473+
}
474+
475+
body = [...imports, ...body];
461476

462477
const component = b.function_declaration(
463478
b.id(analysis.name),

packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/server/index.svelte.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/svelte/tests/snapshot/samples/inline-module-vars/index.svelte

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)