Description
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
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