Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-lobsters-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: Ensure imports are above other statements
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,22 @@ export function client_component(analysis, options) {
analysis.uses_slots ||
analysis.slot_names.size > 0;

const body = [...module.body, ...state.hoisted];
// Merge hoisted statements into module body.
// Ensure imports are on top, with the order preserved, then module body, then hoisted statements
/** @type {ESTree.ImportDeclaration[]} */
const imports = [];
/** @type {ESTree.Program['body']} */
let body = [];

for (const entry of [...module.body, ...state.hoisted]) {
if (entry.type === 'ImportDeclaration') {
imports.push(entry);
} else {
body.push(entry);
}
}

body = [...imports, ...body];

const component = b.function_declaration(
b.id(analysis.name),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.