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

Parse candidates in .svelte files with class:abc="condition" syntax #13274

Merged
merged 9 commits into from
Mar 18, 2024

Conversation

RobinMalfait
Copy link
Member

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 the px-4 class conditionally based on a condition. This also means that we extract class:px-4 as a utility where class is a variant and px-4 is 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

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
@@ -108,3 +109,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing linting to fail. We probably should have something here though. Maybe line - Initial release or something?

oxide/crates/core/src/lib.rs Outdated Show resolved Hide resolved
RobinMalfait and others added 3 commits March 18, 2024 22:49
@RobinMalfait RobinMalfait merged commit f3e7880 into next Mar 18, 2024
1 check passed
@RobinMalfait RobinMalfait deleted the fix/issue-13263 branch March 18, 2024 22:24
@@ -297,9 +297,14 @@ mod auto_content {
("foo.jpg", Some("xl:font-bold")),
// 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>")),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Svelte, expression would be in squiggly brackets and not quotes
<div class:px-4={condition}>

@ryanylee
Copy link

RobinMalfait I think this still isn't working in 4.0.0-alpha.10. I think it has to do with class:abc="condition" actually being class:abc={condition} in .svelte files

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.

3 participants