Skip to content

Minify arbitrary values when printing candidates#14720

Merged
RobinMalfait merged 8 commits into
nextfrom
robin/simplify_candidate_printing
Oct 18, 2024
Merged

Minify arbitrary values when printing candidates#14720
RobinMalfait merged 8 commits into
nextfrom
robin/simplify_candidate_printing

Conversation

@RobinMalfait

@RobinMalfait RobinMalfait commented Oct 18, 2024

Copy link
Copy Markdown
Member

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

RobinMalfait commented Oct 18, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Comment thread packages/@tailwindcss-upgrade/src/template/candidates.test.ts
Comment thread packages/@tailwindcss-upgrade/src/template/candidates.ts Outdated
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
Comment thread packages/@tailwindcss-upgrade/src/template/candidates.ts
@RobinMalfait RobinMalfait merged commit 2abf228 into next Oct 18, 2024
@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