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 parser fails with generic components #2875

Closed
notramo opened this issue Mar 30, 2024 · 2 comments
Closed

Svelte parser fails with generic components #2875

notramo opened this issue Mar 30, 2024 · 2 comments
Labels
good first issue Experience Level - Good for newcomers

Comments

@notramo
Copy link

notramo commented Mar 30, 2024

The Svelte parser fails when the component has TypeScript generics.
This is valid Svelte syntax:

<script lang=ts generics="T extends Record<string, unknown>">

The TS generic type syntax in Record<string, unknown> is considered as closing > by the parser, disregarding that it's inside an attribute.

@Boshen Boshen added the good first issue Experience Level - Good for newcomers label Mar 31, 2024
@Boshen
Copy link
Member

Boshen commented Mar 31, 2024

Similar to #2017, we need to improve the parser to balance out the angle brackets or quotes.

The parsing code is here https://github.com/oxc-project/oxc/tree/main/crates/oxc_linter/src/partial_loader

PRs are welcome.

Boshen pushed a commit that referenced this issue Apr 7, 2024
While looking into this, I knew vue would have similar problems. Which
then led me to realize the generic case was handled already so I tried
abstract out the function so both the vue and svelte partial loaders
could reuse the code. Finally added some svelte test cases to prove this
resolved the issue.

I am a bit new to rust so if there was a better way to reuse the
find_script_closing_angle function open to suggestions.
@kalvenschraut
Copy link
Contributor

@Boshen this issue can be closed, not sure why it didn't auto close on my PR being merged

eryue0220 added a commit to eryue0220/oxc that referenced this issue Apr 7, 2024
…20/oxc into feat/jest-prefer-lowercase-title

* 'feat/jest-prefer-lowercase-title' of github.com:eryue0220/oxc:
  feat(linter/import): Add `ignoreTypes` option for the `import/no-cycle` rule (oxc-project#2905)
  fix(linter): handle self closing script tags in astro partial loader (oxc-project#2017) (oxc-project#2907)
  fix(linter): svelte partial loader handle generics (oxc-project#2875) (oxc-project#2906)
  fix(tasks/rulegen): read quasi in TaggedTemplateExpression (oxc-project#2903)
@Boshen Boshen closed this as completed Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Experience Level - Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants