Skip to content

[Svelte 5] Regression in JS output - script context module variable declarations before import statements #13135

Closed
@xeho91

Description

@xeho91

Describe the bug

Hi awesome Svelte maintainers!

There's a regression in JS output. I happen to notice it while upgrading svelte to latest version.
Below is the screenshot from when I was trying to inspect as to why the build isn't working anymore.
image

I'll summarise shortly. Variable declarations inside the <script module> tag in the JS output are above the import declarations. Which is... invalid, right? Right?!

With the help of @JReinhold and his amazingly quick search skills, we've managed to narrow down when this regression happened.

So, latest working version is 5.0.0-next.240

Reading the changelogs, I couldn't figure out which one of PR is the culprit, sorry! 😦

Reproduction

A quick comparison in the JS output:

5.0.0-next.240

5.0.0-next.243

import * as $ from "svelte/internal/client";
import { confetti } from '@neoconfetti/svelte';

var root = $.template(`<div></div>`);
const result = confetti();

export default function App($$anchor, $$props) {
	$.push($$props, false);
	$.init();

	var div = root();

	$.append($$anchor, div);
	$.pop();
}
const result = confetti();

import * as $ from "svelte/internal/client";
import { confetti } from '@neoconfetti/svelte';

var root = $.template(`<div></div>`);

export default function App($$anchor, $$props) {
	$.push($$props, false);
	$.init();

	var div = root();

	$.append($$anchor, div);
	$.pop();
}

Diff overview, because I'm nice (nah, I love Svelte).

```js
+ const result = confetti();
+ 
import * as $ from "svelte/internal/client";
import { confetti } from '@neoconfetti/svelte';

var root = $.template(`<div></div>`);
- const result = confetti();

export default function App($$anchor, $$props) {
	$.push($$props, false);
	$.init();

	var div = root();

	$.append($$anchor, div);
	$.pop();
}

Logs

No response

System Info

next

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions