Home / Function/ substituteAtVariant() — tailwindcss Function Reference

substituteAtVariant() — tailwindcss Function Reference

Architecture documentation for the substituteAtVariant() function in variants.ts from the tailwindcss codebase.

Function typescript OxideCore Extractor calls 4 called by 3

Entity Profile

Dependency Diagram

graph TD
  101ae1c2_eee3_3589_2aa3_922a6a429d4f["substituteAtVariant()"]
  c58d3214_88d6_f4fc_257f_8e84def5b24f["buildDesignSystem()"]
  c58d3214_88d6_f4fc_257f_8e84def5b24f -->|calls| 101ae1c2_eee3_3589_2aa3_922a6a429d4f
  95cb326e_6b59_0903_0c96_d221fca5c2b1["parseCss()"]
  95cb326e_6b59_0903_0c96_d221fca5c2b1 -->|calls| 101ae1c2_eee3_3589_2aa3_922a6a429d4f
  24c6462c_8059_28e8_4bfc_8d04c9da1c7e["fromAst()"]
  24c6462c_8059_28e8_4bfc_8d04c9da1c7e -->|calls| 101ae1c2_eee3_3589_2aa3_922a6a429d4f
  a32bba76_f60d_883f_1ff1_276a0bb9db9f["walk()"]
  101ae1c2_eee3_3589_2aa3_922a6a429d4f -->|calls| a32bba76_f60d_883f_1ff1_276a0bb9db9f
  9db2a11b_4852_e036_e394_622c7a90dd1f["styleRule()"]
  101ae1c2_eee3_3589_2aa3_922a6a429d4f -->|calls| 9db2a11b_4852_e036_e394_622c7a90dd1f
  ceb1ff41_a641_27dd_6289_7f779710b411["parseVariant()"]
  101ae1c2_eee3_3589_2aa3_922a6a429d4f -->|calls| ceb1ff41_a641_27dd_6289_7f779710b411
  666b100e_8313_09d0_334c_b0fc7e6b9d54["applyVariant()"]
  101ae1c2_eee3_3589_2aa3_922a6a429d4f -->|calls| 666b100e_8313_09d0_334c_b0fc7e6b9d54
  style 101ae1c2_eee3_3589_2aa3_922a6a429d4f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/variants.ts lines 1210–1235

export function substituteAtVariant(ast: AstNode[], designSystem: DesignSystem): Features {
  let features = Features.None
  walk(ast, (variantNode) => {
    if (variantNode.kind !== 'at-rule' || variantNode.name !== '@variant') return

    // Starting with the `&` rule node
    let node = styleRule('&', variantNode.nodes)

    let variant = variantNode.params

    let variantAst = designSystem.parseVariant(variant)
    if (variantAst === null) {
      throw new Error(`Cannot use \`@variant\` with unknown variant: ${variant}`)
    }

    let result = applyVariant(node, variantAst, designSystem.variants)
    if (result === null) {
      throw new Error(`Cannot use \`@variant\` with variant: ${variant}`)
    }

    // Update the variant at-rule node, to be the `&` rule node
    features |= Features.Variants
    return WalkAction.Replace(node)
  })
  return features
}

Domain

Subdomains

Frequently Asked Questions

What does substituteAtVariant() do?
substituteAtVariant() is a function in the tailwindcss codebase.
What does substituteAtVariant() call?
substituteAtVariant() calls 4 function(s): applyVariant, parseVariant, styleRule, walk.
What calls substituteAtVariant()?
substituteAtVariant() is called by 3 function(s): buildDesignSystem, fromAst, parseCss.

Analyze Your Own Codebase

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

Try Supermodel Free