Home / Function/ formatNodes() — tailwindcss Function Reference

formatNodes() — tailwindcss Function Reference

Architecture documentation for the formatNodes() function in format-nodes.ts from the tailwindcss codebase.

Function typescript OxideCore Extractor calls 1 called by 10

Entity Profile

Dependency Diagram

graph TD
  a342f353_2ecc_4db5_ac10_390f5d309eea["formatNodes()"]
  43d27c33_63b0_12b0_510a_e3bcd5373f81["migrate()"]
  43d27c33_63b0_12b0_510a_e3bcd5373f81 -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  98dfdcac_ec22_e7a5_912e_7d87eb45892c["migrate()"]
  98dfdcac_ec22_e7a5_912e_7d87eb45892c -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  57138d88_d90d_e321_2fb5_cca1ce215644["migrate()"]
  57138d88_d90d_e321_2fb5_cca1ce215644 -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  e7c4824a_90a6_ecd4_ccb5_dbcb8e7d4a47["migrate()"]
  e7c4824a_90a6_ecd4_ccb5_dbcb8e7d4a47 -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  51773c2e_bb3d_63e0_1017_2196c25f1acb["migrate()"]
  51773c2e_bb3d_63e0_1017_2196c25f1acb -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  c8a04bfa_6610_ee54_24b2_9c037c187fbb["migrate()"]
  c8a04bfa_6610_ee54_24b2_9c037c187fbb -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  52eccd67_a1a1_1568_397e_4f4e39b2a252["migrate()"]
  52eccd67_a1a1_1568_397e_4f4e39b2a252 -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  d07539e7_2238_f7ed_f9de_f1fe2e0501cc["migrate()"]
  d07539e7_2238_f7ed_f9de_f1fe2e0501cc -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  1384a7a2_8488_cf52_f804_aafd8b87a44b["migrate()"]
  1384a7a2_8488_cf52_f804_aafd8b87a44b -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  eb8ababf_fa35_08e1_76f8_c2b2cea868b8["run()"]
  eb8ababf_fa35_08e1_76f8_c2b2cea868b8 -->|calls| a342f353_2ecc_4db5_ac10_390f5d309eea
  862af4dc_ad02_1198_1156_1e2a5a5540a7["walk()"]
  a342f353_2ecc_4db5_ac10_390f5d309eea -->|calls| 862af4dc_ad02_1198_1156_1e2a5a5540a7
  style a342f353_2ecc_4db5_ac10_390f5d309eea 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

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