Home / Function/ compileAst() — tailwindcss Function Reference

compileAst() — tailwindcss Function Reference

Architecture documentation for the compileAst() function in index.ts from the tailwindcss codebase.

Function typescript Oxide Extractor calls 8 called by 1

Entity Profile

Dependency Diagram

graph TD
  95f6fed7_1762_4f0d_f308_50c6be9a770a["compileAst()"]
  23bd4e2f_c62c_a942_7014_8486569053ee["index.ts"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|defined in| 23bd4e2f_c62c_a942_7014_8486569053ee
  c59be670_b950_e897_c2ef_f6a86119dcc3["compile()"]
  c59be670_b950_e897_c2ef_f6a86119dcc3 -->|calls| 95f6fed7_1762_4f0d_f308_50c6be9a770a
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f["parseCss()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f
  fdbae017_3891_f845_038f_5fc0e026e5e4["comment()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| fdbae017_3891_f845_038f_5fc0e026e5e4
  e7db6358_7af5_e4b2_792d_749691a304cc["add()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| e7db6358_7af5_e4b2_792d_749691a304cc
  9f2a64dc_05ff_3425_1af8_f2dbd33c3b9a["optimizeAst()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| 9f2a64dc_05ff_3425_1af8_f2dbd33c3b9a
  9df67824_a508_b69d_ab39_217fd335ee36["markUsedVariable()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| 9df67824_a508_b69d_ab39_217fd335ee36
  ad08c258_e5c2_4cd4_c935_0925a940458e["compileCandidates()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| ad08c258_e5c2_4cd4_c935_0925a940458e
  4982d9ce_98d4_85d9_44af_7cc47b93c482["walk()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| 4982d9ce_98d4_85d9_44af_7cc47b93c482
  a63f95f1_044a_f4fa_d577_48c385d0d0cb["has()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| a63f95f1_044a_f4fa_d577_48c385d0d0cb
  style 95f6fed7_1762_4f0d_f308_50c6be9a770a 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

Called By

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