Parse candidates in .svelte files with class:abc="condition" syntax#13274
Merged
RobinMalfait merged 9 commits intonextfrom Mar 18, 2024
Merged
Parse candidates in .svelte files with class:abc="condition" syntax#13274RobinMalfait merged 9 commits intonextfrom
.svelte files with class:abc="condition" syntax#13274RobinMalfait merged 9 commits intonextfrom
Conversation
In svelte there is a convention where you can use `<div class:px-4="condition" />` which means that we extract `class:px-4` as a utility where `class` is a variant. This is obviously incorrect, to solve this we can ignore the `class:` part before parsing the whole file. This is also what we do in v3. Ideally we have completely separate parsers for various programming languages (based on file type) and fallback to the generic one we have now. Implementing that, is a much bigger scope.
There is some funky stuff happening when running `cargo test` where it sees contents from another test. Maybe a bug in the tmpdir crate. I don't see this problem locally when running `cargo nextest run`, but when using the native `cargo test` command it fails.
CHANGELOG.md
Outdated
| - Move the CLI into a separate `@tailwindcss/cli` package ([#13095](https://github.com/tailwindlabs/tailwindcss/pull/13095)) | ||
|
|
||
| ## [4.0.0-alpha.1] - 2024-03-06 | ||
|
|
Contributor
There was a problem hiding this comment.
This is causing linting to fail. We probably should have something here though. Maybe line - Initial release or something?
thecrypticace
suggested changes
Mar 18, 2024
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
thecrypticace
approved these changes
Mar 18, 2024
ryanylee
reviewed
Mar 21, 2024
| // A file that is ignored | ||
| ("foo.html", Some("lg:font-bold")), | ||
| // A svelte file with `class:foo="bar"` syntax | ||
| ("index.svelte", Some("<div class:px-4='condition'></div>")), |
There was a problem hiding this comment.
In Svelte, expression would be in squiggly brackets and not quotes
<div class:px-4={condition}>
|
RobinMalfait I think this still isn't working in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces backwards compatibility for the
class:syntax in Svelte files.In Svelte there is a convention where you can use
<div class:px-4="condition" />which allows you to apply thepx-4class conditionally based on a condition. This also means that we extractclass:px-4as a utility whereclassis a variant andpx-4is the utility.This is obviously incorrect, to solve this we can ignore the
class:part before parsing the whole file.This is also what we do in v3.
In a perfect world, we have more specific parsers depending on the file type before using the generic parser we use now. But that's a bigger project on its own way beyond the scope of this PR.
Fixes: #13263