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

Function compileAstNodes

packages/tailwindcss/src/compile.ts:123–175  ·  view source on GitHub ↗
(
  candidate: Candidate,
  designSystem: DesignSystem,
  flags: CompileAstFlags,
)

Source from the content-addressed store, hash-verified

121}
122
123export function compileAstNodes(
124 candidate: Candidate,
125 designSystem: DesignSystem,
126 flags: CompileAstFlags,
127) {
128 let asts = compileBaseUtility(candidate, designSystem)
129 if (asts.length === 0) return []
130
131 let respectImportant = designSystem.important && Boolean(flags & CompileAstFlags.RespectImportant)
132
133 let rules: {
134 node: AstNode
135 propertySort: {
136 order: number[]
137 count: number
138 }
139 }[] = []
140
141 let selector = `.${escape(candidate.raw)}`
142
143 for (let nodes of asts) {
144 let propertySort = getPropertySort(nodes)
145
146 // If the candidate itself is important then we want to always mark
147 // the utility as important. However, at a design system level we want
148 // to be able to opt-out when using things like `@apply`
149 if (candidate.important || respectImportant) {
150 applyImportant(nodes)
151 }
152
153 let node: StyleRule = {
154 kind: 'rule',
155 selector,
156 nodes,
157 }
158
159 for (let variant of candidate.variants) {
160 let result = applyVariant(node, variant, designSystem.variants)
161
162 // When the variant results in `null`, it means that the variant cannot be
163 // applied to the rule. Discard the candidate and continue to the next
164 // one.
165 if (result === null) return []
166 }
167
168 rules.push({
169 node,
170 propertySort,
171 })
172 }
173
174 return rules
175}
176
177export function applyVariant(
178 node: Rule,

Callers 1

buildDesignSystemFunction · 0.90

Calls 5

escapeFunction · 0.90
compileBaseUtilityFunction · 0.85
getPropertySortFunction · 0.85
applyImportantFunction · 0.85
applyVariantFunction · 0.85

Tested by

no test coverage detected