Skip to content

Fix crash when formatting svelte files that have "let:class".#24

Merged
bradlc merged 2 commits intotailwindlabs:mainfrom
chrsep:main
Jan 27, 2022
Merged

Fix crash when formatting svelte files that have "let:class".#24
bradlc merged 2 commits intotailwindlabs:mainfrom
chrsep:main

Conversation

@chrsep
Copy link
Copy Markdown
Contributor

@chrsep chrsep commented Jan 26, 2022

Hi there, I encountered a crash when running the plugin on a svelte file that has a slot component like this:

  <p
    slot="test"
    let:class={className}
    class="h-full w-full p-2 backdrop-blur-0 {className}"
  />

Below was the error message and I've got a repro here:

image

I found that the plugin was trying to read the "value" attribute from the let directive, which is always undefined. So to avoid this, I added a check to make sure that the sorting only runs on the class attributes, not on a directive named class such as let:class={className}.

@bradlc
Copy link
Copy Markdown
Contributor

bradlc commented Jan 27, 2022

Thank you!

@bradlc bradlc merged commit f3a4a28 into tailwindlabs:main Jan 27, 2022
bronisMateusz pushed a commit to bronisMateusz/prettier-plugin-tailwindcss-drupal that referenced this pull request Apr 16, 2025
…ndlabs#24)

* Add tests for svelte's let directive.

* Avoid formatting svelte's let directive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants