sveltejs/svelte

Closing script tag in comment causes error

Closed this issue · 4 comments

Describe the bug

Including "</script>" in a comment leads to an error, either "</script> attempted to close an element that was not open" or "Unterminated comment", depending on whether a single or multiline comment was used. This is an issue because certain libraries (eg Runed) include script tags in examples in jsdoc comments.

From some testing it looks like this issue only manifests in code in node_modules when svelte-preprocess is used.

Reproduction

https://svelte.dev/playground/54541fdd150141188a698ae9f9d38f0c?version=5.43.0

Logs

Single line comment:
Error: Unterminated comment

Multiline comment:
`</script>` attempted to close an element that was not open

System Info

REPL with svelte v5.43.0

Severity

annoyance

7nik commented

This is an issue because certain libraries (eg Runed) include script tags in examples in jsdoc comments.

The example is a *.ts file where this is not an issue.

It is an issue, at least when using svelte-preprocess. Should I reopen this issue on that repo?

Here's a small reproduction with esbuild-svelte: reproduction.zip (run node build.js)

7nik commented

From what I see and understand, esbuild-svelte (?) tries to parse the code example in the JSDoc comment in debounced.svelte.js but fails because each line is prepended with * .
So, I don't see how it is related to </script>.

Oh weird, just tested it with rollup and the same error doesn't happen. Looks like I misattributed the issue to svelte itself. Thanks for the help!