Home / Function/ parseCss() — tailwindcss Function Reference

parseCss() — tailwindcss Function Reference

Architecture documentation for the parseCss() function in index.ts from the tailwindcss codebase.

Function typescript Oxide Extractor calls 32 called by 2

Entity Profile

Dependency Diagram

graph TD
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f["parseCss()"]
  23bd4e2f_c62c_a942_7014_8486569053ee["index.ts"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|defined in| 23bd4e2f_c62c_a942_7014_8486569053ee
  95f6fed7_1762_4f0d_f308_50c6be9a770a["compileAst()"]
  95f6fed7_1762_4f0d_f308_50c6be9a770a -->|calls| f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f
  a1fd01c1_0fb9_2557_6ee0_a660cb46e83b["__unstable__loadDesignSystem()"]
  a1fd01c1_0fb9_2557_6ee0_a660cb46e83b -->|calls| f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f
  2d1ddb63_f29d_b245_22dc_8060d98def4c["substituteAtImports()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 2d1ddb63_f29d_b245_22dc_8060d98def4c
  4982d9ce_98d4_85d9_44af_7cc47b93c482["walk()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 4982d9ce_98d4_85d9_44af_7cc47b93c482
  94749bfc_586d_a227_ed27_a6fae4004c50["cssContext()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 94749bfc_586d_a227_ed27_a6fae4004c50
  c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61
  1b775438_02d9_5178_6806_405c3c0b5328["createCssUtility()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 1b775438_02d9_5178_6806_405c3c0b5328
  91a1286b_b296_e99a_4150_7ded5cd2aa4e["expand()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 91a1286b_b296_e99a_4150_7ded5cd2aa4e
  ab94dcde_768f_3d99_6111_8043865014ab["set()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| ab94dcde_768f_3d99_6111_8043865014ab
  2a22052d_f868_4f88_0a03_2033be58172d["styleRule()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 2a22052d_f868_4f88_0a03_2033be58172d
  ed286c50_134b_5b5b_ff58_76456160010c["compoundsForSelectors()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| ed286c50_134b_5b5b_ff58_76456160010c
  e7db6358_7af5_e4b2_792d_749691a304cc["add()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| e7db6358_7af5_e4b2_792d_749691a304cc
  63907b21_884d_e864_81c9_68f20a13c40b["fromAst()"]
  f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 63907b21_884d_e864_81c9_68f20a13c40b
  style f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/index.ts lines 141–707

async function parseCss(
  ast: AstNode[],
  {
    base = '',
    from,
    loadModule = throwOnLoadModule,
    loadStylesheet = throwOnLoadStylesheet,
  }: CompileOptions = {},
) {
  let features = Features.None
  ast = [contextNode({ base }, ast)] as AstNode[]

  features |= await substituteAtImports(ast, base, loadStylesheet, 0, from !== undefined)

  let important = null as boolean | null
  let theme = new Theme()
  let customVariants = new Map<string, (designSystem: DesignSystem) => void>()
  let customVariantDependencies = new Map<string, Set<string>>()
  let customUtilities: ((designSystem: DesignSystem) => void)[] = []
  let firstThemeRule = null as StyleRule | null
  let utilitiesNode = null as AtRule | null
  let variantNodes: AtRule[] = []
  let sources: { base: string; pattern: string; negated: boolean }[] = []
  let inlineCandidates: string[] = []
  let ignoredCandidates: string[] = []
  let root = null as Root

  // Handle at-rules
  walk(ast, (node, _ctx) => {
    if (node.kind !== 'at-rule') return
    let ctx = cssContext(_ctx)

    // Find `@tailwind utilities` so that we can later replace it with the
    // actual generated utility class CSS.
    if (
      node.name === '@tailwind' &&
      (node.params === 'utilities' || node.params.startsWith('utilities'))
    ) {
      // Any additional `@tailwind utilities` nodes can be removed
      if (utilitiesNode !== null) {
        return WalkAction.Replace([])
      }

      // When inside `@reference` we should treat `@tailwind utilities` as if
      // it wasn't there in the first place. This should also let `build()`
      // return the cached static AST.
      if (ctx.context.reference) {
        return WalkAction.Replace([])
      }

      let params = segment(node.params, ' ')
      for (let param of params) {
        if (param.startsWith('source(')) {
          let path = param.slice(7, -1)

          // Keyword: `source(none)`
          if (path === 'none') {
            root = path
            continue
          }

          // Explicit path: `source('…')`
          if (
            (path[0] === '"' && path[path.length - 1] !== '"') ||
            (path[0] === "'" && path[path.length - 1] !== "'") ||
            (path[0] !== "'" && path[0] !== '"')
          ) {
            throw new Error('`source(…)` paths must be quoted.')
          }

          root = {
            base: (ctx.context.sourceBase as string) ?? (ctx.context.base as string),
            pattern: path.slice(1, -1),
          }
        }
      }

      utilitiesNode = node
      features |= Features.Utilities
    }

Domain

Subdomains

Frequently Asked Questions

What does parseCss() do?
parseCss() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/index.ts.
Where is parseCss() defined?
parseCss() is defined in packages/tailwindcss/src/index.ts at line 141.
What does parseCss() call?
parseCss() calls 32 function(s): add, addKeyframes, applyCompatibilityHooks, atRoot, atRule, buildDesignSystem, compoundsForSelectors, context, and 24 more.
What calls parseCss()?
parseCss() is called by 2 function(s): __unstable__loadDesignSystem, compileAst.

Analyze Your Own Codebase

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

Try Supermodel Free