compileAst() — tailwindcss Function Reference
Architecture documentation for the compileAst() function in index.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb["compileAst()"] 5af9cd3c_2cf4_9dee_376e_fc39122d865a["index.ts"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|defined in| 5af9cd3c_2cf4_9dee_376e_fc39122d865a 9c33d37f_aea4_85fa_1eb9_f13429950630["compile()"] 9c33d37f_aea4_85fa_1eb9_f13429950630 -->|calls| ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb 3970218d_3d6c_e455_87cc_45b4a094f0e9["parseCss()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| 3970218d_3d6c_e455_87cc_45b4a094f0e9 96bdb9bb_93af_2fac_25bd_5a2e67895fa7["comment()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| 96bdb9bb_93af_2fac_25bd_5a2e67895fa7 06ed9408_12cf_7ddd_a435_8cdd942de1d4["add()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| 06ed9408_12cf_7ddd_a435_8cdd942de1d4 47b4c875_7e44_6ff9_fb06_16ecf9254223["optimizeAst()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| 47b4c875_7e44_6ff9_fb06_16ecf9254223 31c8f8e4_0e98_63f8_a45c_113e0f57308b["markUsedVariable()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| 31c8f8e4_0e98_63f8_a45c_113e0f57308b f611bd99_74d3_1161_f7f5_4c1d73c377e5["compileCandidates()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| f611bd99_74d3_1161_f7f5_4c1d73c377e5 ed78da58_8727_ad98_120c_61f35cea357a["walk()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| ed78da58_8727_ad98_120c_61f35cea357a df728a67_bdd0_0789_98a1_af70e5020cd5["has()"] ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb -->|calls| df728a67_bdd0_0789_98a1_af70e5020cd5 style ae5a4f96_ffbe_5d6f_324b_4caa358fe1fb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/index.ts lines 709–815
export async function compileAst(
input: AstNode[],
opts: CompileOptions = {},
): Promise<{
sources: { base: string; pattern: string; negated: boolean }[]
root: Root
features: Features
build(candidates: string[]): AstNode[]
}> {
let { designSystem, ast, sources, root, utilitiesNode, features, inlineCandidates } =
await parseCss(input, opts)
if (process.env.NODE_ENV !== 'test') {
ast.unshift(comment(`! tailwindcss v${version} | MIT License | https://tailwindcss.com `))
}
// Track all invalid candidates
function onInvalidCandidate(candidate: string) {
designSystem.invalidCandidates.add(candidate)
}
// Track all valid candidates, these are the incoming `rawCandidate` that
// resulted in a generated AST Node. All the other `rawCandidates` are invalid
// and should be ignored.
let allValidCandidates = new Set<string>()
let compiled = null as AstNode[] | null
let previousAstNodeCount = 0
let defaultDidChange = false
for (let candidate of inlineCandidates) {
if (!designSystem.invalidCandidates.has(candidate)) {
allValidCandidates.add(candidate)
defaultDidChange = true
}
}
return {
sources,
root,
features,
build(newRawCandidates: string[]) {
if (features === Features.None) {
return input
}
if (!utilitiesNode) {
compiled ??= optimizeAst(ast, designSystem, opts.polyfills)
return compiled
}
let didChange = defaultDidChange
let didAddExternalVariable = false
defaultDidChange = false
// Add all new candidates unless we know that they are invalid.
let prevSize = allValidCandidates.size
for (let candidate of newRawCandidates) {
if (!designSystem.invalidCandidates.has(candidate)) {
if (candidate[0] === '-' && candidate[1] === '-') {
let didMarkVariableAsUsed = designSystem.theme.markUsedVariable(candidate)
didChange ||= didMarkVariableAsUsed
didAddExternalVariable ||= didMarkVariableAsUsed
} else {
allValidCandidates.add(candidate)
didChange ||= allValidCandidates.size !== prevSize
}
}
}
// If no new candidates were added, we can return the original CSS. This
// currently assumes that we only add new candidates and never remove any.
if (!didChange) {
compiled ??= optimizeAst(ast, designSystem, opts.polyfills)
return compiled
}
let newNodes = compileCandidates(allValidCandidates, designSystem, {
onInvalidCandidate,
}).astNodes
if (opts.from) {
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does compileAst() do?
compileAst() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/index.ts.
Where is compileAst() defined?
compileAst() is defined in packages/tailwindcss/src/index.ts at line 709.
What does compileAst() call?
compileAst() calls 8 function(s): add, comment, compileCandidates, has, markUsedVariable, optimizeAst, parseCss, walk.
What calls compileAst()?
compileAst() is called by 1 function(s): compile.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free