svelte-check hangs on <script> tag with specific attributes
Closed this issue · 8 comments
Describe the bug
svelte-check hangs on svelte file containing <script>
tag with particular set of attributes.
I noticed it because it was failing on this file.
Finally I was able to make a minimal reproduction.
Reproduction
- Create a Svelte component file, or check out simplified reproduction repository, or check out existing one
<script
defer
src='fds'
on:load={() => {}}
>
</script>
- Run
svelte-check
on it
Leading paces matters. Without spaces, it does not hang, but returns an error. But it doesn't change anything if the <script>
is inside of another tag (still hangs).
! It is not reproduced in the reproduction repository. Only hanging is reproduced.
/Users/src/routes/Matomo.svelte:4:17
Error: Expected > (svelte)
src='fds'
on:load={() => {}}
>
/Users/src/routes/Matomo.svelte:4:17
Error: Expected > (js)
src='fds'
on:load={() => {}}
>
It does not hangs nor returns error if any of attributes are missing. So all the attributes matters
Expected behaviour
It should never hang, because it is bad for CI/CD, pre-commit hooks, editors etc.
System Info
- OS: macOS 14.4.1 (23E224), intel
- "svelte": "^4.2.15"
- "@sveltejs/adapter-static": "^3.0.1",
- "@sveltejs/kit": "^2.5.7",
- "@sveltejs/vite-plugin-svelte": "^3.1.0",
- "svelte-check": "^3.7.1",
Which package is the issue about?
No response
Additional Information, eg. Screenshots
I believe it is related to similar prettier-plugin-svelte
issue
The hang is because of the regex for the script tag that is present in prettier-plugin-svelte, svelte and language-tools. It seems like the problem has to do with the multiple-line script tag. So until it's fixed, you can work around it by putting all the script tag attributes in one line.
Nope, having it in one line causes the same issue:
/Users/pnedrigailov/workspace/location-insights/frontend/dashboard/src/routes/(root)/+layout.svelte:1:34
Error: Expected > (svelte)
<script defer src='' on:load={() => {}} lang="ts">
import { setContext } from 'svelte'
The event won't work on top-level script tag so I think this is expected. The same error also exists in the svelte REPL.
It fails on every level, not only on the top level. See https://gitlab.com/dexterlabs/dexlib/-/blob/f0679dc96428418e91c00ac879d15d762483ffed/packages/svelte-matomo/src/index.svelte for example.
I can't reproduce the parser error with the linked component in both Svelte 4 and 5. Please provide a reproduction repository.
Sure. The reproduction repository can be found here: https://github.com/shadow-identity/sveltejs-language-tools-issues-2363
Check it out, install dependencies and do npm run check
.
I also updated the description.
Tho I was not able to reproduce the case with the error. It really appears if the <script> is on the top level, so not a bug (probably). Where is the regexp from your first comment is located? I can file a bug there.
A similar regex is in the svelte, prettier-plugin-svelte and language tools. There's already a related issue for Svelte core sveltejs/svelte#9564.