Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte-check hangs on <script> tag with specific attributes #2363

Open
shadow-identity opened this issue May 3, 2024 · 8 comments
Open

svelte-check hangs on <script> tag with specific attributes #2363

shadow-identity opened this issue May 3, 2024 · 8 comments
Labels
bug Something isn't working perf Performance

Comments

@shadow-identity
Copy link
Contributor

shadow-identity commented May 3, 2024

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

  1. Create a Svelte component file, or check out simplified reproduction repository, or check out existing one
    <script
        defer
        src='fds'
        on:load={() => {}}
    >
    </script>
  1. 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

@jasonlyu123
Copy link
Member

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.

@jasonlyu123 jasonlyu123 added the perf Performance label May 13, 2024
@shadow-identity
Copy link
Contributor Author

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'

@jasonlyu123
Copy link
Member

jasonlyu123 commented May 22, 2024

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.

@shadow-identity
Copy link
Contributor Author

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.

@jasonlyu123
Copy link
Member

jasonlyu123 commented May 22, 2024

I can't reproduce the parser error with the linked component in both Svelte 4 and 5. Please provide a reproduction repository.

@shadow-identity
Copy link
Contributor Author

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.

@shadow-identity
Copy link
Contributor Author

shadow-identity commented May 22, 2024

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.

@jasonlyu123
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working perf Performance
Projects
None yet
Development

No branches or pull requests

2 participants