-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Re-introduce automatic var injection shorthand #15020
Merged
Merged
Conversation
This file contains 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
RobinMalfait
force-pushed
the
feat/automatic-var-injection
branch
2 times, most recently
from
November 18, 2024 11:26
71e621c
to
b696bc3
Compare
RobinMalfait
changed the title
Re-introduce automatic var injection
Re-introduce automatic var injection shorthand
Nov 18, 2024
thecrypticace
approved these changes
Nov 18, 2024
This parses it as an arbitrary value where the `var(…)` surroundings are omitted.
Fallbacks, dataType hints and modifiers also get the same treatment.
Combine the `in_arbitrary` and `idx_arbitrary_start` variables into an enum. In the next commit we will introduce the `Arbitrary::Parens` state for arbitrary value shorthand for variables. E.g.: `bg-(--my-var)`.
RobinMalfait
force-pushed
the
feat/automatic-var-injection
branch
from
November 18, 2024 12:58
7355087
to
ba164be
Compare
adamwathan
reviewed
Nov 18, 2024
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
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 re-introduces the automatic var injection feature.
For some backstory, we used to support classes such as
bg-[--my-color]
that resolved as-if you wrotebg-[var(--my-color)]
.The is issue is that some newer CSS properties accepts dashed-idents (without the
var(…)
). This means that some properties acceptview-timeline-name: --my-name;
(see: https://developer.mozilla.org/en-US/docs/Web/CSS/view-timeline-name).To make this a tiny bit worse, these properties also accept
var(--my-name-reference)
where the variable--my-name-reference
could reference a dashed-ident such as--my-name
.This makes the
bg-[--my-color]
ambiguous because we don't know if you wantvar(--my-color)
or--my-color
.With this PR, we bring back the automatic var injection feature as syntactic sugar, but we use a different syntax to avoid the ambiguity. Instead of
bg-[--my-color]
, you can now writebg-(--my-color)
to get the same effect asbg-[var(--my-color)]
.This also applies to modifiers, so
bg-red-500/[var(--my-opacity)]
can be written asbg-red-500/(--my-opacity)
. To go full circle, you can rewritebg-[var(--my-color)]/[var(--my-opacity)]
asbg-(--my-color)/(--my-opacity)
.This is implemented as syntactical sugar at the parsing stage and handled when re-printing. Internally the system (and every plugin) still see the proper
var(--my-color)
value.Since this is also handled during printing of the candidate, codemods don't need to be changed but they will provide the newly updated syntax.
E.g.: running this on the Catalyst codebase, you'll now see changes like this:
Whereas before we converted this to the much longer
min-w-[var(--button-width)]
.Additionally, this required some changes to the Oxide scanner to make sure that
(
and)
are valid characters for arbitrary-like values.