Skip to content

Compiler wraps else/catch statements into comments #16286

Closed
@TheOtterlord

Description

@TheOtterlord

Describe the bug

Writing a comment on the same line as a closing if statement, but the line before an else statement fails, as the else statement is wrapped into the comment.

This begins happening in Svelte 5.35.0

<script>
	if (true) {
		console.log('a')
	} // This breaks things
	else {
		console.log('b')
	}
</script>

<p>
	Hello
</p>
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';

var root = $.from_html(`<p>Hello</p>`);

export default function App($$anchor) {
	if (true) {
		console.log('a');
	} // This breaks things else {
		console.log('b');
	}

	var p = root();

	$.append($$anchor, p);
}

Reproduction

https://svelte.dev/playground/hello-world?version=5.35.0#H4sIAAAAAAAAA22PwQ6CQAxEf2XTC5AYuBNi4s0P8CYeFii6se5uaBUN4d_dGhMvHue1M9Mu4O0NoYY9EgUzh4kGk-PgBIcCNjA6Qob6uIC8ou4pSPzr2sVY8gNJlHWW8R_vgxf0kmKg4X5yUbatb8WNJpfpjoVZVLaS9jgQlhTOeWazQulqqsocLo5NN6G9spGL82fWERLjX2v3tba-qX59vomf2s-jOlKZrhN8CtR6yHpKyjqanR-gHm3KX99b7N01IAEAAA==

Logs

Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
file: /home/otterlord/repos/.../src/components/CommentWidget.svelte:17:0

15: 
16:   $.append($$anchor, div);
17: }

System Info

System:
    OS: Linux 6.15 Arch Linux
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 20.81 GB / 31.13 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.11.0 - /run/user/1000/fnm_multishells/31167_1751477101541/bin/node
    npm: 10.9.0 - /run/user/1000/fnm_multishells/31167_1751477101541/bin/npm
    pnpm: 10.12.3 - ~/.local/share/pnpm/pnpm
    bun: 1.1.38 - ~/.bun/bin/bun
  Browsers:
    Chromium: 137.0.7151.119
  npmPackages:
    svelte: 5.35.0 => 5.35.0

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions