formatNodes() — tailwindcss Function Reference
Architecture documentation for the formatNodes() function in format-nodes.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 5d3451a8_5d2d_de8f_920f_deec034713bd["formatNodes()"] cc32470d_4e38_6d9b_e583_6e81bb0dc253["migrate()"] cc32470d_4e38_6d9b_e583_6e81bb0dc253 -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd 86e5240c_c4b1_4628_44c0_1c2f8a0111de["migrate()"] 86e5240c_c4b1_4628_44c0_1c2f8a0111de -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd e693c615_04b0_46f3_b602_3e46d121fcb0["migrate()"] e693c615_04b0_46f3_b602_3e46d121fcb0 -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd 74a61e0c_fc6d_ca6e_70cb_582ad1c4ad3c["migrate()"] 74a61e0c_fc6d_ca6e_70cb_582ad1c4ad3c -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd b242fd0e_6a8e_7d8b_fdb9_e04bb2e47104["migrate()"] b242fd0e_6a8e_7d8b_fdb9_e04bb2e47104 -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd b614008a_e4aa_722c_910a_3c58e4d28cef["migrate()"] b614008a_e4aa_722c_910a_3c58e4d28cef -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd c5a75dce_403f_ac99_8467_fc78fa640177["migrate()"] c5a75dce_403f_ac99_8467_fc78fa640177 -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd 74fc48f6_df85_86ac_e006_45cc2fe2ccca["migrate()"] 74fc48f6_df85_86ac_e006_45cc2fe2ccca -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd d7062e64_c90e_b85d_7355_db6c443e36d0["migrate()"] d7062e64_c90e_b85d_7355_db6c443e36d0 -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd c1db9de2_3654_d42b_b9f2_1c5a0ccbd307["run()"] c1db9de2_3654_d42b_b9f2_1c5a0ccbd307 -->|calls| 5d3451a8_5d2d_de8f_920f_deec034713bd 07d1c181_5704_5e29_cec9_3c03edb8746c["walk()"] 5d3451a8_5d2d_de8f_920f_deec034713bd -->|calls| 07d1c181_5704_5e29_cec9_3c03edb8746c style 5d3451a8_5d2d_de8f_920f_deec034713bd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/@tailwindcss-upgrade/src/codemods/css/format-nodes.ts lines 13–84
export function formatNodes(): Plugin {
async function migrate(root: Root) {
// Find the nodes to format
let nodesToFormat: ChildNode[] = []
walk(root, (child, _idx, parent) => {
// Always print semicolons after at-rules
if (child.type === 'atrule') {
child.raws.semicolon = true
}
if (child.type === 'atrule' && child.name === 'tw-bucket') {
nodesToFormat.push(child)
} else if (child.raws.tailwind_pretty) {
// @ts-expect-error We might not have a parent
child.parent ??= parent
nodesToFormat.unshift(child)
}
})
let output: string[] = []
// Format the nodes
for (let node of nodesToFormat) {
let contents = (() => {
if (node.type === 'atrule' && node.name === 'tw-bucket') {
// Remove the `@tw-bucket` wrapping, and use the contents directly.
return node
.toString()
.trim()
.replace(/@tw-bucket(.*?){([\s\S]*)}/, '$2')
}
return node.toString()
})()
// Do not format the user bucket to ensure we keep the user's formatting
// intact.
if (node.type === 'atrule' && node.name === 'tw-bucket' && node.params === 'user') {
output.push(contents)
continue
}
// Format buckets
if (node.type === 'atrule' && node.name === 'tw-bucket') {
output.push(await format(contents, FORMAT_OPTIONS))
continue
}
// Format any other nodes
node.replaceWith(
postcss.parse(
`${node.raws.before ?? ''}${(await format(contents, FORMAT_OPTIONS)).trim()}`,
),
)
}
root.removeAll()
root.append(
postcss.parse(
output
.map((bucket) => bucket.trim())
.filter(Boolean)
.join('\n\n'),
),
)
}
return {
postcssPlugin: '@tailwindcss/upgrade/format-nodes',
OnceExit: migrate,
}
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does formatNodes() do?
formatNodes() is a function in the tailwindcss codebase.
What does formatNodes() call?
formatNodes() calls 1 function(s): walk.
What calls formatNodes()?
formatNodes() is called by 10 function(s): migrate, migrate, migrate, migrate, migrate, migrate, migrate, migrate, and 2 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free