compileCandidates() — tailwindcss Function Reference
Architecture documentation for the compileCandidates() function in compile.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD f611bd99_74d3_1161_f7f5_4c1d73c377e5["compileCandidates()"] 214bac69_e516_bea4_67fa_4e9e092ced3b["compile.ts"] f611bd99_74d3_1161_f7f5_4c1d73c377e5 -->|defined in| 214bac69_e516_bea4_67fa_4e9e092ced3b 96876152_5423_5f9b_9f88_1db666070351["substituteAtApply()"] 96876152_5423_5f9b_9f88_1db666070351 -->|calls| f611bd99_74d3_1161_f7f5_4c1d73c377e5 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed["buildDesignSystem()"] 9b965fd7_d8e9_0b43_cd5d_c9294ab598ed -->|calls| f611bd99_74d3_1161_f7f5_4c1d73c377e5 ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb["compileAst()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| f611bd99_74d3_1161_f7f5_4c1d73c377e5 58b955a9_8496_3780_d1da_e267f826d91a["getClassOrder()"] 58b955a9_8496_3780_d1da_e267f826d91a -->|calls| f611bd99_74d3_1161_f7f5_4c1d73c377e5 d4b90da0_01b5_b21d_ff05_b37798744576["parseCandidate()"] f611bd99_74d3_1161_f7f5_4c1d73c377e5 -->|calls| d4b90da0_01b5_b21d_ff05_b37798744576 e37ec412_58f3_7fbe_3589_99329ee9b910["set()"] f611bd99_74d3_1161_f7f5_4c1d73c377e5 -->|calls| e37ec412_58f3_7fbe_3589_99329ee9b910 e57db502_ed4e_4f14_1b2a_b25af3c0477d["compileAstNodes()"] f611bd99_74d3_1161_f7f5_4c1d73c377e5 -->|calls| e57db502_ed4e_4f14_1b2a_b25af3c0477d df728a67_bdd0_0789_98a1_af70e5020cd5["has()"] f611bd99_74d3_1161_f7f5_4c1d73c377e5 -->|calls| df728a67_bdd0_0789_98a1_af70e5020cd5 826fa88e_aa5d_5bf5_f2c6_9a0302d5b02f["get()"] f611bd99_74d3_1161_f7f5_4c1d73c377e5 -->|calls| 826fa88e_aa5d_5bf5_f2c6_9a0302d5b02f 7787e2e6_2e19_8e07_7666_21a94194841f["compare()"] f611bd99_74d3_1161_f7f5_4c1d73c377e5 -->|calls| 7787e2e6_2e19_8e07_7666_21a94194841f style f611bd99_74d3_1161_f7f5_4c1d73c377e5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/compile.ts lines 11–121
export function compileCandidates(
rawCandidates: Iterable<string>,
designSystem: DesignSystem,
{
onInvalidCandidate,
respectImportant,
}: { onInvalidCandidate?: (candidate: string) => void; respectImportant?: boolean } = {},
) {
let nodeSorting = new Map<
AstNode,
{ properties: { order: number[]; count: number }; variants: bigint; candidate: string }
>()
let astNodes: AstNode[] = []
let matches = new Map<string, Candidate[]>()
// Parse candidates and variants
for (let rawCandidate of rawCandidates) {
if (designSystem.invalidCandidates.has(rawCandidate)) {
onInvalidCandidate?.(rawCandidate)
continue // Bail, invalid candidate
}
let candidates = designSystem.parseCandidate(rawCandidate)
if (candidates.length === 0) {
onInvalidCandidate?.(rawCandidate)
continue // Bail, invalid candidate
}
matches.set(rawCandidate, candidates)
}
let flags = CompileAstFlags.None
if (respectImportant ?? true) {
flags |= CompileAstFlags.RespectImportant
}
let variantOrderMap = designSystem.getVariantOrder()
// Create the AST
for (let [rawCandidate, candidates] of matches) {
let found = false
for (let candidate of candidates) {
let rules = designSystem.compileAstNodes(candidate, flags)
if (rules.length === 0) continue
found = true
for (let { node, propertySort } of rules) {
// Track the variant order which is a number with each bit representing a
// variant. This allows us to sort the rules based on the order of
// variants used.
let variantOrder = 0n
for (let variant of candidate.variants) {
variantOrder |= 1n << BigInt(variantOrderMap.get(variant)!)
}
nodeSorting.set(node, {
properties: propertySort,
variants: variantOrder,
candidate: rawCandidate,
})
astNodes.push(node)
}
}
if (!found) {
onInvalidCandidate?.(rawCandidate)
}
}
astNodes.sort((a, z) => {
// SAFETY: At this point it is safe to use TypeScript's non-null assertion
// operator because if the ast nodes didn't exist, we introduced a bug
// above, but there is no need to re-check just to be sure. If this relied
// on pure user input, then we would need to check for its existence.
let aSorting = nodeSorting.get(a)!
let zSorting = nodeSorting.get(z)!
// Sort by variant order first
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does compileCandidates() do?
compileCandidates() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/compile.ts.
Where is compileCandidates() defined?
compileCandidates() is defined in packages/tailwindcss/src/compile.ts at line 11.
What does compileCandidates() call?
compileCandidates() calls 6 function(s): compare, compileAstNodes, get, has, parseCandidate, set.
What calls compileCandidates()?
compileCandidates() is called by 4 function(s): buildDesignSystem, compileAst, getClassOrder, substituteAtApply.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free