Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
extract baseCandidate
  • Loading branch information
RobinMalfait committed May 13, 2025
commit 5526698eb5b125799c05dce51a7f14061e10a749
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Scanner } from '@tailwindcss/oxide'
import type { Candidate } from '../../../../tailwindcss/src/candidate'

export async function extractRawCandidates(
content: string,
Expand All @@ -13,3 +14,13 @@ export async function extractRawCandidates(
}
return candidates
}

// Create a basic stripped candidate without variants or important flag
export function baseCandidate<T extends Candidate>(candidate: T) {
let base = structuredClone(candidate)

base.important = false
base.variants = []

return base
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DefaultMap } from '../../../../tailwindcss/src/utils/default-map'
import * as ValueParser from '../../../../tailwindcss/src/value-parser'
import { dimensions } from '../../utils/dimension'
import type { Writable } from '../../utils/types'
import { baseCandidate } from './candidates'
import { computeUtilitySignature, preComputedUtilities } from './signatures'

const baseReplacementsCache = new DefaultMap<DesignSystem, Map<string, Candidate>>(
Expand Down Expand Up @@ -79,9 +80,7 @@ export function migrateArbitraryUtilities(
// will re-add those later but they are irrelevant for what we are trying to
// do here (and will increase cache hits because we only have to deal with
// the base utility, nothing more).
let targetCandidate = structuredClone(candidate)
targetCandidate.important = false
targetCandidate.variants = []
let targetCandidate = baseCandidate(candidate)

let targetCandidateString = designSystem.printCandidate(targetCandidate)
if (baseReplacementsCache.get(designSystem).has(targetCandidateString)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Config } from '../../../../tailwindcss/src/compat/plugin-api'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import { DefaultMap } from '../../../../tailwindcss/src/utils/default-map'
import * as version from '../../utils/version'
import { baseCandidate } from './candidates'
import { isSafeMigration } from './is-safe-migration'

const __filename = url.fileURLToPath(import.meta.url)
Expand Down Expand Up @@ -92,10 +93,8 @@ export async function migrateLegacyClasses(
for (let candidate of designSystem.parseCandidate(rawCandidate)) {
// Create a base candidate string from the candidate.
// E.g.: `hover:blur!` -> `blur`
let baseCandidate = structuredClone(candidate) as Candidate
baseCandidate.variants = []
baseCandidate.important = false
let baseCandidateString = designSystem.printCandidate(baseCandidate)
let base = baseCandidate(candidate)
let baseCandidateString = designSystem.printCandidate(base)

// Find the new base candidate string. `blur` -> `blur-sm`
let newBaseCandidateString = LEGACY_CLASS_MAP.get(baseCandidateString)
Expand Down