cssAstToPostCssAst() — tailwindcss Function Reference
Architecture documentation for the cssAstToPostCssAst() function in ast.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 2b13c224_9fb8_311a_1669_17e838226ea5["cssAstToPostCssAst()"] 25f462e7_c718_35c5_7ff1_b1b41cc176bf["ast.ts"] 2b13c224_9fb8_311a_1669_17e838226ea5 -->|defined in| 25f462e7_c718_35c5_7ff1_b1b41cc176bf 7e4891ad_b5c5_f083_e9e1_3dc43422517d["tailwindcss()"] 7e4891ad_b5c5_f083_e9e1_3dc43422517d -->|calls| 2b13c224_9fb8_311a_1669_17e838226ea5 0204f9b9_80aa_c3e8_eb61_22170d608d65["createLineTable()"] 2b13c224_9fb8_311a_1669_17e838226ea5 -->|calls| 0204f9b9_80aa_c3e8_eb61_22170d608d65 5bcf4886_1230_a8ff_7302_a26cc5a9a525["get()"] 2b13c224_9fb8_311a_1669_17e838226ea5 -->|calls| 5bcf4886_1230_a8ff_7302_a26cc5a9a525 c203f636_607a_d332_b4c5_6a40c108f778["decl()"] 2b13c224_9fb8_311a_1669_17e838226ea5 -->|calls| c203f636_607a_d332_b4c5_6a40c108f778 66319c06_7c38_f9ea_4bf0_2a0e18bac1a4["rule()"] 2b13c224_9fb8_311a_1669_17e838226ea5 -->|calls| 66319c06_7c38_f9ea_4bf0_2a0e18bac1a4 f9b19679_c1f0_28d6_4d1a_31a10c52e42d["atRule()"] 2b13c224_9fb8_311a_1669_17e838226ea5 -->|calls| f9b19679_c1f0_28d6_4d1a_31a10c52e42d 96bdb9bb_93af_2fac_25bd_5a2e67895fa7["comment()"] 2b13c224_9fb8_311a_1669_17e838226ea5 -->|calls| 96bdb9bb_93af_2fac_25bd_5a2e67895fa7 style 2b13c224_9fb8_311a_1669_17e838226ea5 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