cssAstToPostCssAst() — tailwindcss Function Reference
Architecture documentation for the cssAstToPostCssAst() function in ast.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD dea2012d_fe14_a673_2ce4_701a84a75cdb["cssAstToPostCssAst()"] 9106ed35_a5a8_5f41_7f5e_a6fe5287f68d["ast.ts"] dea2012d_fe14_a673_2ce4_701a84a75cdb -->|defined in| 9106ed35_a5a8_5f41_7f5e_a6fe5287f68d 6d05b300_c6ad_6d9d_74a4_394205536160["tailwindcss()"] 6d05b300_c6ad_6d9d_74a4_394205536160 -->|calls| dea2012d_fe14_a673_2ce4_701a84a75cdb 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3["createLineTable()"] dea2012d_fe14_a673_2ce4_701a84a75cdb -->|calls| 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3 2820372c_b982_9e06_fc23_f8f4ac308d00["get()"] dea2012d_fe14_a673_2ce4_701a84a75cdb -->|calls| 2820372c_b982_9e06_fc23_f8f4ac308d00 1369a6dc_e395_347d_5d24_b88e22c5446d["decl()"] dea2012d_fe14_a673_2ce4_701a84a75cdb -->|calls| 1369a6dc_e395_347d_5d24_b88e22c5446d 085cf56e_8188_afb1_04da_5ccd0fb7babc["rule()"] dea2012d_fe14_a673_2ce4_701a84a75cdb -->|calls| 085cf56e_8188_afb1_04da_5ccd0fb7babc 2f6881be_62d9_4b96_7331_a962ced095f7["atRule()"] dea2012d_fe14_a673_2ce4_701a84a75cdb -->|calls| 2f6881be_62d9_4b96_7331_a962ced095f7 fdbae017_3891_f845_038f_5fc0e026e5e4["comment()"] dea2012d_fe14_a673_2ce4_701a84a75cdb -->|calls| fdbae017_3891_f845_038f_5fc0e026e5e4 style dea2012d_fe14_a673_2ce4_701a84a75cdb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/@tailwindcss-postcss/src/ast.ts lines 9–124
export function cssAstToPostCssAst(
postcss: postcss.Postcss,
ast: AstNode[],
source?: postcss.Source,
): postcss.Root {
let inputMap = new DefaultMap<Source, postcss.Input>((src) => {
return new postcss.Input(src.code, {
map: source?.input.map,
from: src.file ?? undefined,
})
})
let lineTables = new DefaultMap<Source, LineTable>((src) => createLineTable(src.code))
let root = postcss.root()
root.source = source
function toSource(loc: SourceLocation | undefined): postcss.Source | undefined {
// Use the fallback if this node has no location info in the AST
if (!loc) return
if (!loc[0]) return
let table = lineTables.get(loc[0])
let start = table.find(loc[1])
let end = table.find(loc[2])
return {
input: inputMap.get(loc[0]),
start: {
line: start.line,
column: start.column + 1,
offset: loc[1],
},
end: {
line: end.line,
column: end.column + 1,
offset: loc[2],
},
}
}
function updateSource(astNode: postcss.ChildNode, loc: SourceLocation | undefined) {
let source = toSource(loc)
// The `source` property on PostCSS nodes must be defined if present because
// `toJSON()` reads each property and tries to read from source.input if it
// sees a `source` property. This means for a missing or otherwise absent
// source it must be *missing* from the object rather than just `undefined`
if (source) {
astNode.source = source
} else {
delete astNode.source
}
}
function transform(node: AstNode, parent: postcss.Container) {
// Declaration
if (node.kind === 'declaration') {
let astNode = postcss.decl({
prop: node.property,
value: node.value ?? '',
important: node.important,
})
updateSource(astNode, node.src)
parent.append(astNode)
}
// Rule
else if (node.kind === 'rule') {
let astNode = postcss.rule({ selector: node.selector })
updateSource(astNode, node.src)
astNode.raws.semicolon = true
parent.append(astNode)
for (let child of node.nodes) {
transform(child, astNode)
}
}
// AtRule
else if (node.kind === 'at-rule') {
let astNode = postcss.atRule({ name: node.name.slice(1), params: node.params })
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does cssAstToPostCssAst() do?
cssAstToPostCssAst() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-postcss/src/ast.ts.
Where is cssAstToPostCssAst() defined?
cssAstToPostCssAst() is defined in packages/@tailwindcss-postcss/src/ast.ts at line 9.
What does cssAstToPostCssAst() call?
cssAstToPostCssAst() calls 6 function(s): atRule, comment, createLineTable, decl, get, rule.
What calls cssAstToPostCssAst()?
cssAstToPostCssAst() is called by 1 function(s): tailwindcss.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free