Fixes #13135

---------

Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
pull/13110/head
Rich Harris 1 year ago committed by GitHub
parent 2b362ddc63
commit dfe23a1233
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: Ensure imports are above other statements

@ -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),

@ -1,33 +0,0 @@
import "svelte/internal/disclose-version";
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) {
var picture = root();
var source = $.child(picture);
$.set_attribute(source, "srcset", __ENHANCED_IMG_1__ + " 1440w, " + __ENHANCED_IMG_2__ + " 960w");
var source_1 = $.sibling(source, 2);
$.set_attribute(source_1, "srcset", __ENHANCED_IMG_3__ + " 1440w, " + __ENHANCED_IMG_4__ + " 960w");
var source_2 = $.sibling(source_1, 2);
$.set_attribute(source_2, "srcset", __ENHANCED_IMG_5__ + " 1440w, " + __ENHANCED_IMG_6__ + " 960w");
var img = $.sibling(source_2, 2);
$.set_attribute(img, "src", __ENHANCED_IMG_5__);
$.reset(picture);
$.append($$anchor, picture);
}

@ -1,12 +0,0 @@
import * as $ from "svelte/internal/server";
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__";
export default function Inline_module_vars($$payload) {
$$payload.out += `<picture><source${$.attr("srcset", __ENHANCED_IMG_1__ + " 1440w, " + __ENHANCED_IMG_2__ + " 960w")} type="image/avif"> <source${$.attr("srcset", __ENHANCED_IMG_3__ + " 1440w, " + __ENHANCED_IMG_4__ + " 960w")} type="image/webp"> <source${$.attr("srcset", __ENHANCED_IMG_5__ + " 1440w, " + __ENHANCED_IMG_6__ + " 960w")} type="image/png"> <img${$.attr("src", __ENHANCED_IMG_5__)} alt="production test" width="1440" height="1440"></picture>`;
}

@ -1,17 +0,0 @@
<svelte:options runes={true} />
<script module>
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__";
</script>
<picture>
<source srcset={__ENHANCED_IMG_1__ + " 1440w, " + __ENHANCED_IMG_2__ + " 960w"} type="image/avif" />
<source srcset={__ENHANCED_IMG_3__ + " 1440w, " + __ENHANCED_IMG_4__ + " 960w"} type="image/webp" />
<source srcset={__ENHANCED_IMG_5__ + " 1440w, " + __ENHANCED_IMG_6__ + " 960w"} type="image/png" />
<img src={__ENHANCED_IMG_5__} alt="production test" width=1440 height=1440 />
</picture>
Loading…
Cancel
Save