Home / Function/ substituteFunctionsInValue() — tailwindcss Function Reference

substituteFunctionsInValue() — tailwindcss Function Reference

Architecture documentation for the substituteFunctionsInValue() function in migrate-preflight.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  93d0cdce_24aa_be83_c138_90437551952e["substituteFunctionsInValue()"]
  a3f66598_fbf6_c4e3_9350_55626482e7b1["migratePreflight()"]
  a3f66598_fbf6_c4e3_9350_55626482e7b1 -->|calls| 93d0cdce_24aa_be83_c138_90437551952e
  f66dddcc_be1c_d082_4eb0_ec82ce3bf380["toCss()"]
  93d0cdce_24aa_be83_c138_90437551952e -->|calls| f66dddcc_be1c_d082_4eb0_ec82ce3bf380
  a4f33871_42b3_0484_fe12_6c438f15a657["eventuallyUnquote()"]
  93d0cdce_24aa_be83_c138_90437551952e -->|calls| a4f33871_42b3_0484_fe12_6c438f15a657
  0638028e_f2f7_8e77_2f19_1bd2ce4b2d6a["parse()"]
  93d0cdce_24aa_be83_c138_90437551952e -->|calls| 0638028e_f2f7_8e77_2f19_1bd2ce4b2d6a
  style 93d0cdce_24aa_be83_c138_90437551952e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/css/migrate-preflight.ts lines 117–164

function substituteFunctionsInValue(
  ast: ValueParser.ValueAstNode[],
  handle: (value: string, fallback?: string) => string | null,
) {
  walk(ast, (node) => {
    if (node.kind === 'function' && node.value === 'theme') {
      if (node.nodes.length < 1) return

      // Ignore whitespace before the first argument
      if (node.nodes[0].kind === 'separator' && node.nodes[0].value.trim() === '') {
        node.nodes.shift()
      }

      let pathNode = node.nodes[0]
      if (pathNode.kind !== 'word') return

      let path = pathNode.value

      // For the theme function arguments, we require all separators to contain
      // comma (`,`), spaces alone should be merged into the previous word to
      // avoid splitting in this case:
      //
      // theme(--color-red-500 / 75%) theme(--color-red-500 / 75%, foo, bar)
      //
      // We only need to do this for the first node, as the fallback values are
      // passed through as-is.
      let skipUntilIndex = 1
      for (let i = skipUntilIndex; i < node.nodes.length; i++) {
        if (node.nodes[i].value.includes(',')) {
          break
        }
        path += ValueParser.toCss([node.nodes[i]])
        skipUntilIndex = i + 1
      }

      path = eventuallyUnquote(path)
      let fallbackValues = node.nodes.slice(skipUntilIndex + 1)

      let replacement =
        fallbackValues.length > 0 ? handle(path, ValueParser.toCss(fallbackValues)) : handle(path)
      if (replacement === null) return

      return WalkAction.Replace(ValueParser.parse(replacement))
    }
  })

  return ValueParser.toCss(ast)
}

Subdomains

Called By

Frequently Asked Questions

What does substituteFunctionsInValue() do?
substituteFunctionsInValue() is a function in the tailwindcss codebase.
What does substituteFunctionsInValue() call?
substituteFunctionsInValue() calls 3 function(s): eventuallyUnquote, parse, toCss.
What calls substituteFunctionsInValue()?
substituteFunctionsInValue() is called by 1 function(s): migratePreflight.

Analyze Your Own Codebase

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

Try Supermodel Free