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

Function compileBaseUtility

packages/tailwindcss/src/compile.ts:265–331  ·  view source on GitHub ↗
(candidate: Candidate, designSystem: DesignSystem)

Source from the content-addressed store, hash-verified

263}
264
265function compileBaseUtility(candidate: Candidate, designSystem: DesignSystem) {
266 if (candidate.kind === 'arbitrary') {
267 let value: string | null = candidate.value
268
269 // Assumption: If an arbitrary property has a modifier, then we assume it
270 // is an opacity modifier.
271 if (candidate.modifier) {
272 value = asColor(value, candidate.modifier, designSystem.theme)
273 }
274
275 if (value === null) return []
276
277 return [[decl(candidate.property, value)]]
278 }
279
280 let utilities = designSystem.utilities.get(candidate.root) ?? []
281
282 let asts: AstNode[][] = []
283
284 let normalUtilities = utilities.filter((u) => !isFallbackUtility(u))
285 for (let utility of normalUtilities) {
286 if (utility.kind !== candidate.kind) continue
287
288 let compiledNodes = utility.compileFn(candidate)
289 if (compiledNodes === undefined) continue
290 if (compiledNodes === null) {
291 // `null` means that the result is invalid and that this plugin should not
292 // result in any CSS, but that doesn't mean that subsequent plugins are
293 // invalid as well.
294 //
295 // However, for backwards compatibility with `matchUtilities` this means
296 // that we do need to bail entirely: plugins that handle a specific
297 // arbitrary value type prevent falling through to other plugins if the
298 // result is invalid for that plugin
299 if (utility.options?.types?.length) return asts
300
301 continue
302 }
303 asts.push(compiledNodes)
304 }
305
306 if (asts.length > 0) return asts
307
308 let fallbackUtilities = utilities.filter((u) => isFallbackUtility(u))
309 for (let utility of fallbackUtilities) {
310 if (utility.kind !== candidate.kind) continue
311
312 let compiledNodes = utility.compileFn(candidate)
313 if (compiledNodes === undefined) continue
314 if (compiledNodes === null) {
315 // `null` means that the result is invalid and that this plugin should not
316 // result in any CSS, but that doesn't mean that subsequent plugins are
317 // invalid as well.
318 //
319 // However, for backwards compatibility with `matchUtilities` this means
320 // that we do need to bail entirely: plugins that handle a specific
321 // arbitrary value type prevent falling through to other plugins if the
322 // result is invalid for that plugin

Callers 1

compileAstNodesFunction · 0.85

Calls 4

asColorFunction · 0.90
declFunction · 0.90
isFallbackUtilityFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected