Skip to content

[AST] Incorrect parsing of comments inside the callback scope #13040

Open
@xeho91

Description

@xeho91

Describe the bug

Sorry in advance, but I might be bringing a PITA with comments, again.

I noticed while working on updating svelte-ast-print, I've had inline snapshots mismatch (thanks Vitest!).
There was a bug which I've overlooked before and noticed that something was off. I was able to narrow that there's a parsing difference between version svelte@5.0.0-next.190 and svelte@5.0.0-next.191. Regardless, both versions parse it wrongly, including the latest one.

Possibly related PR: #12471

Piece of input inside the <script> tag that gets parsed wrong:

beforeUpdate(() => {
  // determine whether we should auto-scroll
  // once the DOM is updated...
});

afterUpdate(() => {
  // ...the DOM is now in sync with the data
});

svelte@5.0.0-next.190

svelte@5.0.0-next.191

-       beforeUpdate(() => {
-               // determine whether we should auto-scroll
+       beforeUpdate(() => {}); // determine whether we should auto-scroll
-               // once the DOM is updated...
+       // once the DOM is updated...
-       });
-
-       afterUpdate(() => {
-               // ...the DOM is now in sync with the data
-       });
+       afterUpdate(() => {}); // ...the DOM is now in sync with the data
-       beforeUpdate(() => {
+       beforeUpdate(() => {});
-               // determine whether we should auto-scroll
+       // determine whether we should auto-scroll
-               // once the DOM is updated...
+       // once the DOM is updated...
-       });
-
-       afterUpdate(() => {
+       afterUpdate(() => {});
+
-               // ...the DOM is now in sync with the data
+       // ...the DOM is now in sync with the data
-       });
-

Below I will provide a simple reproduction where you can see that the comment inside the callback scope of beforeUpdate() gets wrongly parsed as trailingComments.

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE02OywrCMBBFf2WYTS0Uum-14D_oyriIyZQG8yIzFaT03yUI4vIezoG74ew8MQ63DaMOhAOec8YO5Z3r4Bd5IeyQ01pMJUc2xWWZVFTiQk5FYIMHzanQNVstBDvMJQVovm0zqljdf-VwaOE0wVa5kr6Hy-IYTAqBogAvafUWWPQbXGRnCYz2_qHNE9ikTDXb21HFY_87gx2GZN3syOIgZaX9vn8AcUwca90AAAA=

Logs

No response

System Info

next

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions