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
  ef07d6e3_0c3a_4722_5511_8d4759b3f570["substituteFunctionsInValue()"]
  4ccbfbad_b80c_422a_38fe_dc35ee118e8d["migrate-preflight.ts"]
  ef07d6e3_0c3a_4722_5511_8d4759b3f570 -->|defined in| 4ccbfbad_b80c_422a_38fe_dc35ee118e8d
  904b969f_df9e_eb9f_fedd_18eea0cfe028["migratePreflight()"]
  904b969f_df9e_eb9f_fedd_18eea0cfe028 -->|calls| ef07d6e3_0c3a_4722_5511_8d4759b3f570
  e79308d2_473f_b6d6_3b04_e4e55c2708d3["toCss()"]
  ef07d6e3_0c3a_4722_5511_8d4759b3f570 -->|calls| e79308d2_473f_b6d6_3b04_e4e55c2708d3
  e8898d86_b380_e0ab_d884_65fc28945d60["eventuallyUnquote()"]
  ef07d6e3_0c3a_4722_5511_8d4759b3f570 -->|calls| e8898d86_b380_e0ab_d884_65fc28945d60
  2d6c8361_96d8_df0d_ca51_c62f179fdc73["parse()"]
  ef07d6e3_0c3a_4722_5511_8d4759b3f570 -->|calls| 2d6c8361_96d8_df0d_ca51_c62f179fdc73
  ed78da58_8727_ad98_120c_61f35cea357a["walk()"]
  ef07d6e3_0c3a_4722_5511_8d4759b3f570 -->|calls| ed78da58_8727_ad98_120c_61f35cea357a
  style ef07d6e3_0c3a_4722_5511_8d4759b3f570 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, defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-preflight.ts.
Where is substituteFunctionsInValue() defined?
substituteFunctionsInValue() is defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-preflight.ts at line 117.
What does substituteFunctionsInValue() call?
substituteFunctionsInValue() calls 4 function(s): eventuallyUnquote, parse, toCss, walk.
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