Home / Function/ postCssAstToCssAst() — tailwindcss Function Reference

postCssAstToCssAst() — tailwindcss Function Reference

Architecture documentation for the postCssAstToCssAst() function in ast.ts from the tailwindcss codebase.

Function typescript PostCSSPlugin AST calls 5 called by 2

Entity Profile

Dependency Diagram

graph TD
  63cea7e8_6a82_90d2_b2b0_c166362f218b["postCssAstToCssAst()"]
  9106ed35_a5a8_5f41_7f5e_a6fe5287f68d["ast.ts"]
  63cea7e8_6a82_90d2_b2b0_c166362f218b -->|defined in| 9106ed35_a5a8_5f41_7f5e_a6fe5287f68d
  6d05b300_c6ad_6d9d_74a4_394205536160["tailwindcss()"]
  6d05b300_c6ad_6d9d_74a4_394205536160 -->|calls| 63cea7e8_6a82_90d2_b2b0_c166362f218b
  18b254d7_4530_90ad_11ed_fa759156351c["compiler()"]
  18b254d7_4530_90ad_11ed_fa759156351c -->|calls| 63cea7e8_6a82_90d2_b2b0_c166362f218b
  2820372c_b982_9e06_fc23_f8f4ac308d00["get()"]
  63cea7e8_6a82_90d2_b2b0_c166362f218b -->|calls| 2820372c_b982_9e06_fc23_f8f4ac308d00
  1369a6dc_e395_347d_5d24_b88e22c5446d["decl()"]
  63cea7e8_6a82_90d2_b2b0_c166362f218b -->|calls| 1369a6dc_e395_347d_5d24_b88e22c5446d
  085cf56e_8188_afb1_04da_5ccd0fb7babc["rule()"]
  63cea7e8_6a82_90d2_b2b0_c166362f218b -->|calls| 085cf56e_8188_afb1_04da_5ccd0fb7babc
  2f6881be_62d9_4b96_7331_a962ced095f7["atRule()"]
  63cea7e8_6a82_90d2_b2b0_c166362f218b -->|calls| 2f6881be_62d9_4b96_7331_a962ced095f7
  fdbae017_3891_f845_038f_5fc0e026e5e4["comment()"]
  63cea7e8_6a82_90d2_b2b0_c166362f218b -->|calls| fdbae017_3891_f845_038f_5fc0e026e5e4
  style 63cea7e8_6a82_90d2_b2b0_c166362f218b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-postcss/src/ast.ts lines 126–189

export function postCssAstToCssAst(root: postcss.Root): AstNode[] {
  let inputMap = new DefaultMap<postcss.Input, Source>((input) => ({
    file: input.file ?? input.id ?? null,
    code: input.css,
  }))

  function toSource(node: postcss.ChildNode): SourceLocation | undefined {
    let source = node.source
    if (!source) return

    let input = source.input
    if (!input) return
    if (source.start === undefined) return
    if (source.end === undefined) return

    return [inputMap.get(input), source.start.offset, source.end.offset]
  }

  function transform(
    node: postcss.ChildNode,
    parent: Extract<AstNode, { nodes: AstNode[] }>['nodes'],
  ) {
    // Declaration
    if (node.type === 'decl') {
      let astNode = decl(node.prop, node.value, node.important)
      astNode.src = toSource(node)
      parent.push(astNode)
    }

    // Rule
    else if (node.type === 'rule') {
      let astNode = rule(node.selector)
      astNode.src = toSource(node)
      node.each((child) => transform(child, astNode.nodes))
      parent.push(astNode)
    }

    // AtRule
    else if (node.type === 'atrule') {
      let astNode = atRule(`@${node.name}`, node.params)
      astNode.src = toSource(node)
      node.each((child) => transform(child, astNode.nodes))
      parent.push(astNode)
    }

    // Comment
    else if (node.type === 'comment') {
      if (node.text.charCodeAt(0) !== EXCLAMATION_MARK) return
      let astNode = comment(node.text)
      astNode.src = toSource(node)
      parent.push(astNode)
    }

    // Unknown
    else {
      node satisfies never
    }
  }

  let ast: AstNode[] = []
  root.each((node) => transform(node, ast))

  return ast
}

Domain

Subdomains

Frequently Asked Questions

What does postCssAstToCssAst() do?
postCssAstToCssAst() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-postcss/src/ast.ts.
Where is postCssAstToCssAst() defined?
postCssAstToCssAst() is defined in packages/@tailwindcss-postcss/src/ast.ts at line 126.
What does postCssAstToCssAst() call?
postCssAstToCssAst() calls 5 function(s): atRule, comment, decl, get, rule.
What calls postCssAstToCssAst()?
postCssAstToCssAst() is called by 2 function(s): compiler, tailwindcss.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free