compileCandidates() — tailwindcss Function Reference
Architecture documentation for the compileCandidates() function in compile.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD ad08c258_e5c2_4cd4_c935_0925a940458e["compileCandidates()"] eea0ec96_6369_abc2_64b3_490868392e31["compile.ts"] ad08c258_e5c2_4cd4_c935_0925a940458e -->|defined in| eea0ec96_6369_abc2_64b3_490868392e31 7ad9d996_c0ff_47f5_d131_ab2ead06506e["substituteAtApply()"] 7ad9d996_c0ff_47f5_d131_ab2ead06506e -->|calls| ad08c258_e5c2_4cd4_c935_0925a940458e e557c8a4_bb27_ee44_c462_9e238157ad04["buildDesignSystem()"] e557c8a4_bb27_ee44_c462_9e238157ad04 -->|calls| ad08c258_e5c2_4cd4_c935_0925a940458e 95f6fed7_1762_4f0d_f308_50c6be9a770a["compileAst()"] 95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| ad08c258_e5c2_4cd4_c935_0925a940458e da2d4fa4_738d_c7f2_6941_85df06fd5f32["getClassOrder()"] da2d4fa4_738d_c7f2_6941_85df06fd5f32 -->|calls| ad08c258_e5c2_4cd4_c935_0925a940458e 7d328a86_10c6_b5c1_6390_36f4fffe9c14["parseCandidate()"] ad08c258_e5c2_4cd4_c935_0925a940458e -->|calls| 7d328a86_10c6_b5c1_6390_36f4fffe9c14 ab94dcde_768f_3d99_6111_8043865014ab["set()"] ad08c258_e5c2_4cd4_c935_0925a940458e -->|calls| ab94dcde_768f_3d99_6111_8043865014ab 8b088e47_7f37_81e9_fe8a_5da6d3f5e245["compileAstNodes()"] ad08c258_e5c2_4cd4_c935_0925a940458e -->|calls| 8b088e47_7f37_81e9_fe8a_5da6d3f5e245 a63f95f1_044a_f4fa_d577_48c385d0d0cb["has()"] ad08c258_e5c2_4cd4_c935_0925a940458e -->|calls| a63f95f1_044a_f4fa_d577_48c385d0d0cb 0e687735_200d_7212_bbf6_504ebc1bfe77["get()"] ad08c258_e5c2_4cd4_c935_0925a940458e -->|calls| 0e687735_200d_7212_bbf6_504ebc1bfe77 b45e6f94_1ba7_7e51_9816_073c45d06c7a["compare()"] ad08c258_e5c2_4cd4_c935_0925a940458e -->|calls| b45e6f94_1ba7_7e51_9816_073c45d06c7a style ad08c258_e5c2_4cd4_c935_0925a940458e 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