Skip to content

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

Merged
RobinMalfait merged 9 commits intonextfrom
fix/issue-13263
Mar 18, 2024
Merged

Parse candidates in .svelte files with class:abc="condition" syntax#13274
RobinMalfait merged 9 commits intonextfrom
fix/issue-13263

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
- 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?

RobinMalfait and others added 3 commits March 18, 2024 22:49
@RobinMalfait RobinMalfait merged commit f3e7880 into next Mar 18, 2024
@RobinMalfait RobinMalfait deleted the fix/issue-13263 branch March 18, 2024 22:24
// 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