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

Minify arbitrary values when printing candidates #14720

Merged
merged 8 commits into from
Oct 18, 2024

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Oct 18, 2024

This PR will optimize and simplify the candidates when printing the candidate again after running codemods.

When we parse a candidate, we will add spaces around operators, for example p-[calc(1px+1px)]] will internally be handled as calc(1px + 1px). Before this change, we would re-print this as: p-[calc(1px_+_1px)].

This PR changes that by simplifying the candidate again so that the output is p-[calc(1px+1px)]. In addition, if you wrote p-[calc(1px_+_1px)] then we will also simplify it to the concise form p-[calc(1px_+_1px)].

Some examples:

Input:

<div class="[p]:flex"></div>
<div class="[&:is(p)]:flex"></div>
<div class="has-[p]:flex"></div>
<div class="px-[theme(spacing.4)-1px]"></div>

Output before:

<div class="[&:is(p)]:flex"></div>
<div class="[&:is(p)]:flex"></div>
<div class="has-[&:is(p)]:flex"></div>
<div class="px-[var(--spacing-4)_-_1px]"></div>

Output after:

<div class="[p]:flex"></div>
<div class="[p]:flex"></div>
<div class="has-[p]:flex"></div>
<div class="px-[var(--spacing-4)-1px]"></div>

This is alternative implementation to #14717 and #14718
Closes: #14717
Closes: #14718

@RobinMalfait RobinMalfait requested a review from a team as a code owner October 18, 2024 15:36
Copy link
Member Author

RobinMalfait commented Oct 18, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @RobinMalfait and the rest of your teammates on Graphite Graphite

'hover:peer-[&_p]:',
'hover:peer-[&_p]:focus:',
'peer-[&:hover]:peer-[&_p]:',
['', ''], // no variant
Copy link
Member Author

Choose a reason for hiding this comment

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

Created a tuple with in and out (similar to the candidate above)

@RobinMalfait RobinMalfait changed the title Simplify candidate printing Minify arbitrary values when printing candidates Oct 18, 2024
This is the only thing where I know we _don't_ want spaces. But this was
already handled when adding spaces internally.
@RobinMalfait RobinMalfait force-pushed the robin/simplify_candidate_printing branch from c22846e to 8500630 Compare October 18, 2024 18:11
@RobinMalfait RobinMalfait merged commit 2abf228 into next Oct 18, 2024
2 checks passed
@RobinMalfait RobinMalfait deleted the robin/simplify_candidate_printing branch October 18, 2024 20:44
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