MCPcopy
hub / github.com/tailwindlabs/tailwindcss / compileCandidates

Function compileCandidates

packages/tailwindcss/src/compile.ts:11–121  ·  view source on GitHub ↗
(
  rawCandidates: Iterable<string>,
  designSystem: DesignSystem,
  {
    onInvalidCandidate,
    respectImportant,
  }: { onInvalidCandidate?: (candidate: string) => void; respectImportant?: boolean } = {},
)

Source from the content-addressed store, hash-verified

9import { walk, WalkAction } from './walk'
10
11export function compileCandidates(
12 rawCandidates: Iterable<string>,
13 designSystem: DesignSystem,
14 {
15 onInvalidCandidate,
16 respectImportant,
17 }: { onInvalidCandidate?: (candidate: string) => void; respectImportant?: boolean } = {},
18) {
19 let nodeSorting = new Map<
20 AstNode,
21 { properties: { order: number[]; count: number }; variants: bigint; candidate: string }
22 >()
23 let astNodes: AstNode[] = []
24 let matches = new Map<string, Candidate[]>()
25
26 // Parse candidates and variants
27 for (let rawCandidate of rawCandidates) {
28 if (designSystem.invalidCandidates.has(rawCandidate)) {
29 onInvalidCandidate?.(rawCandidate)
30 continue // Bail, invalid candidate
31 }
32
33 let candidates = designSystem.parseCandidate(rawCandidate)
34 if (candidates.length === 0) {
35 onInvalidCandidate?.(rawCandidate)
36 continue // Bail, invalid candidate
37 }
38
39 matches.set(rawCandidate, candidates)
40 }
41
42 let flags = CompileAstFlags.None
43
44 if (respectImportant ?? true) {
45 flags |= CompileAstFlags.RespectImportant
46 }
47
48 let variantOrderMap = designSystem.getVariantOrder()
49
50 // Create the AST
51 for (let [rawCandidate, candidates] of matches) {
52 let found = false
53
54 for (let candidate of candidates) {
55 let rules = designSystem.compileAstNodes(candidate, flags)
56 if (rules.length === 0) continue
57
58 found = true
59
60 for (let { node, propertySort } of rules) {
61 // Track the variant order which is a number with each bit representing a
62 // variant. This allows us to sort the rules based on the order of
63 // variants used.
64 let variantOrder = 0n
65 for (let variant of candidate.variants) {
66 variantOrder |= 1n << BigInt(variantOrderMap.get(variant)!)
67 }
68

Callers 4

getClassOrderFunction · 0.90
buildFunction · 0.90
substituteAtApplyFunction · 0.90
candidatesToAstFunction · 0.90

Calls 5

compareFunction · 0.90
setMethod · 0.80
onInvalidCandidateFunction · 0.70
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected