Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hoist imports on top #13082

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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/hip-beers-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: hoist imports on top
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ export function client_component(analysis, options) {
analysis.uses_slots ||
analysis.slot_names.size > 0;

const body = [...module.body, ...state.hoisted];
// we hoist all the import declarations to the top of the file
const body = [...module.body, ...state.hoisted].sort((body_a, body_b) =>
body_a.type === 'ImportDeclaration' ? -1 : 1
paoloricciuti marked this conversation as resolved.
Show resolved Hide resolved
);

const component = b.function_declaration(
b.id(analysis.name),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
import TextInput from './Child.svelte';
import * as $ from "svelte/internal/client";

var root = $.template(`<!> `, 1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
import { random } from './module.svelte';
import * as $ from "svelte/internal/client";

export default function Imports_in_modules($$anchor) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";

const __ENHANCED_IMG_1__ = "__VITE_ASSET__2AM7_y_a__";
const __ENHANCED_IMG_2__ = "__VITE_ASSET__2AM7_y_b__";
const __ENHANCED_IMG_3__ = "__VITE_ASSET__2AM7_y_c__";
const __ENHANCED_IMG_4__ = "__VITE_ASSET__2AM7_y_d__";
const __ENHANCED_IMG_5__ = "__VITE_ASSET__2AM7_y_e__";
const __ENHANCED_IMG_6__ = "__VITE_ASSET__2AM7_y_f__";

import * as $ from "svelte/internal/client";

var root = $.template(`<picture><source type="image/avif"> <source type="image/webp"> <source type="image/png"> <img alt="production test" width="1440" height="1440"></picture>`);

export default function Inline_module_vars($$anchor) {
Expand Down