Skip to content

Commit fcc81f9

Browse files
committed
prefer positive candidates over negative candidates
Right now, when we _know_ that a replacement utility exist, then we use it immediately. However, if multiple match then we don't really know what to do so up until now we just bailed. But the funny part is that `-tracking-wide` and `tracking-tight` result in the exact same signature. In this situation, we pick the positive value instead of the negative value. If at any point, multiple positive utilities exist, we bail again. So this only covers the above scenario where a negative and positive utility was present.
1 parent 595f639 commit fcc81f9

1 file changed

Lines changed: 46 additions & 10 deletions

File tree

packages/tailwindcss/src/canonicalize-candidates.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,29 @@ function arbitraryUtilities(candidate: Candidate, options: InternalCanonicalizeO
11281128
// Find a corresponding utility for the same signature
11291129
let replacements = utilities.get(targetSignature)
11301130

1131-
// Multiple utilities can map to the same signature. Not sure how to migrate
1132-
// this one so let's just skip it for now.
1133-
//
1134-
// TODO: Do we just migrate to the first one?
1135-
if (replacements.length > 1) return
1131+
// Multiple utilities can map to the same signature.
1132+
if (replacements.length > 1) {
1133+
// Prefer positive values over negative values
1134+
let maybeReplacement: string | undefined = undefined
1135+
for (let replacement of replacements) {
1136+
if (replacement[0] === '-') continue // Skip negative values
1137+
1138+
// If multiple non-negative replacements exists then we are unsure
1139+
// what to do, so let's bail.
1140+
if (maybeReplacement) return
1141+
1142+
// Consider this replacement
1143+
maybeReplacement = replacement
1144+
}
1145+
1146+
if (maybeReplacement) {
1147+
for (let replacementCandidate of parseCandidate(designSystem, maybeReplacement)) {
1148+
yield replacementCandidate
1149+
}
1150+
}
1151+
1152+
return
1153+
}
11361154

11371155
// If we didn't find any replacement utilities, let's try to strip the
11381156
// modifier and find a replacement then. If we do, we can try to re-add the
@@ -1353,11 +1371,29 @@ function bareValueUtilities(candidate: Candidate, options: InternalCanonicalizeO
13531371
// Find a corresponding utility for the same signature
13541372
let replacements = utilities.get(targetSignature)
13551373

1356-
// Multiple utilities can map to the same signature. Not sure how to migrate
1357-
// this one so let's just skip it for now.
1358-
//
1359-
// TODO: Do we just migrate to the first one?
1360-
if (replacements.length > 1) return
1374+
// Multiple utilities can map to the same signature.
1375+
if (replacements.length > 1) {
1376+
// Prefer positive values over negative values
1377+
let maybeReplacement: string | undefined = undefined
1378+
for (let replacement of replacements) {
1379+
if (replacement[0] === '-') continue // Skip negative values
1380+
1381+
// If multiple non-negative replacements exists then we are unsure
1382+
// what to do, so let's bail.
1383+
if (maybeReplacement) return
1384+
1385+
// Consider this replacement
1386+
maybeReplacement = replacement
1387+
}
1388+
1389+
if (maybeReplacement) {
1390+
for (let replacementCandidate of parseCandidate(designSystem, maybeReplacement)) {
1391+
yield replacementCandidate
1392+
}
1393+
}
1394+
1395+
return
1396+
}
13611397

13621398
// If we didn't find any replacement utilities, let's try to strip the
13631399
// modifier and find a replacement then. If we do, we can try to re-add the

0 commit comments

Comments
 (0)